update where shell starts and add override -home setting
This commit is contained in:
@@ -15,6 +15,24 @@ import (
|
||||
qrcode "github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
// expandHome resolves a leading ~ to the current user's home directory.
|
||||
func expandHome(p string) (string, error) {
|
||||
if p == "" {
|
||||
return os.UserHomeDir()
|
||||
}
|
||||
if p == "~" {
|
||||
return os.UserHomeDir()
|
||||
}
|
||||
if strings.HasPrefix(p, "~/") {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return filepath.Join(home, p[2:]), nil
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Run is the application entry point, called from main().
|
||||
func Run() {
|
||||
addr := flag.String("addr", "127.0.0.1:5000", "listen address")
|
||||
@@ -25,10 +43,24 @@ func Run() {
|
||||
certreset := flag.Bool("certreset", false, "remove stored custom certificate, revert to self-signed")
|
||||
logFlag := flag.String("log", "", "auth log file path; 'off' disables file logging (default: gotermix.log next to binary)")
|
||||
mfaFlag := flag.String("mfa", "", "manage MFA for a user: -mfa <username> on|off")
|
||||
homeFlag := flag.String("home", "", "starting directory for new shell sessions (default: user home ~)")
|
||||
flag.Parse()
|
||||
|
||||
initialCwd, _ = os.Getwd()
|
||||
|
||||
// Resolve shell starting directory.
|
||||
home, err := expandHome(*homeFlag)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error resolving home directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
info, err := os.Stat(home)
|
||||
if err != nil || !info.IsDir() {
|
||||
fmt.Fprintf(os.Stderr, "error: -home %q is not a valid directory\n", home)
|
||||
os.Exit(1)
|
||||
}
|
||||
shellHome = home
|
||||
|
||||
// Credentials file lives next to the executable.
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user