Skip to content

Commit 736d86c

Browse files
committed
ghost: specify the proper shell to use
1 parent 3841f96 commit 736d86c

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

overlord/sysutils_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func Install() error {
133133
<key>EnvironmentVariables</key>
134134
<dict>
135135
<key>SHELL</key>
136-
<string>/bin/bash</string>
136+
<string>%s</string>
137137
<key>HOME</key>
138138
<string>%s</string>
139139
<key>TERM</key>
@@ -145,7 +145,7 @@ func Install() error {
145145
<true/>
146146
</dict>
147147
</plist>
148-
`, argsXML, homeDir)
148+
`, argsXML, getUserShell(), homeDir)
149149

150150
launchAgentsDir := filepath.Join(homeDir, "Library", "LaunchAgents")
151151
plistFilePath := filepath.Join(launchAgentsDir, "com.overlord.ghost.plist")

overlord/sysutils_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ RequiresMountsFor=%s
179179
[Service]
180180
Type=simple
181181
User=%s
182-
Environment=SHELL=/bin/bash
182+
Environment=SHELL=%s
183183
Environment=HOME=%s
184184
Environment=TERM=xterm-256color
185185
ExecStart=%s %s
@@ -188,7 +188,7 @@ RestartSec=5
188188
189189
[Install]
190190
WantedBy=multi-user.target
191-
`, homeDir, currentUser, homeDir, targetPath, cmdArgs)
191+
`, homeDir, currentUser, getUserShell(), homeDir, targetPath, cmdArgs)
192192

193193
serviceFilePath, err := getSystemdServicePath()
194194
if err != nil {

overlord/utils.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"os"
14+
"os/exec"
1415
"path/filepath"
1516
"runtime"
1617
"strconv"
@@ -148,6 +149,33 @@ func installBinaryToUserLocal() (string, error) {
148149
return targetPath, nil
149150
}
150151

152+
// getUserShell returns the user's current shell, with fallback to /bin/bash
153+
func getUserShell() string {
154+
// Try to get shell from environment variable first
155+
if shell := os.Getenv("SHELL"); shell != "" {
156+
return shell
157+
}
158+
159+
// Ultimate fallback
160+
return "/bin/bash"
161+
}
162+
163+
// getShellFromUserDB tries to get the user's shell from the user database
164+
func getShellFromUserDB(username string) string {
165+
// Try using getent command (works on most Unix systems)
166+
cmd := exec.Command("getent", "passwd", username)
167+
output, err := cmd.Output()
168+
if err == nil {
169+
// Parse passwd entry: username:x:uid:gid:gecos:home:shell
170+
fields := strings.Split(strings.TrimSpace(string(output)), ":")
171+
if len(fields) >= 7 && fields[6] != "" {
172+
return fields[6]
173+
}
174+
}
175+
176+
return ""
177+
}
178+
151179
// getServiceCommand constructs the command line arguments for the service
152180
// by filtering out the --install flag from os.Args
153181
func getServiceCommand() []string {

0 commit comments

Comments
 (0)