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:
parent
231e3c69f4
commit
5cd2909677
16
Main.go
16
Main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/SommerEngineering/Sync/Sync"
|
"github.com/SommerEngineering/Sync/Sync"
|
||||||
|
"github.com/howeyc/gopass"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Show the current version:
|
// Show the current version:
|
||||||
log.Println(`Sync v1.1.0`)
|
log.Println(`Sync v1.2.0`)
|
||||||
|
|
||||||
// Allow Go to use all CPUs:
|
// Allow Go to use all CPUs:
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
@ -23,6 +24,7 @@ func main() {
|
|||||||
// Check if the directories are provided:
|
// Check if the directories are provided:
|
||||||
if localDir == `` || remoteDir == `` {
|
if localDir == `` || remoteDir == `` {
|
||||||
log.Println(`Please provide the local and remote directory.`)
|
log.Println(`Please provide the local and remote directory.`)
|
||||||
|
os.Exit(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ func main() {
|
|||||||
if localDir == `.` {
|
if localDir == `.` {
|
||||||
if currentWD, currentWDError := os.Getwd(); currentWDError != nil {
|
if currentWD, currentWDError := os.Getwd(); currentWDError != nil {
|
||||||
log.Println("Cannot use the current working directory as local directory: " + currentWDError.Error())
|
log.Println("Cannot use the current working directory as local directory: " + currentWDError.Error())
|
||||||
|
os.Exit(2)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Println("I use the current working directory as local directory: " + currentWD)
|
log.Println("I use the current working directory as local directory: " + currentWD)
|
||||||
@ -44,10 +47,12 @@ func main() {
|
|||||||
// Check if local dir exist
|
// Check if local dir exist
|
||||||
if dirInfo, dirError := os.Stat(localDir); dirError != nil {
|
if dirInfo, dirError := os.Stat(localDir); dirError != nil {
|
||||||
log.Println("There is an error with the local directory: " + dirError.Error())
|
log.Println("There is an error with the local directory: " + dirError.Error())
|
||||||
|
os.Exit(3)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
if !dirInfo.IsDir() {
|
if !dirInfo.IsDir() {
|
||||||
log.Println("There is an error with the local directory: You provided a file instead!")
|
log.Println("There is an error with the local directory: You provided a file instead!")
|
||||||
|
os.Exit(4)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +62,13 @@ func main() {
|
|||||||
if password == `` {
|
if password == `` {
|
||||||
// Promt for the password:
|
// Promt for the password:
|
||||||
fmt.Print(`Please provide the password for the connection: `)
|
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 {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -91,6 +102,7 @@ func main() {
|
|||||||
ssh := Sync.ConnectSSH(config, serverAddrString)
|
ssh := Sync.ConnectSSH(config, serverAddrString)
|
||||||
if ssh == nil {
|
if ssh == nil {
|
||||||
log.Println(`It was not possible to connect to the SSH server.`)
|
log.Println(`It was not possible to connect to the SSH server.`)
|
||||||
|
os.Exit(6)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ func Synchronise(ssh *ssh.Client, supervised, pushOnly bool, localDir, remoteDir
|
|||||||
sftp, sftpError := sftp.NewClient(ssh)
|
sftp, sftpError := sftp.NewClient(ssh)
|
||||||
if sftpError != nil {
|
if sftpError != nil {
|
||||||
log.Println("Was not able to connect to the server: " + sftpError.Error())
|
log.Println("Was not able to connect to the server: " + sftpError.Error())
|
||||||
|
os.Exit(7)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user