66 lines
2.1 KiB
Bash
Executable File
66 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
source ./scripts/_common.sh
|
|
|
|
# YunoHost install args
|
|
# packaging v2 passes these variables to scripts.
|
|
domain=${YNH_APP_ARG_DOMAIN:?Missing domain}
|
|
path=$(normalize_path "${YNH_APP_ARG_PATH:-/}")
|
|
admin_user=${YNH_APP_ARG_ADMIN_USER:-${YNH_APP_ARG_ADMIN:-admin}}
|
|
admin_password=${YNH_APP_ARG_ADMIN_PASSWORD:-${YNH_APP_ARG_PASSWORD:-}}
|
|
if [ -z "$admin_password" ]; then
|
|
echo "Admin password is required" >&2
|
|
exit 1
|
|
fi
|
|
port=$(find_free_port)
|
|
|
|
# Create dedicated app user when resources.system_user did not already do it.
|
|
if ! id "$app" >/dev/null 2>&1; then
|
|
useradd --system --home "$install_dir" --shell /usr/sbin/nologin "$app"
|
|
fi
|
|
|
|
mkdir -p "$install_dir" "$data_dir/data" "$data_dir/media/originals" "$data_dir/media/thumbs" "$data_dir/media/previews" "$data_dir/media/pending" "$data_dir/logs" "$config_dir"
|
|
cp -a backend web doc "$install_dir"/
|
|
|
|
cp conf/config.json "$config_dir/config.json"
|
|
sed -i \
|
|
-e "s#__PORT__#$port#g" \
|
|
-e "s#__PATH__#$path#g" \
|
|
-e "s#__DATA_DIR__#$data_dir#g" \
|
|
-e "s#__INSTALL_DIR__#$install_dir#g" \
|
|
-e "s#__ADMIN_USER__#$admin_user#g" \
|
|
-e "s#__ADMIN_PASSWORD__#$admin_password#g" \
|
|
"$config_dir/config.json"
|
|
|
|
cp conf/albumik.service "$service_file"
|
|
sed -i \
|
|
-e "s#__APP__#$app#g" \
|
|
-e "s#__DATA_DIR__#$data_dir#g" \
|
|
-e "s#__INSTALL_DIR__#$install_dir#g" \
|
|
"$service_file"
|
|
|
|
mkdir -p "/etc/nginx/conf.d/$domain.d"
|
|
cp conf/nginx.conf "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
sed -i \
|
|
-e "s#__PORT__#$port#g" \
|
|
-e "s#__PATH__#$path#g" \
|
|
"/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
chown -R "$app:$app" "$install_dir" "$data_dir" "$config_dir"
|
|
chmod 750 "$data_dir" "$config_dir"
|
|
chmod 640 "$config_dir/config.json"
|
|
|
|
# Save a few settings for remove/backup scripts if yunohost helpers are available.
|
|
if command -v yunohost >/dev/null 2>&1; then
|
|
yunohost app setting "$app" domain -v "$domain" || true
|
|
yunohost app setting "$app" path -v "$path" || true
|
|
yunohost app setting "$app" port -v "$port" || true
|
|
fi
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable --now "$app"
|
|
nginx -t
|
|
systemctl reload nginx
|
|
|
|
echo "Albumik installed: https://$domain$path"
|