2016-11-28 13:13:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ ! -d /data/git/.ssh ]; then
|
|
|
|
mkdir -p /data/git/.ssh
|
2023-07-06 15:02:56 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the correct permissions on the .ssh directory and authorized_keys file,
|
|
|
|
# or sshd will refuse to use them and lead to clone/push/pull failures.
|
|
|
|
# It could happen when users have copied their data to a new volume and changed the file permission by accident,
|
|
|
|
# and it would be very hard to troubleshoot unless users know how to check the logs of sshd which is started by s6.
|
|
|
|
chmod 700 /data/git/.ssh
|
|
|
|
if [ -f /data/git/.ssh/authorized_keys ]; then
|
|
|
|
chmod 600 /data/git/.ssh/authorized_keys
|
2016-11-28 13:13:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f /data/git/.ssh/environment ]; then
|
2019-05-13 22:19:38 +00:00
|
|
|
echo "GITEA_CUSTOM=$GITEA_CUSTOM" >| /data/git/.ssh/environment
|
2016-11-28 13:13:18 +00:00
|
|
|
chmod 600 /data/git/.ssh/environment
|
2019-05-13 22:19:38 +00:00
|
|
|
|
|
|
|
elif ! grep -q "^GITEA_CUSTOM=$GITEA_CUSTOM$" /data/git/.ssh/environment; then
|
|
|
|
sed -i /^GITEA_CUSTOM=/d /data/git/.ssh/environment
|
|
|
|
echo "GITEA_CUSTOM=$GITEA_CUSTOM" >> /data/git/.ssh/environment
|
2016-11-28 13:13:18 +00:00
|
|
|
fi
|
|
|
|
|
2019-05-13 22:19:38 +00:00
|
|
|
if [ ! -f ${GITEA_CUSTOM}/conf/app.ini ]; then
|
|
|
|
mkdir -p ${GITEA_CUSTOM}/conf
|
2017-10-31 08:55:46 +00:00
|
|
|
|
|
|
|
# Set INSTALL_LOCK to true only if SECRET_KEY is not empty and
|
|
|
|
# INSTALL_LOCK is empty
|
|
|
|
if [ -n "$SECRET_KEY" ] && [ -z "$INSTALL_LOCK" ]; then
|
|
|
|
INSTALL_LOCK=true
|
|
|
|
fi
|
|
|
|
|
2021-07-08 11:38:13 +00:00
|
|
|
# Substitute the environment variables in the template
|
2022-12-25 15:25:25 +00:00
|
|
|
APP_NAME=${APP_NAME:-"Forgejo: Beyond coding. We forge."} \
|
2020-11-30 19:52:04 +00:00
|
|
|
RUN_MODE=${RUN_MODE:-"prod"} \
|
2020-05-04 09:50:29 +00:00
|
|
|
DOMAIN=${DOMAIN:-"localhost"} \
|
2017-10-31 08:55:46 +00:00
|
|
|
SSH_DOMAIN=${SSH_DOMAIN:-"localhost"} \
|
|
|
|
HTTP_PORT=${HTTP_PORT:-"3000"} \
|
|
|
|
ROOT_URL=${ROOT_URL:-""} \
|
|
|
|
DISABLE_SSH=${DISABLE_SSH:-"false"} \
|
|
|
|
SSH_PORT=${SSH_PORT:-"22"} \
|
2019-08-23 23:44:24 +00:00
|
|
|
SSH_LISTEN_PORT=${SSH_LISTEN_PORT:-"${SSH_PORT}"} \
|
2019-06-24 05:33:57 +00:00
|
|
|
LFS_START_SERVER=${LFS_START_SERVER:-"false"} \
|
2017-10-31 08:55:46 +00:00
|
|
|
DB_TYPE=${DB_TYPE:-"sqlite3"} \
|
|
|
|
DB_HOST=${DB_HOST:-"localhost:3306"} \
|
|
|
|
DB_NAME=${DB_NAME:-"gitea"} \
|
|
|
|
DB_USER=${DB_USER:-"root"} \
|
|
|
|
DB_PASSWD=${DB_PASSWD:-""} \
|
|
|
|
INSTALL_LOCK=${INSTALL_LOCK:-"false"} \
|
2018-05-23 15:31:12 +00:00
|
|
|
DISABLE_REGISTRATION=${DISABLE_REGISTRATION:-"false"} \
|
|
|
|
REQUIRE_SIGNIN_VIEW=${REQUIRE_SIGNIN_VIEW:-"false"} \
|
2017-10-31 08:55:46 +00:00
|
|
|
SECRET_KEY=${SECRET_KEY:-""} \
|
2019-05-13 22:19:38 +00:00
|
|
|
envsubst < /etc/templates/app.ini > ${GITEA_CUSTOM}/conf/app.ini
|
|
|
|
|
|
|
|
chown ${USER}:git ${GITEA_CUSTOM}/conf/app.ini
|
2016-11-28 13:13:18 +00:00
|
|
|
fi
|
|
|
|
|
2018-10-30 15:41:41 +00:00
|
|
|
# only chown if current owner is not already the gitea ${USER}. No recursive check to save time
|
|
|
|
if ! [[ $(ls -ld /data/gitea | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /data/gitea; fi
|
|
|
|
if ! [[ $(ls -ld /app/gitea | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /app/gitea; fi
|
|
|
|
if ! [[ $(ls -ld /data/git | awk '{print $3}') = ${USER} ]]; then chown -R ${USER}:git /data/git; fi
|
2016-11-28 13:13:18 +00:00
|
|
|
chmod 0755 /data/gitea /app/gitea /data/git
|
2023-06-23 22:44:32 +00:00
|
|
|
|
|
|
|
# Replace app.ini settings with env variables in the form GITEA__SECTION_NAME__KEY_NAME
|
|
|
|
su $USER -c "environment-to-ini --config ${GITEA_CUSTOM}/conf/app.ini"
|