forgejo-app/start.sh

92 lines
3.6 KiB
Bash
Raw Normal View History

2015-04-26 19:45:32 +00:00
#!/bin/bash
set -eu -o pipefail
2015-04-29 00:12:16 +00:00
fqdn=$(hostname -f)
2015-04-26 19:45:32 +00:00
2015-04-29 04:57:58 +00:00
chown -R cloudron.cloudron /app/data
# clean up old logs
rm -rf /home/cloudron/gogs/log && mkdir -p /home/cloudron/gogs/log
chown cloudron:cloudron /home/cloudron/gogs/log
2015-04-29 04:57:58 +00:00
# Dockerfile changes the ownership of this file to make it writable by cloudron user
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
-i /etc/ssh/sshd_config
2015-04-29 00:12:16 +00:00
2015-04-29 04:57:58 +00:00
/usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs &
sleep 3
if [[ ! -f /home/cloudron/gogs/custom/conf/app.ini ]]; then
echo "Triggering installation"
mkdir -p /home/cloudron/gogs/custom/conf
touch /home/cloudron/gogs/custom/conf/app.ini
chown cloudron:cloudron /home/cloudron/gogs/custom/conf/app.ini
2015-06-24 18:36:12 +00:00
admin_password=$(pwgen -1)
echo "Admin password set to ${admin_password}"
# the values here are mostly overwritten by the template file below
2015-04-29 04:57:58 +00:00
curl -X POST http://localhost:3000/install \
--data db_type=MySQL \
--data-urlencode "db_host=${MYSQL_HOST}:${MYSQL_PORT}" \
--data "db_user=${MYSQL_USERNAME}" \
--data-urlencode "db_passwd=${MYSQL_PASSWORD}" \
--data "db_name=${MYSQL_DATABASE}" \
--data-urlencode "repo_root_path=/tmp" \
--data run_user=cloudron \
--data "domain=${fqdn}" \
--data http_port=3000 \
--data-urlencode "app_url=https://${fqdn}/" \
--data "smtp_host=${MAIL_SMTP_SERVER}" \
--data smtp_user= \
--data smtp_pwd= \
2015-04-29 19:57:27 +00:00
--data admin_name=administrator \
2015-06-24 18:36:12 +00:00
--data admin_passwd=${admin_password} \
2015-06-24 20:46:32 +00:00
--data admin_confirm_passwd=${admin_password} \
2015-06-24 22:18:30 +00:00
--data-urlencode admin_email=${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}
2015-04-29 04:57:58 +00:00
fi
# use GOGS_CONFIG maybe for this but not very documented
2015-04-29 00:12:16 +00:00
sed -e "s/##HOSTNAME/${fqdn}/g" \
-e "s/##SSH_PORT/${SSH_PORT}/g" \
-e "s/##MYSQL_HOST/${MYSQL_HOST}/g" \
-e "s/##MYSQL_PORT/${MYSQL_PORT}/g" \
-e "s/##MYSQL_USERNAME/${MYSQL_USERNAME}/g" \
-e "s/##MYSQL_PASSWORD/${MYSQL_PASSWORD}/g" \
-e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/g" \
-e "s/##MAIL_SERVER/${MAIL_SMTP_SERVER}/g" \
2015-04-29 02:29:12 +00:00
-e "s/##MAIL_PORT/${MAIL_SMTP_PORT}/g" \
2015-04-29 00:12:16 +00:00
-e "s/##MAIL_FROM/${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}/g" \
2015-04-29 04:57:58 +00:00
-e "s/##SECRET_KEY/$(pwgen -1 -s)/g" \
2015-04-29 00:12:16 +00:00
/home/cloudron/app.ini.template > "/home/cloudron/gogs/custom/conf/app.ini"
2015-06-24 18:01:16 +00:00
# update ldap (won't work without _csrf)
#curl -X POST http://localhost:3000/admin/auths/1 \
# --data id=1 \
# --data type=2 \
# --data name=cloudron \
# --data domain=cloudron \
# --data host=${LDAP_SERVER} \
# --data port=${LDAP_PORT} \
# --data-urlencode base_dn=ou=users,dc=cloudron \
# --data attribute_username=uid \
# --data attribute_name= \
# --data attribute_surname= \
# --data attribute_mail=mail \
# --data-urlencode 'filter=(&(objectClass=user)(uid=%s))' \
# --data ms_ad_sa= \
# --data is_actived=on
# id, type, name, is_actived, cfg, allow_auto_register, created, updated
2015-06-24 22:36:41 +00:00
mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
-e "REPLACE INTO login_source VALUES (1,2,'cloudron',1,'{\"Name\":\"cloudron\",\"Host\":\"${LDAP_SERVER}\",\"Port\":${LDAP_PORT},\"UseSSL\":false,\"BaseDN\":\"${LDAP_USERS_BASE_DN}\",\"AttributeUsername\":\"uid\",\"AttributeName\":\"\",\"AttributeSurname\":\"\",\"AttributeMail\":\"mail\",\"Filter\":\"(\\\\u0026(objectClass=user)(uid=%s))\",\"MsAdSAFormat\":\"cn=%s,${LDAP_USERS_BASE_DN}\",\"Enabled\":true}',1,'2015-06-24 17:14:12','2015-06-24 17:25:03');"
2015-06-24 18:01:16 +00:00
2015-04-29 04:57:58 +00:00
supervisorctl restart gogs
2015-04-29 02:29:12 +00:00
2015-04-29 04:57:58 +00:00
wait
2015-04-26 19:45:32 +00:00