docker_gitea/setup.sh

24 lines
864 B
Bash
Raw Normal View History

2023-02-28 20:43:05 +00:00
#! /bin/bash
GITEA_HOME=/var/lib/gitea
2023-02-28 22:30:00 +00:00
HOST_GIT_USER=git # this will be the user in the ssh git urls, e.g. git@blacka.com/org/repo.git
2023-02-28 22:37:20 +00:00
HOST_GIT_GROUP=gitea
2023-02-28 22:33:32 +00:00
HOST_GIT_UID=895
2023-02-28 20:43:05 +00:00
2023-02-28 22:37:20 +00:00
# create the 'git:gitea' user to run and own this thing
# Note we want 'git' as the user, since every other git hosting system uses that
2023-02-28 22:33:32 +00:00
if ! id -u "$HOST_GIT_UID" >/dev/null 2>&1; then
2023-02-28 22:37:20 +00:00
groupadd -g "$HOST_GIT_UID" "$HOST_GIT_GROUP"
2023-02-28 22:38:15 +00:00
useradd -u "$HOST_GIT_UID" -g "$HOST_GIT_GROUP" -G docker -d "$GITEA_HOME" -m "$HOST_GIT_USER"
2023-02-28 20:43:05 +00:00
fi
install -d "$GITEA_HOME/data"
2023-03-01 23:08:06 +00:00
install -o $HOST_GIT_USER -g $HOST_GIT_GROUP -m 0700 -d "$GITEA_HOME/.ssh"
2023-02-28 22:30:00 +00:00
cat <<"EOF" | sudo tee $GITEA_HOME/docker-shell
#!/bin/sh
/usr/bin/docker exec -i -u git --env SSH_ORIGINAL_COMMAND="$SSH_ORIGINAL_COMMAND" gitea sh "$@"
EOF
sudo chmod +x $GITEA_HOME/docker-shell
sudo usermod -s $GITEA_HOME/docker-shell git