summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2025-10-19 18:19:14 +0200
committerGravatar Matthias Lucas Jaros <jarlucmat@mailbox.org>2025-10-19 18:19:14 +0200
commit2294af355a549070544eb49638eda6b05cd61a05 (patch)
tree5a3d22211bd6e3d14f939ebc410ffc640b27f478 /init
parentd9fc214c094bdb4ae4f7a855a1cc61134a5b519e (diff)
Cleaned up file structure and script
Diffstat (limited to 'init')
-rwxr-xr-xinit51
1 files changed, 40 insertions, 11 deletions
diff --git a/init b/init
index 3802633..d9da7bd 100755
--- a/init
+++ b/init
@@ -3,15 +3,15 @@
argparse 'u/users=+' 'r/repos=+' -- $argv
or exit 1;
-# setup git user
-adduser git -D --shell "/usr/bin/git-shell"
+set REPO_PERMISSIONS /etc/repo-permissions
+set REPO_REGEX "^((?:\/[a-zA-Z-]+)+.git)\$"
-# create users and copy keys in correct location, set permissions
-for user in (string split ',' $_flag_u)
+function createUser
+ set -l user $argv[1]
echo "Setting up user: $user"
if [ "$user" = git ]
- echo "Denied because user git is reserved"
- continue
+ echo "Error: User git is reserved"
+ return 1
end
set -l HOME "/home/$user"
@@ -20,22 +20,31 @@ for user in (string split ',' $_flag_u)
adduser --home $HOME -D "$user"
passwd -u "$user"
mkdir "$HOME/.ssh"
- cp "/var/keys/$user/authorized_keys" "$HOME/.ssh/"
+ cp "/var/ssh/clients/$user" "$HOME/.ssh/authorized_keys"
chown -R $user "$HOME"
chmod -R 700 "$HOME"
end
-for repoConfig in (string split ',' $_flag_r)
+function setupRepo
+ set -l repoConfig $argv[1]
set -l parsedConfig (string split ':' $repoConfig)
set -l repo $parsedConfig[1]
+ # check repo name
+ set -l matcher (string match -r -g $REPO_REGEX $repo)
+ if test -z $matcher[1]
+ echo "Invalid repo name $repo"
+ return 1
+ end
+
# we assume all repos to be in /srv/repos
- set -l repoDir "/srv/repos/$repo.git"
+ set -l repoDir srv repos
+ set -l repoDir /(string join -n '/' $repoDir (string split '/' $repo))
echo "Setting up repo: $repo"
# write user as allowed into permission file
for user in $parsedConfig[2..]
- echo "$repoDir:$user" >> /srv/repos/permissions
+ echo "$repoDir:$user" >> $REPO_PERMISSIONS
end
# setup repo dir
@@ -47,8 +56,28 @@ for repoConfig in (string split ',' $_flag_r)
chmod -R 700 "$repoDir"
end
+#
+# Setup users
+# First and reserved is git user, which has access to all
+# git repos
+#
+adduser git -D --shell "/usr/bin/git-shell"
+for user in (string split ',' $_flag_u)
+ createUser "$user"
+end
+
+#
+# Setup repos
+# First and reserved is git user, which has access to all
+# git repos
+#
+echo > $REPO_PERMISSIONS
+for repoConfig in (string split ',' $_flag_r)
+ setupRepo "$repoConfig"
+end
+
echo "Setting up server"
# generate host keys in case
-mkdir -p /var/keys/etc/ssh/ && ssh-keygen -A -f /var/keys
+mkdir -p /var/ssh/host/etc/ssh/ && ssh-keygen -A -f /var/ssh/host
# run ssh daemon
/usr/sbin/sshd -D -e