summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2025-10-20 13:49:26 +0200
committerGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2025-10-20 13:49:26 +0200
commit0c3a8a9d78f1a7086efcde9bdd605ec911454458 (patch)
treef23d3d532ba00959554fb8a4bd13ac9676227d75
parent8ef9b0fe88470125d6ee60a3ea0bab796048e692 (diff)
Handle restart case
-rwxr-xr-xsrc/init39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/init b/src/init
index e292d59..9c4107d 100755
--- a/src/init
+++ b/src/init
@@ -9,10 +9,18 @@ source (dirname (status --current-filename))/env
#
#
+function checkUser
+ set -l user $argv[1]
+ cat /etc/passwd | grep -q -E "^$user:"
+ return $status
+end
+
function createUser
set -l userConfig (string split ':' $argv[1])
set -l user $userConfig[1]
set -l key $userConfig[2]
+ checkUser "$user"; and return 0
+
echo "Setting up user: $user"
if [ "$user" = git ]
echo "Error: User git is reserved"
@@ -31,6 +39,14 @@ function createUser
chmod -R 700 "$HOME"
end
+function setupGitUser
+ checkUser "git"; and return 0
+ 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
+ adduser git -u $GIT_UID -D --shell "/usr/bin/git-shell"
+end
+
function setupRepo
set -l repoConfig $argv[1]
set -l parsedConfig (string split ':' $repoConfig)
@@ -62,6 +78,16 @@ function setupRepo
chmod -R 700 "$repoDir"
end
+function runSSHDaemon
+ echo "Setting up server"
+
+ # generate host keys in case
+ mkdir -p /var/ssh/etc/ssh/ && ssh-keygen -A -f /var/ssh
+
+ # run ssh daemon
+ /usr/sbin/sshd -D -e
+end
+
#
#
# main
@@ -83,7 +109,7 @@ if set -q _flag_h
return
end
-# read environment variables
+# read variables
set -l users $_flag_u
for user in (set -n | string match -r "^USER_\S+")
set users $users (eval echo \$$user)
@@ -99,10 +125,7 @@ if set -q $_flag_g
end
# Setup users
-# git user has read/write access to all repos, set git-shell
-# and no password login allowed -> no ssh login possible
-adduser git -u $GIT_UID -D --shell "/usr/bin/git-shell"
-passwd -l git
+setupGitUser
for userConfig in $users
createUser "$userConfig"
end
@@ -116,8 +139,4 @@ end
# create writable log file
touch $LOG && chmod 777 $LOG
-echo "Setting up server"
-# generate host keys in case
-mkdir -p /var/ssh/etc/ssh/ && ssh-keygen -A -f /var/ssh
-# run ssh daemon
-/usr/sbin/sshd -D -e
+runSSHDaemon