1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pleroma_ynh.git synced 2024-09-03 20:15:59 +02:00
This commit is contained in:
YunoHost Bot 2024-08-31 13:28:35 +02:00 committed by GitHub
commit 063d2fd1af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 133 additions and 189 deletions

View file

@ -21,6 +21,7 @@ fund = "https://liberapay.com/Pleroma-euro/"
[integration] [integration]
yunohost = ">=11.2" yunohost = ">=11.2"
helpers_version = "2.1"
architectures = ["amd64", "armhf", "arm64"] architectures = ["amd64", "armhf", "arm64"]
multi_instance = false multi_instance = false
ldap = true ldap = true

View file

@ -1,22 +1,10 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
#=================================================
# PERSONAL HELPERS
#================================================= #=================================================
boolstr() { boolstr() {
bool=("false" "true") bool=("false" "true")
echo "${bool[$1]}" echo "${bool[$1]}"
} }
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,52 +1,43 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# BACKUP THE DATA DIR # BACKUP THE DATA DIR
#================================================= #=================================================
ynh_backup --src_path="$data_dir" --is_big ynh_backup "$data_dir"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_backup --src_path="/etc/nginx/conf.d/$app-cache.conf" --not_mandatory ynh_backup "/etc/nginx/conf.d/$app-cache.conf" || true
ynh_backup --src_path="/etc/systemd/system/$app.service" ynh_backup "/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/$app/" ynh_backup "/etc/$app/"
#================================================= #=================================================
# BACKUP THE POSTGRESQL DATABASE # BACKUP THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_print_info --message="Backing up the PostgreSQL database..." ynh_print_info "Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql ynh_psql_dump_db > db.sql
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -1,55 +1,45 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" ynh_systemctl --service=$app --action="stop" --log_path=systemd --wait_until="Stopped $app"
pkill -u "$app" || true pkill -u "$app" || true
#================================================= #=================================================
# MODIFY URL IN NGINX CONF # MODIFY URL IN NGINX CONF
#================================================= #=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1 ynh_script_progression "Updating NGINX web server configuration..."
ynh_change_url_nginx_config ynh_config_change_url_nginx
#================================================= #=================================================
# SPECIFIC MODIFICATIONS # SPECIFIC MODIFICATIONS
#================================================= #=================================================
# MODIFY A CONFIG FILE # MODIFY A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Modifying a config file..." --weight=1 ynh_script_progression "Updating configuration..."
config="/etc/$app/config.exs" config="/etc/$app/config.exs"
ynh_backup_if_checksum_is_different --file="$config" ynh_backup_if_checksum_is_different "$config"
ynh_replace_string --match_string="$old_domain" --replace_string="$new_domain" --target_file="$config" ynh_replace --match="$old_domain" --replace="$new_domain" --file="$config"
ynh_store_file_checksum --file="$config" ynh_store_file_checksum "$config"
#=================================================
# GENERIC FINALISATION
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="Access Pleroma.Web.Endpoint"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Change of URL completed for $app" --last ynh_script_progression "Change of URL completed for $app"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -15,14 +9,14 @@ source /usr/share/yunohost/helpers
path="/" path="/"
random_key=$(ynh_string_random --length=64) random_key=$(ynh_string_random --length=64)
ynh_app_setting_set --app="$app" --key=random_key --value="$random_key" ynh_app_setting_set --key=random_key --value="$random_key"
signing_salt=$(ynh_string_random --length=8) signing_salt=$(ynh_string_random --length=8)
ynh_app_setting_set --app="$app" --key=signing_salt --value="$signing_salt" ynh_app_setting_set --key=signing_salt --value="$signing_salt"
admin_email=$(ynh_user_get_info --username="$admin" --key="mail") admin_email=$(ynh_user_get_info --username="$admin" --key="mail")
ynh_app_setting_set --app="$app" --key=admin_email --value="$admin_email" ynh_app_setting_set --key=admin_email --value="$admin_email"
## Bypass package_checker name not compatible with pleroma ## Bypass package_checker name not compatible with pleroma
if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then if ynh_in_ci_tests; then
admin="test" admin="test"
fi fi
@ -31,50 +25,52 @@ fi
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Setting up source files..." --weight=1 ynh_script_progression "Setting up source files..."
# Download, check integrity, uncompress and patch the source from manifest.toml # Download, check integrity, uncompress and patch the source from manifest.toml
ynh_setup_source --dest_dir="$install_dir/live" ynh_setup_source --dest_dir="$install_dir/live"
chown -R "$app:www-data" "$install_dir" #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:www-data" "$install_dir"
#================================================= #=================================================
# UPDATE THE POSTGRESQL DATABASE # UPDATE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Configuring the PostgreSQL database..." --weight=1 ynh_script_progression "Configuring the PostgreSQL database..."
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS citext;"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
#================================================= #=================================================
# SYSTEM CONFIGURATION # SYSTEM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 ynh_script_progression "Adding system configurations related to $app..."
if [ "$cache" -eq 1 ]; then if [ "$cache" -eq 1 ]; then
ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" ynh_config_add --template="cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf"
cat ../conf/media.conf >> ../conf/nginx.conf cat ../conf/media.conf >> ../conf/nginx.conf
fi fi
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
yunohost service add "$app" --description="$app daemon for Pleroma" yunohost service add "$app" --description="$app daemon for Pleroma"
#================================================= #=================================================
# MAKE SETUP # MAKE SETUP
#================================================= #=================================================
ynh_script_progression --message="Making setup..." --weight=1 ynh_script_progression "Making setup..."
config="/etc/$app/config.exs" config="/etc/$app/config.exs"
mkdir -p "/etc/$app" mkdir -p "/etc/$app"
chown "$app:$app" "/etc/$app" chown "$app:$app" "/etc/$app"
# Generate instance # Generate instance
ynh_exec_warn_less ynh_exec_as "$app" -i \ ynh_hide_warnings ynh_exec_as_app -i \
"$install_dir/live/bin/pleroma_ctl" instance gen \ "$install_dir/live/bin/pleroma_ctl" instance gen \
--force \ --force \
--output "$config" \ --output "$config" \
@ -101,34 +97,34 @@ ynh_exec_warn_less ynh_exec_as "$app" -i \
cat "../conf/ldap.exs" >> "$config" cat "../conf/ldap.exs" >> "$config"
ynh_replace_string --target_file="$config" \ ynh_replace --file="$config" \
--match_string="config :pleroma, configurable_from_database: false" \ --match="config :pleroma, configurable_from_database: false" \
--replace_string="config :pleroma, configurable_from_database: true" --replace="config :pleroma, configurable_from_database: true"
ynh_replace_string --target_file="$config" \ ynh_replace --file="$config" \
--match_string="registrations_open: true" \ --match="registrations_open: true" \
--replace_string="registrations_open: $(boolstr "$registration")" --replace="registrations_open: $(boolstr "$registration")"
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" migrate ynh_hide_warnings ynh_exec_as_app -i "$install_dir/live/bin/pleroma_ctl" migrate
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="Access Pleroma.Web.Endpoint"
# Add user # Add user
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" user new "$admin" "$admin_email" --password "$password" --moderator --admin -y ynh_hide_warnings ynh_exec_as_app -i "$install_dir/live/bin/pleroma_ctl" user new "$admin" "$admin_email" --password "$password" --moderator --admin -y
ynh_systemd_action --service_name="$app" --action="stop" --log_path=systemd ynh_systemctl --service="$app" --action="stop" --log_path=systemd
# Calculate and store the config file checksum into the app settings # Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$config" ynh_store_file_checksum "$config"
chmod 400 "$config" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$config"
chown "$app:$app" "$config" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$config"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="Access Pleroma.Web.Endpoint"
#================================================= #=================================================
# POST INSTALL # POST INSTALL
@ -136,10 +132,10 @@ ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --l
# Correct path to 'static dir' in DB # Correct path to 'static dir' in DB
# This must be done when Pleroma is running (i.e. after install and start) # This must be done when Pleroma is running (i.e. after install and start)
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" config migrate_to_db ynh_hide_warnings ynh_exec_as_app -i "$install_dir/live/bin/pleroma_ctl" config migrate_to_db
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,38 +1,32 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE SYSTEM CONFIGURATIONS # REMOVE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) # Remove the service from the list of services known by YunoHost (added from `yunohost service add`)
if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then if ynh_hide_warnings yunohost service status "$app" >/dev/null; then
ynh_script_progression --message="Removing $app service integration..." --weight=1 ynh_script_progression "Removing $app service integration..."
yunohost service remove "$app" yunohost service remove "$app"
fi fi
# Remove the dedicated systemd config # Remove the dedicated systemd config
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" ynh_systemctl --service=$app --action="stop" --log_path=systemd --wait_until="Stopped $app"
pkill -u "$app" || true pkill -u "$app" || true
ynh_remove_systemd_config ynh_config_remove_systemd
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
ynh_secure_remove --file="/etc/nginx/conf.d/$app-cache.conf" ynh_safe_rm "/etc/nginx/conf.d/$app-cache.conf"
ynh_secure_remove --file="/etc/$app" ynh_safe_rm "/etc/$app"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,66 +7,67 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$install_dir"
chown -R "$app:$app" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir"
#================================================= #=================================================
# RESTORE THE DATA DIRECTORY # RESTORE THE DATA DIRECTORY
#================================================= #=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1 ynh_script_progression "Restoring the data directory..."
ynh_restore_file --origin_path="$data_dir" --not_mandatory ynh_restore "$data_dir"
chown -R "$app:$app" "$data_dir" chown -R "$app:$app" "$data_dir"
#================================================= #=================================================
# RESTORE THE POSTGRESQL DATABASE # RESTORE THE POSTGRESQL DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1 ynh_script_progression "Restoring the PostgreSQL database..."
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS unaccent;"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name"
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS citext;"
ynh_psql_db_shell <<< "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
ynh_psql_db_shell " < "./db.sql""
#================================================= #=================================================
# RESTORE SYSTEM CONFIGURATIONS # RESTORE SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_script_progression "Restoring system configurations related to $app..."
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$app-cache.conf" --not_mandatory ynh_restore "/etc/nginx/conf.d/$app-cache.conf" || true
ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore "/etc/systemd/system/$app.service"
systemctl enable "$app.service" --quiet systemctl enable "$app.service" --quiet
yunohost service add "$app" --description="$app daemon for Pleroma" yunohost service add "$app" --description="$app daemon for Pleroma"
#================================================= #=================================================
# RESTORE VARIOUS FILES # RESTORE VARIOUS FILES
#================================================= #=================================================
ynh_script_progression --message="Restoring various files..." --weight=1 ynh_script_progression "Restoring various files..."
ynh_restore_file --origin_path="/etc/$app/" ynh_restore "/etc/$app/"
chmod 400 "/etc/$app/config.exs" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "/etc/$app/config.exs"
chown "$app:$app" "/etc/$app/config.exs" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "/etc/$app/config.exs"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 ynh_script_progression "Reloading NGINX web server and $app's service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="Access Pleroma.Web.Endpoint"
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,22 +1,14 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# STOP SYSTEMD SERVICE # STOP SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_script_progression "Stopping $app's systemd service..."
ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped $app" ynh_systemctl --service=$app --action="stop" --log_path=systemd --wait_until="Stopped $app"
if ynh_compare_current_package_version --comparison gt --version "1.1.1~ynh1"; then if ynh_compare_current_package_version --comparison gt --version "1.1.1~ynh1"; then
pkill -u "$app" || true pkill -u "$app" || true
@ -25,20 +17,20 @@ fi
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
if [ -n "${psql_db:-}" ]; then if [ -n "${psql_db:-}" ]; then
ynh_app_setting_delete --app="$app" --key=psql_db ynh_app_setting_delete --key=psql_db
fi fi
# Close a port # Close a port
if yunohost firewall list | grep -q "\- $port$"; then if yunohost firewall list | grep -q "\- $port$"; then
ynh_script_progression --message="Closing port $port..." ynh_script_progression "Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP "$port" ynh_hide_warnings yunohost firewall disallow TCP "$port"
fi fi
# Remove old repository # Remove old repository
ynh_secure_remove --file="/etc/apt/sources.list.d/erlang-solutions.list" ynh_safe_rm "/etc/apt/sources.list.d/erlang-solutions.list"
apt-key del A14F4FCA apt-key del A14F4FCA
# Switch to $install_dir/live # Switch to $install_dir/live
@ -48,8 +40,8 @@ fi
config="/etc/$app/config.exs" config="/etc/$app/config.exs"
if ynh_compare_current_package_version --comparison le --version "1.1.1~ynh1"; then if ynh_app_upgrading_from_version_before_or_equal_to 1.1.1~ynh1; then
ynh_script_progression --message="Upgrading to OTP release..." --weight=1 ynh_script_progression "Upgrading to OTP release..."
# Give permission to the data_dir # Give permission to the data_dir
chown -R "$app":"$app" "$data_dir" chown -R "$app":"$app" "$data_dir"
@ -63,88 +55,85 @@ if ynh_compare_current_package_version --comparison le --version "1.1.1~ynh1"; t
mkdir -p "/etc/$app" mkdir -p "/etc/$app"
chown -R "$app" "/etc/$app" chown -R "$app" "/etc/$app"
mv "$install_dir/live/config/prod.secret.exs" "$config" mv "$install_dir/live/config/prod.secret.exs" "$config"
ynh_replace_string --target_file="$config" \ ynh_replace --file="$config" \
--match_string="use Mix.Config" \ --match="use Mix.Config" \
--replace_string="import Config" --replace="import Config"
echo "config :pleroma, :instance, static_dir: \"/home/yunohost.app/$app/static\"" >> "$config" echo "config :pleroma, :instance, static_dir: \"/home/yunohost.app/$app/static\"" >> "$config"
echo "config :pleroma, Pleroma.Uploaders.Local, uploads: \"/home/yunohost.app/$app/uploads\"" >> "$config" echo "config :pleroma, Pleroma.Uploaders.Local, uploads: \"/home/yunohost.app/$app/uploads\"" >> "$config"
ynh_backup_if_checksum_is_different --file="$config" ynh_backup_if_checksum_is_different "$config"
fi fi
if ynh_compare_current_package_version --comparison le --version "2.0.5~ynh1"; then if ynh_app_upgrading_from_version_before_or_equal_to 2.0.5~ynh1; then
cat "../conf/ldap.exs" >> "$config" cat "../conf/ldap.exs" >> "$config"
fi fi
if ynh_compare_current_package_version --comparison lt --version "2.5.5~ynh2"; then if ynh_app_upgrading_from_version_before 2.5.5~ynh2; then
# packaging v1 did not set a shell # packaging v1 did not set a shell
usermod -s /bin/sh "$app" usermod -s /bin/sh "$app"
fi fi
ynh_replace_string --target_file="$config" \ ynh_replace --file="$config" \
--match_string="config :pleroma, configurable_from_database: false" \ --match="config :pleroma, configurable_from_database: false" \
--replace_string="config :pleroma, configurable_from_database: true" --replace="config :pleroma, configurable_from_database: true"
ynh_replace_string --target_file="$config" \ ynh_replace --file="$config" \
--match_string='registrations_open: true' \ --match='registrations_open: true' \
--replace_string="registrations_open: $(boolstr "$registration")" --replace="registrations_open: $(boolstr "$registration")"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # DOWNLOAD, CHECK AND UNPACK SOURCE
#================================================= #=================================================
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression "Upgrading source files..."
ynh_setup_source --dest_dir="$install_dir/live" --full_replace=1 ynh_setup_source --dest_dir="$install_dir/live" --full_replace
chown -R "$app:$app" "$install_dir"
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir"
#================================================= #=================================================
# REAPPLY SYSTEM CONFIGURATIONS # REAPPLY SYSTEM CONFIGURATIONS
#================================================= #=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_script_progression "Upgrading system configurations related to $app..."
if [ "$cache" -eq 1 ]; then if [ "$cache" -eq 1 ]; then
ynh_add_config --template="../conf/cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf" ynh_config_add --template="cache.conf" --destination="/etc/nginx/conf.d/$app-cache.conf"
cat ../conf/media.conf >> ../conf/nginx.conf cat ../conf/media.conf >> ../conf/nginx.conf
fi fi
# Create a dedicated NGINX config # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
# Create a dedicated systemd config # Create a dedicated systemd config
ynh_add_systemd_config ynh_config_add_systemd
yunohost service add "$app" --description="$app daemon for Pleroma" yunohost service add "$app" --description="$app daemon for Pleroma"
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# MAKE UPGRADE # MAKE UPGRADE
#================================================= #=================================================
ynh_script_progression --message="Making upgrade..." --weight=1 ynh_script_progression "Making upgrade..."
ynh_exec_warn_less ynh_exec_as "$app" -i "$install_dir/live/bin/pleroma_ctl" migrate ynh_hide_warnings ynh_exec_as_app -i "$install_dir/live/bin/pleroma_ctl" migrate
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression "Updating configuration..."
config="/etc/$app/config.exs" config="/etc/$app/config.exs"
ynh_backup_if_checksum_is_different --file="$config" ynh_backup_if_checksum_is_different "$config"
chmod 400 "$config" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$config"
chown "$app:$app" "$config" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown "$app:$app" "$config"
#================================================= #=================================================
# START SYSTEMD SERVICE # START SYSTEMD SERVICE
#================================================= #=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_script_progression "Starting $app's systemd service..."
ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="Access Pleroma.Web.Endpoint" ynh_systemctl --service="$app" --action="start" --log_path=systemd --wait_until="Access Pleroma.Web.Endpoint"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"