Version 1.2.0

In case the password must provided interactively, it is now invisible. Added also exit codes in case of errors for a better usage and automation e.g. with Docker containers. Finally, improved the console output for e.g. Docker containers.
This commit is contained in:
Thorsten Sommer 2016-03-16 08:03:29 +01:00
parent 231e3c69f4
commit 5cd2909677
2 changed files with 589 additions and 576 deletions

16
Main.go
View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/SommerEngineering/Sync/Sync"
"github.com/howeyc/gopass"
"golang.org/x/crypto/ssh"
"log"
"os"
@ -12,7 +13,7 @@ import (
func main() {
// Show the current version:
log.Println(`Sync v1.1.0`)
log.Println(`Sync v1.2.0`)
// Allow Go to use all CPUs:
runtime.GOMAXPROCS(runtime.NumCPU())
@ -23,6 +24,7 @@ func main() {
// Check if the directories are provided:
if localDir == `` || remoteDir == `` {
log.Println(`Please provide the local and remote directory.`)
os.Exit(1)
return
}
@ -30,6 +32,7 @@ func main() {
if localDir == `.` {
if currentWD, currentWDError := os.Getwd(); currentWDError != nil {
log.Println("Cannot use the current working directory as local directory: " + currentWDError.Error())
os.Exit(2)
return
} else {
log.Println("I use the current working directory as local directory: " + currentWD)
@ -44,10 +47,12 @@ func main() {
// Check if local dir exist
if dirInfo, dirError := os.Stat(localDir); dirError != nil {
log.Println("There is an error with the local directory: " + dirError.Error())
os.Exit(3)
return
} else {
if !dirInfo.IsDir() {
log.Println("There is an error with the local directory: You provided a file instead!")
os.Exit(4)
return
}
}
@ -57,7 +62,13 @@ func main() {
if password == `` {
// Promt for the password:
fmt.Print(`Please provide the password for the connection: `)
fmt.Scanln(&password)
if pass, errPass := gopass.GetPasswd(); errPass != nil {
log.Println(`There was an error reading the password securely: ` + errPass.Error())
os.Exit(5)
return
} else {
password = string(pass)
}
} else {
break
}
@ -91,6 +102,7 @@ func main() {
ssh := Sync.ConnectSSH(config, serverAddrString)
if ssh == nil {
log.Println(`It was not possible to connect to the SSH server.`)
os.Exit(6)
return
}

File diff suppressed because it is too large Load Diff