-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detects the best shell and allow to override entrypoint
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// References: | ||
// * https://gitlab.com/gitlab-org/gitlab-runner/-/blob/master/shells/bash.go | ||
// * https://gitlab.com/gitlab-org/gitlab-runner/-/blob/master/executors/shell/shell.go | ||
|
||
/** | ||
* get bash detect shell script | ||
* | ||
* @param isLoginShell {boolean} login shell | ||
* @return {string} generated code | ||
*/ | ||
function getBashDetectShellScript(isLoginShell) { | ||
const bashDefaultArguments = isLoginShell ? '--login' : ''; | ||
return `if [ -x /usr/local/bin/bash ]; then | ||
exec /usr/local/bin/bash ${bashDefaultArguments} "$@" | ||
elif [ -x /usr/bin/bash ]; then | ||
exec /usr/bin/bash ${bashDefaultArguments} "$@" | ||
elif [ -x /bin/bash ]; then | ||
exec /bin/bash ${bashDefaultArguments} "$@" | ||
elif [ -x /usr/local/bin/sh ]; then | ||
exec /usr/local/bin/sh "$@" | ||
elif [ -x /usr/bin/sh ]; then | ||
exec /usr/bin/sh "$@" | ||
elif [ -x /bin/sh ]; then | ||
exec /bin/sh "$@" | ||
elif [ -x /busybox/sh ]; then | ||
exec /busybox/sh "$@" | ||
else | ||
echo shell not found | ||
exit 1 | ||
fi | ||
`; | ||
} | ||
|
||
function getShellCommandLine(userCommand) { | ||
const command = [ | ||
'sh', '-c', getBashDetectShellScript(true) | ||
]; | ||
if (userCommand) { | ||
command.push('--'); | ||
command.push('-c'); | ||
command.push(userCommand); | ||
} | ||
return command; | ||
} | ||
|
||
|
||
module.exports = { | ||
getShellCommandLine | ||
}; |