diff --git a/CHANGELOG.md b/CHANGELOG.md index 861098ac..3cd592f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Secman Dockerfile - New version of shell plugin **v3.0.0** +- Remove backup command ### Fixed diff --git a/api/sync/sync.go b/api/sync/sync.go index 83b9fa7b..8ac0c1a2 100644 --- a/api/sync/sync.go +++ b/api/sync/sync.go @@ -2,23 +2,48 @@ package sync import ( "fmt" - "os" - "os/exec" + "log" + "runtime" + "time" + + "github.com/briandowns/spinner" + "github.com/secman-team/shell" ) func PushSync() { - if _, err := os.Stat("~/.secman/.git"); err != nil { - if os.IsNotExist(err) { - fmt.Println("syncing...") - cmd := exec.Command("secman-sync", "phx") - stdout, err := cmd.Output() - - if err != nil { - fmt.Println(err.Error()) - return - } - - fmt.Print(string(stdout)) + if runtime.GOOS == "windows" { + err, out, errout := shell.PWSLOut("& $HOME/sm/sync.ps1") + + fmt.Print(out) + + if err != nil { + log.Printf("error: %v\n", err) + fmt.Print(errout) + } else if out != "" { + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Suffix = " Syncing..." + s.Start() + + shell.PWSLCmd("& $HOME/sm/secman-sync.ps1 ph") + + s.Stop() + } + } else { + err, out, errout := shell.ShellOut("/home/sm/sync.sh") + + fmt.Print(out) + + if err != nil { + log.Printf("error: %v\n", err) + fmt.Print(errout) + } else if out != "" { + s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) + s.Suffix = " Syncing..." + s.Start() + + shell.ShellCmd("secman-sync phx") + + s.Stop() } } } diff --git a/core/core.go b/core/core.go index 30144124..03b0b97e 100644 --- a/core/core.go +++ b/core/core.go @@ -55,7 +55,7 @@ directory, and initialize your cryptographic keys.`, verxCmd = &cobra.Command{ Use: "verx", Run: func(cmd *cobra.Command, args []string) { - fmt.Println(version) + fmt.Print(version) }, } diff --git a/fetch/fetch.go b/fetch/fetch.go index aab602bc..788c063f 100644 --- a/fetch/fetch.go +++ b/fetch/fetch.go @@ -18,16 +18,16 @@ func FetchSECDIR() { err, out, errout := shell.ShellOut("") if runtime.GOOS == "windows" { - err, out, errout = shell.PWSLOut("~/sm/secman-sync.ps1 --sm") + err, out, errout = shell.PWSLOut("& ~/sm/secman-sync.ps1 pl") } else { err, out, errout = shell.ShellOut("secman-sync pl") } if err != nil { log.Printf("error: %v\n", err) - fmt.Println(errout) + fmt.Print(errout) } s.Stop() - fmt.Println(out) + fmt.Print(out) } diff --git a/go.mod b/go.mod index 0a522da7..2a4b2351 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/atotto/clipboard v0.1.4 github.com/briandowns/spinner v1.12.0 github.com/fatih/color v1.10.0 // indirect - github.com/secman-team/shell v0.3.0 + github.com/secman-team/shell v0.3.1 github.com/spf13/cobra v1.1.3 golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 golang.org/x/sys v0.0.0-20210305034016-7844c3c200c3 // indirect diff --git a/go.sum b/go.sum index 07d4a5df..39425faa 100644 --- a/go.sum +++ b/go.sum @@ -153,6 +153,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/secman-team/shell v0.3.0 h1:bsC8SQUq4rfxVYmgR9R+ol8Dq9zW4IJdAMhCyqoi9D0= github.com/secman-team/shell v0.3.0/go.mod h1:+kAfttTSmyjzVbKIksunNkDxJONomZp52cwY/PgCHHs= +github.com/secman-team/shell v0.3.1 h1:o3/0nrH0sPcEZKvkDKIGcgOOGE7SbMGvcc2rs1yN5uw= +github.com/secman-team/shell v0.3.1/go.mod h1:+kAfttTSmyjzVbKIksunNkDxJONomZp52cwY/PgCHHs= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= diff --git a/packages/backup/backup.py b/packages/backup/backup.py deleted file mode 100644 index 3688ff12..00000000 --- a/packages/backup/backup.py +++ /dev/null @@ -1,192 +0,0 @@ -import os -import sys, getopt -import subprocess as sp -import pathlib -import platform - -# dirs -SECDIR = "~/.secman.bk" -SECDIR_primary = "~/.secman" -SECDIR_url = "secman.bk" -SECDIR_primary_url = ".secman" -cd_SECDIR = "cd {}".format(SECDIR) - -# git & github -SM_GH_UN = sp.getoutput("git config user.name") -create = "gh repo create {}/{} -y --private".format(SM_GH_UN, SECDIR_url) -clone = "gh repo clone {}/{} {}".format(SM_GH_UN, SECDIR_url, SECDIR) -remote = "git remote set-url origin https://github.com/{}/.secman".format( - SM_GH_UN) - -# pkgs -ghraw_url = "https://raw.githubusercontent.com" - -def install(_url): - return "curl -fsSL {}/{} | bash".format(ghraw_url, _url) - -install_brew = install("Homebrew/install/HEAD/install.sh") - -brew_gh = "brew install gh" -choco_gh = "choco install gh" - -def _help(): - print( - "Flags:\n\t-h: help\n\t-i: init ~/.secman.bk folder\n\t-c: clone the backup repo\n\t-p: push new backup passwords\n\t-l: pull passwords\n\t-M: make ~/.secman.bk is the main folder\n" - ) - -def repo_work(): - csi = "cgit secman-ibk" - rdm = 'touch {}/README.md && echo "# My secman backup passwords - {}" >> {}/README.md'.format( - SECDIR, SM_GH_UN, SECDIR) - - # copy ~/.secman to ~/.secman.bk - sp.getoutput("cp -rf {} {}".format(SECDIR_primary, SECDIR)) - os.system("{} && rm -rf .git && git init && {} && {} && {}".format( - cd_SECDIR, rdm, create, csi)) - -def install_installer(): - if platform.system() == "Linux" or platform.system() == "Darwin": - sp.getoutput(brew_gh) - elif platform.system() == "Windows": - sp.getoutput(choco_gh) - -def repo(): - try: - devnull = open(os.devnull) - sp.Popen(["gh"], stdout=devnull, stderr=devnull).communicate() - repo_work() - except OSError: - install_installer() - - try: - devnull = open(os.devnull) - sp.Popen(["gh"], stdout=devnull, stderr=devnull).communicate() - repo_work() - - except OSError: - if platform.system() == "Linux" or platform.system() == "Darwin": - sp.getoutput(install_brew) - elif platform.system() == "Windows": - print( - "you should install Chocolatey from this url https://chocolatey.org/install" - ) - - try: - devnull = open(os.devnull) - - if platform.system() == "Linux" or platform.system( - ) == "Darwin": - sp.Popen(["brew"], stdout=devnull, - stderr=devnull).communicate() - elif platform.system() == "Windows": - sp.Popen(["choco"], stdout=devnull, - stderr=devnull).communicate() - - install_installer() - - try: - devnull = open(os.devnull) - sp.Popen(["gh"], stdout=devnull, - stderr=devnull).communicate() - repo_work() - - except OSError: - print( - "sorry, there's an error while initialize a backup, try again" - ) - - except OSError: - if platform.system() == "Linux" or platform.system( - ) == "Darwin": - print("you should install brew\nhttps://brew.sh") - elif platform.system() == "Windows": - print( - "you should install Chocolatey from this url\nhttps://chocolatey.org/install" - ) - return False - - return True - -def _ph(): - os.system("{} && cgit ph".format(cd_SECDIR)) - -def _pl(): - os.system("{} && cgit pl".format(cd_SECDIR)) - -def _clone(): - os.system(clone) - -def badUsage(): - print( - "Flag not recognized.\nFor an overview of the command, execute: secman-sync backup -h" - ) - -def version(): - os.system("secman ver") - -def make_main(): - """ - 1. check if ~/.secman is not exist - then - 1. copy ~/.secman.bk to ~/.secman - 2. change git remote - - 2. if ~/.secman is exist - then - execute this msg '~/.secman is exist' - """ - - home = os.path.expanduser('~/.secman') - SECDIR_path = pathlib.Path(home) - - if not SECDIR_path.exists(): - os.system("cp -rf {} {}".format(SECDIR, SECDIR_primary)) - os.system("cd {} && {}".format(SECDIR_primary, remote)) - - else: - print("{} is exist".format(SECDIR_primary)) - -def main(argv): - try: - opts, args = getopt.getopt( - argv, "hicvplM", ["help", "init", "clone", "push", "pull", "Main"]) - - except getopt.GetoptError: - badUsage() - sys.exit(2) - - for opt, arg in opts: - if opt in ("-h", "--help"): - _help() - sys.exit() - - elif opt in ("-i", "--init"): - repo_work() - sys.exit() - - elif opt in ("-c", "--clone"): - _clone() - sys.exit() - - elif opt in ("-v", "--version"): - version() - sys.exit() - - elif opt in ("-p", "--push"): - _ph() - sys.exit() - - elif opt in ("-l", "--pull"): - _pl() - sys.exit() - - elif opt in ("-m", "-M", "--Main"): - make_main() - sys.exit() - - else: - badUsage() - sys.exit() - -if __name__ == "__main__": - main(sys.argv[1:]) diff --git a/packages/backup/test.py b/packages/backup/test.py deleted file mode 100644 index acfc2b3a..00000000 --- a/packages/backup/test.py +++ /dev/null @@ -1,11 +0,0 @@ -import subprocess as sp -import platform - -f = "touch xcode.secman" - -_file = sp.getoutput(f) - -print(_file) - -if platform.system() == "Linux": - print("Linux is") diff --git a/plugins/shell b/plugins/shell index 86da9532..74fc5eb3 160000 --- a/plugins/shell +++ b/plugins/shell @@ -1 +1 @@ -Subproject commit 86da953249eb97213644eea248bf9077d7cf4804 +Subproject commit 74fc5eb39923ed360e4620ee4c0180e0c1234383 diff --git a/plugins/v_checker.go b/plugins/v_checker.go index 67715bd3..3e8419dd 100644 --- a/plugins/v_checker.go +++ b/plugins/v_checker.go @@ -17,16 +17,16 @@ func Checker() { err, out, errout := shell.ShellOut("") if runtime.GOOS == "windows" { - err, out, errout = shell.PWSLOut("~/sm/vx.ps1 --sm") + err, out, errout = shell.PWSLOut("& ~/sm/vx.ps1 --sm") } else { err, out, errout = shell.ShellOut("verx --sm") } if err != nil { log.Printf("error: %v\n", err) - fmt.Println(errout) + fmt.Print(errout) } s.Stop() - fmt.Println(out) + fmt.Print(out) } diff --git a/show/show.go b/show/show.go index 9087878d..3b537929 100644 --- a/show/show.go +++ b/show/show.go @@ -7,7 +7,6 @@ import ( "log" "os" "path/filepath" - "runtime" "strings" "github.com/secman-team/secman/v5/pc" @@ -34,13 +33,7 @@ const ( Search ) -func init() { - /* Windows doesn't work with ambiguous width characters */ - if runtime.GOOS == "windows" { - lastPrefix = "+--" - regPrefix = "+--" - } -} +// func init() {} func handleErrors(allErrors []error) { errorStr := "Error" diff --git a/tools b/tools index 16326082..c53c1844 160000 --- a/tools +++ b/tools @@ -1 +1 @@ -Subproject commit 1632608207bf72dca8e08fee1805ce415d05959c +Subproject commit c53c1844aeb0be7b998e09586b20d20bcff2faea