peertube-app/start.sh
2021-12-16 16:11:13 +01:00

92 lines
4.1 KiB
Bash
Executable file

#!/bin/bash
set -eu
mkdir -p /app/data/storage
# 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'"
}
first_time_setup() {
sleep 10
while ! curl --silent --output /dev/null --fail http://localhost:9000/; do
echo "==> (reset root password) Waiting for peertube to initialize..."
sleep 5
done
echo "==> Reset root password"
echo "changeme" | npm run reset-password -- -u root
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
update_ldap
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
echo "==> Migrate config file attributes for v4"
# v4 config file migrations https://github.com/Chocobozzz/PeerTube/releases/tag/v4.0.0
yq eval "del(.log.rotation.maxFileSize)" -i /app/data/production.yaml
yq eval "del(.log.rotation.maxFiles)" -i /app/data/production.yaml
yq eval "del(.log.anonymizeIP)" -i /app/data/production.yaml
yq eval ".log.rotation.max_file_size = \"1MB\"" -i /app/data/production.yaml
yq eval ".log.rotation.max_files = 1" -i /app/data/production.yaml
yq eval ".log.anonymizeIP = false" -i /app/data/production.yaml
yq eval ".storage.bin = \"/app/data/storage/bin/\"" -i /app/data/production.yaml
}
# 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
first_time_setup &
else
update_config
[[ -n "${CLOUDRON_LDAP_SERVER:-}" ]] && update_ldap
echo "==> Migrate HLS paths to new for v4"
node dist/scripts/migrations/peertube-4.0.js
fi
chown -R cloudron:cloudron /app/data
echo "==> Starting PeerTube"
exec gosu cloudron:cloudron npm start