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

243 lines
8.4 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
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Loading installation settings..."
2017-04-21 12:54:39 +02:00
app=$YNH_APP_INSTANCE_NAME
2020-04-19 05:16:46 +02:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
secret=$(ynh_app_setting_get --app=$app --key=secret)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
2019-02-03 00:20:19 +01:00
db_user=$db_name
2020-04-19 05:16:46 +02:00
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
theme=$(ynh_app_setting_get --app=$app theme)
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)
#=================================================
# 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
# If final_path doesn't exist, create it
if [ -z "$final_path" ]; then
2017-04-21 12:54:39 +02:00
final_path=/var/www/$app
2020-04-19 05:16:46 +02:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
2017-04-21 12:54:39 +02:00
fi
2019-02-03 19:31:09 +01:00
if [ -z "$db_pwd" ]; then
2020-04-19 21:54:21 +02:00
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
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
2020-04-19 21:54:21 +02:00
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name"
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
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
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"
2020-04-19 21:54:21 +02:00
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-04-22 23:52:56 +02:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
2019-02-21 14:12:16 +01:00
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
2020-04-19 05:16:46 +02:00
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Stopping a systemd service..."
2020-04-19 05:16:46 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
2021-06-20 23:23:08 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
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
2021-06-21 18:15:01 +02:00
ynh_setup_source --dest_dir="$final_path" #--keep="$final_path/lstu.conf"
2020-04-19 05:16:46 +02:00
fi
2017-04-21 12:54:39 +02:00
2021-06-20 23:23:08 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2017-04-21 12:54:39 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2020-11-16 16:41:23 +01:00
ynh_script_progression --message="Upgrading NGINX web server configuration..."
2017-04-21 12:54:39 +02:00
2019-02-03 00:20:19 +01:00
# Create a dedicated nginx config
ynh_add_nginx_config
2017-04-21 12:54:39 +02:00
2020-04-19 05:16:46 +02:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Upgrading dependencies..."
2020-04-19 05:16:46 +02:00
2022-05-21 00:02:24 +02:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2020-04-19 05:16:46 +02:00
2021-06-21 18:15:01 +02:00
#=================================================
# CONFIGURE LSTU
#=================================================
ynh_script_progression --message="Configuring Lstu..."
if [ $is_public -eq 0 ];
then
ynh_add_config --template="../conf/lstu.conf.ldap" --destination="$final_path/lstu.conf"
else
ynh_add_config --template="../conf/lstu.conf.template" --destination="$final_path/lstu.conf"
fi
2021-06-21 18:15:41 +02:00
#=================================================
# BUILD LSU
#=================================================
ynh_script_progression --message="Building lstu..."
pushd $final_path
carton install --deployment --without=sqlite --without=mysql
popd
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
#=================================================
2020-04-19 05:16:46 +02:00
# SETUP SYSTEMD
2017-04-21 12:54:39 +02:00
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Upgrading systemd configuration..."
2017-04-21 12:54:39 +02:00
2020-04-19 05:16:46 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
2017-04-21 12:54:39 +02:00
2020-11-26 18:32:46 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..."
2020-12-08 17:24:16 +01: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
#=================================================
# SETUP SSOWAT
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Upgrading SSOwat configuration..."
2017-04-21 12:54:39 +02:00
2021-04-22 23:52:56 +02:00
ynh_permission_update --permission="main" --add="visitors"
2019-03-08 21:50:41 +01:00
if [ $is_public -eq 0 ]
then
# If the app is private, only the shortened URLs are publics.
if [ "$path_url" == "/" ]; then
# If the path is /, clear it to prevent any error with the regex.
path_url=""
fi
# Modify the domain to be used in a regex
domain_regex=$(echo "$domain" | sed 's@-@.@g')
2020-04-19 05:16:46 +02:00
ynh_app_setting_set --app=$app --key=protected_regex --value="$domain_regex$path_url/login$","$domain_regex$path_url/logout$","$domain_regex$path_url/api$","$domain_regex$path_url/extensions$","$domain_regex$path_url/stats$","$domain_regex$path_url/d/.*$","$domain_regex$path_url/a$","$domain_regex$path_url/$"
2017-04-21 12:54:39 +02:00
fi
2020-04-19 05:16:46 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-05-30 15:28:48 +02:00
ynh_script_progression --message="Starting a systemd service..."
2020-04-19 05:16:46 +02:00
2020-04-19 21:54:21 +02:00
ynh_systemd_action --service_name=$app --action=reload --line_match="Reloaded Shortened URLs service." --log_path="systemd"
2020-04-19 05:16:46 +02:00
2017-04-21 12:54:39 +02:00
#=================================================
# RELOAD NGINX
#=================================================
2020-11-16 16:41:23 +01:00
ynh_script_progression --message="Reloading NGINX web server..."
2017-04-21 12:54:39 +02:00
2020-04-19 05:16:46 +02:00
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"