Fix share count bug

Also make username in client config less dumb
This commit is contained in:
Olivier Tremblay 2018-10-17 19:54:34 -04:00
parent 2e8083e42f
commit e2e27c51fe
No known key found for this signature in database
GPG key ID: D1C73ACB855E3A6D

22
main.go
View file

@ -35,6 +35,9 @@ func main() {
httpport := flag.String("httpport", "8888", "the remote server's http port") httpport := flag.String("httpport", "8888", "the remote server's http port")
sharecount := flag.Uint("count", 1, "Amount of times you want to share this file") sharecount := flag.Uint("count", 1, "Amount of times you want to share this file")
flag.Parse() flag.Parse()
if *sharecount > 0 {
*sharecount--
}
if *server { if *server {
runServer("0.0.0.0", *sshport, *httpport, "id_rsa") runServer("0.0.0.0", *sshport, *httpport, "id_rsa")
} }
@ -65,8 +68,16 @@ func main() {
fmt.Println(err) fmt.Println(err)
auth = SSHAgent() auth = SSHAgent()
} }
var username string
userobj, err := user.Current()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not get user with user.Current()")
username = "unknown"
} else {
username = userobj.Username
}
sshConfig := &ssh.ClientConfig{ sshConfig := &ssh.ClientConfig{
User: "otremblay", User: username,
Auth: []ssh.AuthMethod{ Auth: []ssh.AuthMethod{
auth, auth,
}, },
@ -86,14 +97,7 @@ func main() {
} }
enc := gob.NewEncoder(ch) enc := gob.NewEncoder(ch)
path = flag.Arg(0) path = flag.Arg(0)
var username string
userobj, err := user.Current()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not get user with user.Current()")
username = "unknown"
} else {
username = userobj.Username
}
hostname, err := os.Hostname() hostname, err := os.Hostname()
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, "Could not get hostname with os.Hostname()") fmt.Fprintln(os.Stderr, "Could not get hostname with os.Hostname()")