aboutsummaryrefslogtreecommitdiffstats
path: root/image/prepare-container.sh
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-03 01:03:27 +0100
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-01-03 01:03:27 +0100
commite6359a9ceb5fba89ab0d152ce6ead2da7b8afa57 (patch)
tree0751a2a4b358f850dac8c83a4ee74a155c6c6e59 /image/prepare-container.sh
parenta912704a1fdc06622466c9887051e1e0b2f5d42f (diff)
downloadcgit-oci-e6359a9ceb5fba89ab0d152ce6ead2da7b8afa57.tar.gz
cgit-oci-e6359a9ceb5fba89ab0d152ce6ead2da7b8afa57.tar.bz2
cgit-oci-e6359a9ceb5fba89ab0d152ce6ead2da7b8afa57.tar.lz
cgit-oci-e6359a9ceb5fba89ab0d152ce6ead2da7b8afa57.zip

feat: a sensible setup, for once

Diffstat (limited to 'image/prepare-container.sh')
-rwxr-xr-ximage/prepare-container.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/image/prepare-container.sh b/image/prepare-container.sh
new file mode 100755
index 0000000..66ccb2f
--- /dev/null
+++ b/image/prepare-container.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+set -e
+
+# Warning : this no standard docker entrypoint, we use dumb-init !
+ensureKeyAlgo() {
+ if [ ! -f "/etc/ssh/ssh_host_${1}_key" ]; then
+ # generate fresh $1 key
+ ssh-keygen -f /etc/ssh/ssh_host_${1}_key -N '' -t "${1}"
+ fi
+}
+ensureKeyAlgo ed25519
+ensureKeyAlgo rsa
+ensureKeyAlgo ecdsa
+[[ -f /etc/sshd_config ]] && mv /etc/sshd_config /etc/ssh/sshd_config || [[ -f /etc/ssh/sshd_config ]]
+chmod -w /etc/ssh/sshd_config
+
+# prepare run dir
+if ! [[ -d "/var/run/sshd" ]]; then
+ mkdir -p /var/run/sshd
+fi
+
+# Run sshd
+echo "Starting sshd"
+/usr/sbin/sshd
+
+# Volume permissions
+echo "Setting up permissions"
+mkdir -p /var/lib/git/.gitolite/logs
+chown -R git /var/lib/git
+chgrp -R www-data /var/lib/git
+chmod -R 775 /var/lib/git
+
+# If no cgitrc, let's copy one from /etc/cgitrc.default. This happens when bindmounting /var/lib/git
+if [ ! -f "/var/lib/git/cgitrc" ]; then
+ echo '# This is an autogenrated file. Do not edit it by hand, changes will be lost.' | cat - /etc/cgitrc.default > /var/lib/git/cgitrc
+ chown git /var/lib/git/cgitrc
+ chmod 711 /var/lib/git/cgitrc
+fi
+if [ ! -f "/var/lib/git/.ssh/authorized_keys" ]; then
+ # Gitolite configuration (admin pubkey)
+ if [ -n "$SSH_KEY" ]; then
+ echo "$SSH_KEY" > "/tmp/admin.pub"
+ su - git -c "gitolite setup -pk \"/tmp/admin.pub\""
+ rm "/tmp/admin.pub"
+ else
+ echo "You need to specify SSH_KEY on first run to setup gitolite"
+ echo 'Example: podman run --rm -dit -v git-data:/var/lib/git -v git-ssh:/etc/ssh -e SSH_KEY="$(cat /home/<user>/.ssh/id_rsa.pub)" gjbs84/gitolite-cgit:latest'
+ exit 1
+ fi
+ echo "First launch: container is now shut down"
+ halt
+else
+ # Check setup at every startup
+ su - git -c "gitolite setup"
+fi
+
+#exec "$@"