1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00
lstu_ynh/scripts/upgrade

242 lines
8.9 KiB
Text
Raw Normal View History

2017-04-21 12:54:39 +02:00
#!/bin/bash
#=================================================
2019-02-03 00:20:19 +01:00
# GENERIC START
2017-04-21 12:54:39 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2018-04-10 00:12:30 +02:00
source _common.sh
2017-04-21 12:54:39 +02:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
2017-04-21 12:54:39 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2017-04-21 12:54:39 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? is_public=$(ynh_app_setting_get --app=$app --key=is_public)
#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? secret=$(ynh_app_setting_get --app=$app --key=secret)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? theme=$(ynh_app_setting_get --app=$app theme)
#REMOVEME? hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password)
2017-04-21 12:54:39 +02:00
#=================================================
2020-04-19 05:16:46 +02:00
# CHECK VERSION
2017-04-21 12:54:39 +02:00
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Checking version..."
2017-04-21 12:54:39 +02:00
2020-04-19 05:16:46 +02:00
upgrade_type=$(ynh_check_app_version_changed)
2022-06-16 01:28:41 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2022-06-16 01:28:41 +02:00
# Backup the current version of the app
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2022-06-16 01:28:41 +02:00
ynh_clean_check_starting
# Restore it if the upgrade fails
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_restore_upgradebackup
2022-06-16 01:28:41 +02:00
}
# Exit if an error occurs during the execution of the script
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_abort_if_errors
2022-06-16 01:28:41 +02:00
#=================================================
# 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"
2020-04-19 05:16:46 +02:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Ensuring downward compatibility..."
2020-04-19 05:16:46 +02:00
2023-05-31 20:58:29 +02:00
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/var/www/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
2017-04-21 12:54:39 +02:00
fi
2019-02-03 19:31:09 +01:00
if [ -z "$db_pwd" ]; then
2023-05-31 20:58:29 +02:00
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) # Fix old db_pwd
2019-02-03 20:03:25 +01:00
if [ -z "$db_pwd" ]; then
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_psql_test_if_first_run
2020-04-19 21:54:21 +02:00
db_name=$(ynh_sanitize_dbid --db_name="$app")
2019-02-03 20:03:25 +01:00
db_user=$db_name
# Initialize database and store postgres password for upgrade
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name"
#REMOVEME? ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
#REMOVEME? #REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) # Password created in ynh_psql_setup_db function
2019-02-03 20:03:25 +01:00
else
2020-04-19 21:54:21 +02:00
ynh_app_setting_delete --app=$app --key=db_pwd
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd
2019-02-03 20:03:25 +01:00
fi
2019-02-03 19:31:09 +01:00
fi
2019-02-14 23:39:36 +01:00
if [ -z "$theme" ]; then
theme="milligram"
2020-04-19 21:54:21 +02:00
ynh_app_setting_set --app=$app --key=theme --value=$theme
2019-02-14 23:39:36 +01:00
fi
2019-02-14 23:41:28 +01:00
if [ -z "$hashed_password" ]; then
# Generate random password
2020-04-19 21:54:21 +02:00
password=$(ynh_string_random --length=8)
2019-02-15 00:25:31 +01:00
hashed_password=$(echo -n $password | sha256sum | cut -d' ' -f1)
2019-02-14 23:41:28 +01:00
2019-03-02 00:19:24 +01:00
echo "The new version of LSTU provide an admin and a stats area which required a password." > mail_to_send
echo "" >> mail_to_send
echo "This password is: $password" >> mail_to_send
2019-02-14 23:41:28 +01:00
2019-02-15 00:25:31 +01:00
ynh_send_readme_to_admin --app_message="mail_to_send" --type="upgrade"
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=hashed_password --value=$hashed_password
2019-02-14 23:41:28 +01:00
fi
2019-02-14 23:39:36 +01:00
# In previous versions, the port was mistakenly exposed to the outside world >_>
if yunohost firewall list | grep -q "\- $port$"
then
ynh_script_progression --message="Closing port $port..."
ynh_exec_warn_less yunohost firewall disallow TCP $port
fi
2021-06-20 23:23:08 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..."
2021-06-20 23:23:08 +02:00
# Create a dedicated user (if not existing)
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2021-06-20 23:23:08 +02:00
2019-02-03 00:20:19 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-04-19 05:16:46 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Upgrading source files..."
2019-02-03 00:20:19 +01:00
2020-04-19 05:16:46 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2023-05-31 20:58:29 +02:00
ynh_setup_source --dest_dir="$install_dir" #--keep="lstu.conf"
2020-04-19 05:16:46 +02:00
fi
2017-04-21 12:54:39 +02:00
2023-05-31 20:58:29 +02:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2021-06-20 23:23:08 +02:00
2017-04-21 12:54:39 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
# UPGRADE DEPENDENCIES
2017-04-21 12:54:39 +02:00
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..."
2017-04-21 12:54:39 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2017-04-21 12:54:39 +02:00
2020-04-19 05:16:46 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
# NGINX CONFIGURATION
2020-04-19 05:16:46 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2020-04-19 05:16:46 +02:00
2022-06-16 01:28:41 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2020-04-19 05:16:46 +02:00
2021-06-21 18:15:01 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
# SPECIFIC UPGRADE
2021-06-21 18:15:01 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
2021-06-21 18:15:01 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? if [ $is_public -eq 0 ];
2021-06-21 18:15:01 +02:00
then
2023-05-31 20:58:29 +02:00
ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$install_dir/lstu.conf"
2021-06-21 18:15:01 +02:00
else
2023-05-31 20:58:29 +02:00
ynh_add_config --template="../conf/lstu.conf.template" --destination="$install_dir/lstu.conf"
2021-06-21 18:15:01 +02:00
fi
2021-06-21 18:15:41 +02:00
#=================================================
# BUILD LSU
#=================================================
ynh_script_progression --message="Building lstu..."
2023-05-31 20:58:29 +02:00
pushd $install_dir
2021-06-21 18:15:41 +02:00
carton install --deployment --without=sqlite --without=mysql
popd
2022-06-16 01:28:41 +02:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Upgrading systemd configuration..."
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# GENERIC FINALIZATION
2017-04-21 12:54:39 +02:00
#=================================================
2019-02-03 00:20:19 +01:00
# SETUP LOGROTATE
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..."
2019-02-03 00:20:19 +01:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2019-02-03 00:20:19 +01:00
#=================================================
2022-06-16 01:28:41 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2017-04-21 12:54:39 +02:00
#=================================================
2022-06-16 01:28:41 +02:00
ynh_script_progression --message="Integrating service in YunoHost..."
2017-04-21 12:54:39 +02:00
2022-06-16 01:28:41 +02:00
yunohost service add $app --log="/var/log/$app.log" --log="/var/www/$app/log/production.log"
2017-04-21 12:54:39 +02:00
2020-11-26 18:32:46 +01:00
#=================================================
2022-06-16 01:28:41 +02:00
# START SYSTEMD SERVICE
2020-11-26 18:32:46 +01:00
#=================================================
2022-06-16 01:28:41 +02:00
ynh_script_progression --message="Starting a systemd service..."
2020-11-26 18:32:46 +01:00
2022-06-16 01:28:41 +02:00
ynh_systemd_action --service_name=$app --action=reload --line_match="Reloaded Shortened URLs service." --log_path="systemd"
2020-12-08 17:24:16 +01:00
2017-04-21 12:54:39 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Configuring permissions..."
2017-04-21 12:54:39 +02:00
2022-06-16 01:28:41 +02:00
# Everyone can access the app.
# The "main" permission is automatically created before the install script.
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_permission_update --permission="main" --add="visitors"
2021-04-22 23:52:56 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? if [ $is_public -eq 0 ]
2019-03-08 21:50:41 +01:00
then
# If the app is private, only the shortened URLs are publics.
2023-05-31 20:58:29 +02:00
if [ "$path" == "/" ]; then
2022-06-16 01:28:41 +02:00
# If the path is /, clear it to prevent any error with the regex.
2023-05-31 20:58:29 +02:00
path=""
2019-03-08 21:50:41 +01:00
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path/login$","$domain_regex$path/logout$","$domain_regex$path/api$","$domain_regex$path/extensions$","$domain_regex$path/stats$","$domain_regex$path/d/.*$","$domain_regex$path/a$","$domain_regex$path/$"
2017-04-21 12:54:39 +02:00
fi
#=================================================
# RELOAD NGINX
#=================================================
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..."
2017-04-21 12:54:39 +02:00
2023-05-31 20:58:29 +02:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-05-30 15:30:23 +02:00
ynh_script_progression --message="Upgrade of $app completed"