2021-11-10 19:58:54 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
2022-07-15 05:14:36 +02:00
|
|
|
db_user=$(ynh_app_setting_get --app=$app --key=db_user)
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2021-11-15 20:16:45 +01:00
|
|
|
port_web=$(ynh_app_setting_get --app=$app --key=port_web)
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-07-15 05:14:36 +02:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
2022-07-15 05:14:36 +02:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=${app}-web --action="stop" --log_path=systemd --line_match="Stopped"
|
|
|
|
ynh_systemd_action --service_name=${app}-sidekiq --action="stop" --log_path=systemd --line_match="Stopped"
|
|
|
|
|
2021-11-15 20:16:45 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If port_web doesn't exist, create it, needed for old install
|
|
|
|
if [[ -z "$port_web" ]]; then
|
|
|
|
port_web=3000
|
|
|
|
ynh_app_setting_set --app=$app --key=port_web --value=$port_web
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If db_pwd doesn't exist, create it, needed for old install
|
|
|
|
if [[ -z "$db_pwd" ]]; then
|
|
|
|
db_pwd=$(ynh_string_random)
|
|
|
|
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
|
|
|
|
ynh_psql_test_if_first_run
|
|
|
|
sudo --login --user=postgres psql -c"ALTER user $app WITH PASSWORD '$db_pwd'" postgres
|
|
|
|
ynh_replace_string --match_string="DB_PASS=" --replace_string="DB_PASS=${db_pwd}" --target_file="$config"
|
|
|
|
fi
|
|
|
|
|
|
|
|
ynh_remove_extra_repo
|
2022-07-15 15:35:26 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=redis_namespace
|
2022-07-15 15:37:06 +02:00
|
|
|
ynh_app_setting_delete --app=$app --key=secret_key_base
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
2022-07-15 05:14:36 +02:00
|
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version=$RUBY_VERSION
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-15 05:14:36 +02:00
|
|
|
# NGINX CONFIGURATION
|
2021-11-10 19:58:54 +01:00
|
|
|
#=================================================
|
2022-07-15 05:14:36 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2021-11-15 20:16:45 +01:00
|
|
|
|
2022-07-15 05:14:36 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2021-11-10 19:58:54 +01:00
|
|
|
#=================================================
|
2021-11-15 20:16:45 +01:00
|
|
|
# INSTALLING RUBY AND BUNDLER
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installing Ruby..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
|
|
|
ynh_use_ruby
|
|
|
|
ynh_gem install bundler:1.17.3 --no-document
|
|
|
|
ynh_exec_as $app echo "gem: --no-ri --no-rdoc" >> "$final_path/.gemrc"
|
|
|
|
popd
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
2021-11-15 20:16:45 +01:00
|
|
|
database_yml="$final_path/config/database.yml"
|
|
|
|
diaspora_toml="$final_path/config/diaspora.toml"
|
|
|
|
|
2022-07-15 17:22:00 +02:00
|
|
|
ynh_add_config --template="../conf/database.yml.example" --destination="$database_yml"
|
|
|
|
ynh_add_config --template="../conf/diaspora.toml.example" --destination="$diaspora_toml"
|
2021-11-15 20:16:45 +01:00
|
|
|
|
|
|
|
chmod 400 "$database_yml"
|
|
|
|
chown $app:$app "$database_yml"
|
|
|
|
|
|
|
|
chmod 400 "$diaspora_toml"
|
|
|
|
chown $app:$app "$diaspora_toml"
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2021-12-13 18:48:25 +01:00
|
|
|
ynh_add_systemd_config --service="$app-web" --template="acropolis-web.service"
|
|
|
|
ynh_add_systemd_config --service="$app-sidekiq" --template="acropolis-sidekiq.service"
|
2021-11-15 20:16:45 +01:00
|
|
|
|
2022-07-15 05:14:36 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE ACROPOLIS
|
|
|
|
#=================================================
|
2021-11-15 20:16:45 +01:00
|
|
|
ynh_script_progression --message="Upgrading acropolis..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
2022-07-15 15:44:56 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config deployment 'true'
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle config without 'development test'
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path bin/bundle install -j$(getconf _NPROCESSORS_ONLN)
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:clean
|
2022-07-16 01:08:24 +02:00
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake assets:precompile
|
|
|
|
ynh_exec_warn_less ynh_exec_as $app $ynh_ruby_load_path RAILS_ENV=production bin/rake db:migrate
|
2021-11-15 20:16:45 +01:00
|
|
|
popd
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
2021-11-15 20:16:45 +01:00
|
|
|
yunohost service add "$app-web" --description="$app web service"
|
|
|
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
2022-07-16 16:16:54 +02:00
|
|
|
ynh_systemd_action --service_name=${app}-web --action="start" --log_path=systemd --line_match="listening on"
|
|
|
|
ynh_systemd_action --service_name=${app}-sidekiq --action="start" --log_path=systemd --line_match="Booted Rails"
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2021-11-10 19:58:54 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-12-10 10:43:12 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|