diff options
| author | 2025-11-09 19:36:18 +0100 | |
|---|---|---|
| committer | 2025-11-09 20:06:31 +0100 | |
| commit | 6f8b029143bef2694fe6d95e27123b8dbf9475d1 (patch) | |
| tree | 7fe4005e10d4c2d4a36f1f079f95a02f0994dc46 | |
| parent | 1dccdb20f97c82580e89f0aa3786d9480a307141 (diff) | |
Added fail helper function that gives formatted output returns nonzero
status
| -rwxr-xr-x | src/init | 37 |
1 files changed, 24 insertions, 13 deletions
@@ -9,6 +9,13 @@ source (status dirname)/env # # +function fail + set_color red + echo "$argv" + set_color normal + return 1 +end + function checkUser set -l user $argv[1] cat /etc/passwd | grep -q -E "^$user:" @@ -19,22 +26,26 @@ function setupUser set -l userConfig (string split ':' $argv[1]) set -l user $userConfig[1] set -l key $userConfig[2] - checkUser "$user"; and return 0 + set -l HOME "/home/$user" echo "Setting up user: $user" if [ "$user" = git ] echo "Error: User git is reserved" return 1 end + + # setup user exist if necessary + if checkUser "$user" + # user is not restricted, this is done in ssh config with forceCommand + # we need to be able to run a fish script to check for permissions + adduser --home $HOME -D "$user"; or fail "Failed to create user $user" + # add user to sudo group + addgroup "$user" $_GIT_SUDO_GROUP; or fail "Failed to add user $user to group $_GIT_SUDO_GROUP" + # unlock account to allow ssh logins + passwd -u "$user" &>/dev/null; or fail "Failed to unlock account of $user" + end - set -l HOME "/home/$user" - # user is not restricted, this is done in ssh config with forceCommand - # we need to be able to run a fish script to check for permissions - adduser --home $HOME -D "$user" - # add user to sudo group - addgroup "$user" $_GIT_SUDO_GROUP - # unlock account to allow ssh logins - passwd -u "$user" &>/dev/null + # Copy/Overwrite ssh key mkdir "$HOME/.ssh" echo "$key" > "$HOME/.ssh/authorized_keys" chown -R $user "$HOME" @@ -46,10 +57,10 @@ function setupGitUser echo "Setting up git user" # git user has read/write access to all repos, set git-shell # and no password login allowed -> no ssh login possible - addgroup -g $GIT_GID git - adduser git -u $GIT_UID -G git -D --shell "/usr/bin/git-shell" + addgroup -g $GIT_GID git; or fail "Failed to create git user group" + adduser git -u $GIT_UID -G git -D --shell "/usr/bin/git-shell"; or fail "Failed to setup git user" # group that is allowed to sudo - addgroup $_GIT_SUDO_GROUP + addgroup $_GIT_SUDO_GROUP; or fail "Failed to setup git sudo group" end function setupRepo @@ -60,7 +71,7 @@ function setupRepo # check repo name set -l matcher (string match -r -g "^$_REPO_VALIDATION_REGEX\$" -- $repo) if test -z $matcher[1] - echo "Failed to setup repo, invalid config: $repoConfig" + fail "Failed to setup repo, invalid config: $repoConfig" return 1 end |
