aboutsummaryrefslogtreecommitdiffstats
path: root/prepare-container.sh
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar Grégory Joubès <gregoryjoubesnetcourriercom>2020-11-03 16:29:12 +0100
committerLibravatarLarge Libravatar Grégory Joubès <gregoryjoubesnetcourriercom>2020-11-03 16:29:12 +0100
commit860fb6c4c8b1111a411e2587f394f2a9e8128716 (patch)
tree40743465de9596bdc9d7c960b38764d7741c2510 /prepare-container.sh
downloadcgit-oci-860fb6c4c8b1111a411e2587f394f2a9e8128716.tar.gz
cgit-oci-860fb6c4c8b1111a411e2587f394f2a9e8128716.tar.bz2
cgit-oci-860fb6c4c8b1111a411e2587f394f2a9e8128716.tar.lz
cgit-oci-860fb6c4c8b1111a411e2587f394f2a9e8128716.zip

Initial commit

Diffstat (limited to 'prepare-container.sh')
-rwxr-xr-xprepare-container.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/prepare-container.sh b/prepare-container.sh
new file mode 100755
index 0000000..784b9eb
--- /dev/null
+++ b/prepare-container.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+
+# Warning : this no standard docker entrypoint, we use dumb-init !
+
+if [ ! -f "/etc/ssh/ssh_host_rsa_key" ]; then
+ # generate fresh rsa key
+ ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
+fi
+if [ ! -f "/etc/ssh/ssh_host_dsa_key" ]; then
+ # generate fresh dsa key
+ ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
+fi
+
+#prepare run dir
+if [ ! -d "/var/run/sshd" ]; then
+ mkdir -p /var/run/sshd
+fi
+
+# Run sshd
+echo "Starting sshd"
+/usr/sbin/sshd
+
+# If no cgitrc, let's copy one from /etc/cgitrc.default. This happens when bindmounting /home/git
+if [ ! -f "/home/git/cgitrc" ]; then
+ cp /etc/cgitrc.default /home/git/cgitrc
+fi
+
+# Gitolite configuration (admin pubkey)
+if [ ! -f "/home/git/.ssh/authorized_keys" ]; then
+ 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: docker run --rm --name git-test -e SSH_KEY="$(cat ~/.ssh/id_rsa.pub)" -v git-data:/home/git -dit gitolite-cgit-cds:v10'
+ exit 1
+ fi
+ echo "First launch : container is now shut down"
+ halt
+# Check setup at every startup
+else
+ su - git -c "gitolite setup"
+fi
+
+# Volume permissions
+echo "Setting up permissions"
+chown -R git:git /home/git
+chmod -R 755 /home/git/repositories
+
+# htaccess/htpasswd auth (comes from docker-cgit/scripts)
+echo "No Apache htaccess required"
+if [ "$HTTP_AUTH_PASSWORD" != "" ]; then
+ echo "Enables Apache htaccess"
+ echo "AuthType Basic
+AuthName \"CGit\"
+AuthUserFile /var/www/htdocs/cgit/.htpasswd
+Require valid-user" > /var/www/htdocs/cgit/.htaccess
+htpasswd -c -b /var/www/htdocs/cgit/.htpasswd $HTTP_AUTH_USER $HTTP_AUTH_PASSWORD
+fi
+
+#exec "$@"
+