91 lines
2.8 KiB
Bash
Executable File
91 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
source ./_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:-/}")
|
|
if [ "$path" = "/" ]; then
|
|
nginx_path="/"
|
|
else
|
|
nginx_path="$path/"
|
|
fi
|
|
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 "$YNH_APP_BASEDIR/backend" "$YNH_APP_BASEDIR/web" "$YNH_APP_BASEDIR/doc" "$install_dir"/
|
|
|
|
cp "$YNH_APP_BASEDIR/conf/config.json" "$config_dir/config.json"
|
|
CONFIG_FILE="$config_dir/config.json" \
|
|
APP_PORT="$port" \
|
|
APP_PATH="$path" \
|
|
APP_DATA_DIR="$data_dir" \
|
|
APP_INSTALL_DIR="$install_dir" \
|
|
APP_ADMIN_USER="$admin_user" \
|
|
APP_ADMIN_PASSWORD="$admin_password" \
|
|
python3 - <<'PYCONF'
|
|
import os
|
|
from pathlib import Path
|
|
|
|
config_file = Path(os.environ["CONFIG_FILE"])
|
|
content = config_file.read_text()
|
|
|
|
replacements = {
|
|
"__PORT__": os.environ["APP_PORT"],
|
|
"__PATH__": os.environ["APP_PATH"],
|
|
"__DATA_DIR__": os.environ["APP_DATA_DIR"],
|
|
"__INSTALL_DIR__": os.environ["APP_INSTALL_DIR"],
|
|
"__ADMIN_USER__": os.environ["APP_ADMIN_USER"],
|
|
"__ADMIN_PASSWORD__": os.environ["APP_ADMIN_PASSWORD"],
|
|
}
|
|
|
|
for key, value in replacements.items():
|
|
content = content.replace(key, value)
|
|
|
|
config_file.write_text(content)
|
|
PYCONF
|
|
|
|
cp "$YNH_APP_BASEDIR/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 "$YNH_APP_BASEDIR/conf/nginx.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
sed -i \
|
|
-e "s#__PORT__#$port#g" \
|
|
-e "s#__PATH__#$nginx_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"
|