service-gitit/docker-entrypoint.sh

77 lines
1.8 KiB
Bash
Raw Normal View History

2019-02-19 10:05:42 +00:00
#!/bin/sh
set -e
2021-05-08 15:12:26 +00:00
set -u
GITIT_USER_EMAIL="${GITIT_USER_EMAIL:-}"
GITIT_USER_NAME="${GITIT_USER_NAME:-}"
GITIT_REMOTE_REPOSITORY="${GITIT_REMOTE_REPOSITORY:-}"
GITIT_REMOTE_DOMAIN="${GITIT_REMOTE_DOMAIN:-}"
2019-02-19 10:05:42 +00:00
if [ ! -f /data/gitit.conf ]; then
echo "Building config for gitit"
gitit --print-default-config > /data/gitit.conf
sed -i 's|default-extension: page|default-extension: md|' /data/gitit.conf
fi
## Check existing variables
if [ -z "$GITIT_USER_EMAIL" ]; then
>&2 echo "ERROR: Environment variable GITIT_USER_EMAIL not defined"
exit 1
fi
if [ -z "$GITIT_USER_NAME" ]; then
>&2 echo "ERROR: Environment variable GITIT_USER_NAME not defined"
exit 1
fi
2019-03-11 23:36:08 +00:00
# Configure GIT
CUR="$(pwd)"
2021-01-27 14:15:34 +00:00
mkdir -p /data/wikidata
2019-03-11 23:36:08 +00:00
cd /data/wikidata
2019-03-11 23:36:08 +00:00
if [ ! -d /data/wikidata/.git ]; then
git init
fi
git config diff.renames false
git config --global user.email "$GITIT_USER_EMAIL"
git config --global user.name "$GITIT_USER_NAME"
2019-03-11 23:36:08 +00:00
2021-05-08 15:12:26 +00:00
if [ -n "$GITIT_REMOTE_REPOSITORY" ]; then
if [ -z "$GITIT_REMOTE_DOMAIN" ]; then
>&2 echo "ERROR: Environment variable GITIT_REMOTE_DOMAIN not defined"
2021-05-08 15:12:26 +00:00
exit 1
fi
mkdir -p /data/ssh
if [ ! -f /data/ssh/mirror_rsa ]; then
>&2 echo "ERROR: SSH Key file /data/ssh/mirror_rsa is missing."
>&2 echo " Please create it with 'ssh-keygen -f /data/ssh/mirror_rsa' ."
exit 1
fi
2021-05-08 15:12:26 +00:00
git remote remove origin
git remote add origin "$GITIT_REMOTE_REPOSITORY"
mkdir -p /root/.ssh
cat > /root/.ssh/config <<-MARK
2021-05-08 15:24:48 +00:00
Host $GITIT_REMOTE_DOMAIN
2021-05-08 15:12:26 +00:00
IdentityFile /data/ssh/mirror_rsa
StrictHostKeyChecking no
2021-05-08 15:12:26 +00:00
MARK
chmod 600 /root/.ssh/config
chmod 700 /root/.ssh
else
>&2 echo "INFO: Environment variable GITIT_REMOTE_REPOSITORY not defined."
>&2 echo " Skipping mirror repository configuration."
2021-05-08 15:12:26 +00:00
fi
2019-03-11 23:36:08 +00:00
cd "$CUR"
2019-02-19 10:05:42 +00:00
if [ "$1" = 'gitit' ]; then
exec gitit "$@"
fi
exec "$@"