mirror of
https://github.com/YunoHost-Apps/mobilizon_ynh.git
synced 2024-09-03 19:46:19 +02:00
125 lines
5 KiB
Bash
125 lines
5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
# Cleanup
|
|
ynh_secure_remove --file="$install_dir/$app/priv/data/GeoLite2-City.mmdb"
|
|
ynh_secure_remove --file="/usr/share/GeoIP"
|
|
|
|
# Move legacy configuration files
|
|
if [ ! -f "$install_dir/config.exs" ]; then
|
|
if [ -f "$install_dir/live/config/prod.secret.exs" ]; then
|
|
ynh_delete_file_checksum --file="$install_dir/live/config/prod.secret.exs"
|
|
mv -f "$install_dir/live/config/prod.secret.exs" "$install_dir/config.exs"
|
|
fi
|
|
if [ -f "$install_dir/live/config/runtime.exs" ]; then
|
|
ynh_delete_file_checksum --file="$install_dir/live/config/runtime.exs"
|
|
mv -f "$install_dir/live/config/runtime.exs" "$install_dir/config.exs"
|
|
fi
|
|
if [ -f "/etc/$app/config.exs" ]; then
|
|
ynh_delete_file_checksum --file="/etc/$app/config.exs"
|
|
mv -f "/etc/$app/config.exs" "$install_dir/config.exs"
|
|
ynh_secure_remove --file="/etc/$app"
|
|
fi
|
|
chown -R "$app:$app" "$install_dir/config.exs"
|
|
ynh_store_file_checksum --file="$install_dir/config.exs"
|
|
fi
|
|
# Check if previous "if block" did the job
|
|
if [ ! -f "$install_dir/config.exs" ]; then
|
|
ynh_die --message="Could not find a previous configuration file. Please contact maintainers on the forum."
|
|
fi
|
|
|
|
# Migrate data to data_dir
|
|
# FIXME: could be old, might be nice to remove
|
|
if [ -e "$install_dir/$app/uploads/" ] && [ -n "$(ls -A "$install_dir/$app/uploads/")" ]; then
|
|
ynh_script_progression --message="Moving data directory..."
|
|
rsync -a "$install_dir/$app/uploads/" "$data_dir/uploads/"
|
|
ynh_secure_remove "$install_dir/$app/uploads"
|
|
|
|
if grep "Mobilizon.Web.Upload.Uploader.Local" "$MOBILIZON_CONFIG_PATH" >/dev/null; then
|
|
ynh_replace_string --target_file="$MOBILIZON_CONFIG_PATH" \
|
|
--match_string="uploads: \".*/uploads\"" \
|
|
--replace_string="$data_dir/uploads"
|
|
else
|
|
ynh_add_config --template="uploads.exs" --destination="$install_dir/uploads.exs"
|
|
cat "$install_dir/uploads.exs" >> "$MOBILIZON_CONFIG_PATH"
|
|
ynh_secure_remove --file="$install_dir/uploads.exs"
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:www-data" "$install_dir"
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
ynh_backup_if_checksum_is_different --file="$MOBILIZON_CONFIG_PATH"
|
|
ynh_replace_string --match_string="adapter: Bamboo.SMTPAdapter," --replace_string="adapter: Swoosh.Adapters.SMTP," --target_file="$MOBILIZON_CONFIG_PATH"
|
|
ynh_replace_string --match_string="server: \"127.0.0.1\"," --replace_string="relay: \"127.0.0.1\"," --target_file="$MOBILIZON_CONFIG_PATH"
|
|
ynh_store_file_checksum --file="$MOBILIZON_CONFIG_PATH"
|
|
|
|
chmod 400 "$MOBILIZON_CONFIG_PATH"
|
|
chown "$app:$app" "$MOBILIZON_CONFIG_PATH"
|
|
|
|
#=================================================
|
|
# MAKE SETUP
|
|
#=================================================
|
|
ynh_script_progression --message="Migrating app..."
|
|
|
|
ynh_exec_as "$app" MOBILIZON_CONFIG_PATH="$MOBILIZON_CONFIG_PATH" "$install_dir/live/bin/mobilizon_ctl" migrate
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
yunohost service add "$app" --description="$app daemon for Mobilizon"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Mobilizon.Web.Endpoint at"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|