peertube-app/start.sh

88 lines
3.7 KiB
Bash
Raw Normal View History

2020-06-16 04:47:04 +00:00
#!/bin/bash
set -eu
mkdir -p /app/data/storage /run/peertube/cache
2020-06-16 04:47:04 +00:00
2021-12-15 16:41:56 +00:00
# do not rely on WORKDIR
cd /app/code/server
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-10-15 04:45:44 +00:00
first_time_setup() {
2022-03-08 05:08:39 +00:00
echo "==> Starting peertube to run migrations on first run"
npm start & # be wary of https://stackoverflow.com/questions/70738567/why-does-running-npm-run-script-as-root-switch-user
peertube_pid=$!
2020-06-24 22:02:16 +00:00
sleep 10
2021-09-13 20:13:22 +00:00
while ! curl --silent --output /dev/null --fail http://localhost:9000/; do
2022-03-08 05:08:39 +00:00
echo "==> Waiting for peertube"
2020-06-24 22:02:16 +00:00
sleep 5
2020-06-16 04:47:04 +00:00
done
2022-03-08 05:08:39 +00:00
kill -SIGTERM ${peertube_pid} # this kills the process group
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
2022-03-08 05:08:39 +00:00
# https://docs.joinpeertube.org/maintain-tools?id=cli-wrapper . Note that we have to restart peertube when installed this way
2020-10-15 04:45:44 +00:00
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
echo "==> Installing LDAP plugin"
2022-03-08 05:08:39 +00:00
npm run plugin:install -- -n peertube-plugin-auth-ldap -v 0.0.10
update_ldap
2020-10-15 04:45:44 +00:00
fi
}
update_config() {
echo "==> Ensure and updating configs"
yq eval ".webserver.hostname = \"${CLOUDRON_APP_DOMAIN}\"" -i /app/data/production.yaml
# database
yq eval ".database.hostname = \"${CLOUDRON_POSTGRESQL_HOST}\"" -i /app/data/production.yaml
yq eval ".database.port = ${CLOUDRON_POSTGRESQL_PORT}" -i /app/data/production.yaml
yq eval ".database.username = \"${CLOUDRON_POSTGRESQL_USERNAME}\"" -i /app/data/production.yaml
yq eval ".database.password = \"${CLOUDRON_POSTGRESQL_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".database.name = \"${CLOUDRON_POSTGRESQL_DATABASE}\"" -i /app/data/production.yaml
yq eval "del(.database.suffix)" -i /app/data/production.yaml
# redis
yq eval ".redis.hostname = \"${CLOUDRON_REDIS_HOST}\"" -i /app/data/production.yaml
yq eval ".redis.port = ${CLOUDRON_REDIS_PORT}" -i /app/data/production.yaml
yq eval ".redis.auth = \"${CLOUDRON_REDIS_PASSWORD}\"" -i /app/data/production.yaml
# smtp
yq eval ".smtp.hostname = \"${CLOUDRON_MAIL_SMTP_SERVER}\"" -i /app/data/production.yaml
yq eval ".smtp.port = ${CLOUDRON_MAIL_SMTP_PORT}" -i /app/data/production.yaml
yq eval ".smtp.username = \"${CLOUDRON_MAIL_SMTP_USERNAME}\"" -i /app/data/production.yaml
yq eval ".smtp.password = \"${CLOUDRON_MAIL_SMTP_PASSWORD}\"" -i /app/data/production.yaml
yq eval ".smtp.tls = false" -i /app/data/production.yaml
yq eval ".smtp.disable_starttls = true" -i /app/data/production.yaml
yq eval ".smtp.from_address = \"${CLOUDRON_MAIL_FROM}\"" -i /app/data/production.yaml
yq eval ".storage.bin = \"/app/data/storage/bin/\"" -i /app/data/production.yaml
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
update_config
2022-03-08 05:08:39 +00:00
first_time_setup
2020-10-15 04:45:44 +00:00
else
update_config
2020-10-15 04:45:44 +00:00
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
fi
chown -R cloudron:cloudron /app/data /run/peertube
2020-06-16 04:47:04 +00:00
echo "==> Starting PeerTube"
2020-06-16 04:47:04 +00:00
exec gosu cloudron:cloudron npm start