peertube-app/start.sh

74 lines
3.1 KiB
Bash
Raw Normal View History

2020-06-16 04:47:04 +00:00
#!/bin/bash
set -eu
mkdir -p /app/data/storage
2020-10-15 04:45:44 +00:00
first_time_setup() {
2020-06-24 22:02:16 +00:00
sleep 10
2020-06-16 04:47:04 +00:00
while ! curl --fail http://localhost:9000/; do
echo "==> (reset root password) Waiting for peertube to initialize..."
2020-06-24 22:02:16 +00:00
sleep 5
2020-06-16 04:47:04 +00:00
done
2020-10-15 04:45:44 +00:00
echo "==> Reset root password"
2020-06-24 19:33:41 +00:00
echo "changeme" | npm run reset-password -- -u root
2020-10-15 04:45:44 +00:00
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
echo "==> Installing LDAP plugin"
cd /app/code/cli && node dist/server/tools/peertube.js plugins install -n peertube-plugin-auth-ldap --url "${CLOUDRON_APP_ORIGIN}" --username root --password changeme
fi
}
update_ldap() {
echo "==> Updating Ldap credentials"
PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} \
-c "UPDATE plugin SET settings='{\"url\": \"${CLOUDRON_LDAP_URL}\", \"weight\": 100, \"insecure-tls\": false, \"bind-dn\": \"${CLOUDRON_LDAP_BIND_DN}\", \"bind-credentials\": \"${CLOUDRON_LDAP_BIND_PASSWORD}\", \"search-base\": \"${CLOUDRON_LDAP_USERS_BASE_DN}\", \"mail-property\": \"mail\", \"search-filter\": \"(|(mail={{username}})(username={{username}}))\", \"username-property\": \"username\"}' WHERE name='auth-ldap'"
2020-06-16 04:47:04 +00:00
}
# cd /var/www/peertube/peertube-latest/scripts && sudo -H -u peertube ./upgrade.sh
if [[ ! -f "/app/data/production.yaml" ]]; then
echo "==> First run. creating config"
cp /app/pkg/production.yaml.example /app/data/production.yaml
# this is sed because there are too many paths
sed -e 's,/var/www/peertube/storage,/app/data/storage,g' -i /app/data/production.yaml
2020-10-15 04:45:44 +00:00
(first_time_setup && update_ldap) &
else
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
2020-06-16 04:47:04 +00:00
fi
echo "==> Updating configs"
yq w -i /app/data/production.yaml webserver.hostname "${CLOUDRON_APP_DOMAIN}"
# database
yq w -i /app/data/production.yaml database.hostname "${CLOUDRON_POSTGRESQL_HOST}"
yq w -i /app/data/production.yaml database.port "${CLOUDRON_POSTGRESQL_PORT}"
yq w -i /app/data/production.yaml database.username "${CLOUDRON_POSTGRESQL_USERNAME}"
yq w -i /app/data/production.yaml database.password "${CLOUDRON_POSTGRESQL_PASSWORD}"
yq w -i /app/data/production.yaml database.name "${CLOUDRON_POSTGRESQL_DATABASE}"
2020-07-21 20:12:54 +00:00
yq d -i /app/data/production.yaml database.suffix
2020-06-16 04:47:04 +00:00
# redis
yq w -i /app/data/production.yaml redis.hostname "${CLOUDRON_REDIS_HOST}"
yq w -i /app/data/production.yaml redis.port "${CLOUDRON_REDIS_PORT}"
yq w -i /app/data/production.yaml redis.auth "${CLOUDRON_REDIS_PASSWORD}"
# smtp
yq w -i /app/data/production.yaml smtp.hostname "${CLOUDRON_MAIL_SMTP_SERVER}"
yq w -i /app/data/production.yaml smtp.port "${CLOUDRON_MAIL_SMTP_PORT}"
yq w -i /app/data/production.yaml smtp.username "${CLOUDRON_MAIL_SMTP_USERNAME}"
yq w -i /app/data/production.yaml smtp.password "${CLOUDRON_MAIL_SMTP_PASSWORD}"
yq w -i /app/data/production.yaml smtp.tls false
yq w -i /app/data/production.yaml smtp.disable_starttls true
yq w -i /app/data/production.yaml smtp.from_address "${CLOUDRON_MAIL_FROM}"
chown -R cloudron:cloudron /app/data
echo "==> Starting PeerTube"
2020-06-16 04:47:04 +00:00
exec gosu cloudron:cloudron npm start