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
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Loading installation settings..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2019-02-03 00:20:19 +01:00
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
2017-04-21 12:54:39 +02:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
secret=$(ynh_app_setting_get $app secret)
|
2019-02-03 00:20:19 +01:00
|
|
|
db_name=$(ynh_app_setting_get $app db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
db_pwd=$(ynh_app_setting_get $app psqlpwd)
|
2019-02-14 23:39:36 +01:00
|
|
|
theme=$(ynh_app_setting_get $app theme)
|
2019-02-14 23:41:28 +01:00
|
|
|
hashed_password=$(ynh_app_setting_get $app hashed_password)
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FIX OLD THINGS
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Ensuring downward compatibility..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
|
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 0
|
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${#final_path}" -eq 0 ]
|
|
|
|
then # Si final_path n'est pas renseigné dans la config yunohost, cas d'ancien script, code final_path en dur
|
|
|
|
final_path=/var/www/$app
|
|
|
|
fi
|
|
|
|
|
2019-02-03 19:31:09 +01:00
|
|
|
if [ -z "$db_pwd" ]; then
|
|
|
|
db_pwd=$(ynh_app_setting_get $app db_pwd) # Fix old db_pwd
|
2019-02-03 20:03:25 +01:00
|
|
|
if [ -z "$db_pwd" ]; then
|
|
|
|
db_name=$(ynh_sanitize_dbid "$app")
|
|
|
|
db_user=$db_name
|
|
|
|
# Initialize database and store postgres password for upgrade
|
|
|
|
ynh_psql_setup_db "$db_name" "$db_user"
|
|
|
|
ynh_app_setting_set "$app" db_name "$db_name"
|
|
|
|
db_pwd=$(ynh_app_setting_get $app psqlpwd) # Password created in ynh_psql_setup_db function
|
|
|
|
else
|
|
|
|
ynh_app_setting_delete $app db_pwd
|
|
|
|
ynh_app_setting_set $app psqlpwd $db_pwd
|
|
|
|
fi
|
2019-02-03 19:31:09 +01:00
|
|
|
fi
|
|
|
|
|
2019-02-14 23:39:36 +01:00
|
|
|
if [ -z "$theme" ]; then
|
|
|
|
theme="milligram"
|
|
|
|
ynh_app_setting_set $app theme $theme
|
|
|
|
fi
|
|
|
|
|
2019-02-14 23:41:28 +01:00
|
|
|
if [ -z "$hashed_password" ]; then
|
|
|
|
# Generate random password
|
2019-02-18 23:20:31 +01:00
|
|
|
password=$(ynh_string_random 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"
|
|
|
|
|
|
|
|
ynh_app_setting_set $app hashed_password $hashed_password
|
2019-02-14 23:41:28 +01:00
|
|
|
fi
|
2019-02-14 23:39:36 +01:00
|
|
|
|
2019-02-21 14:08:27 +01:00
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "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
|
2019-02-21 14:08:27 +01:00
|
|
|
# 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
|
2019-02-03 00:20:19 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Upgrading source files..."
|
2019-02-03 00:20:19 +01:00
|
|
|
|
2019-02-21 00:36:05 +01:00
|
|
|
ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql cpanminus
|
2019-02-03 00:20:19 +01:00
|
|
|
|
|
|
|
ynh_setup_source "$final_path"
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "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
|
|
|
|
2019-02-21 14:08:27 +01:00
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
ynh_print_info "Making sure dedicated system user exists..."
|
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
2017-04-21 12:54:39 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# SETUP LSTU
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Upgrading lstu configuration..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
2019-02-03 00:20:19 +01:00
|
|
|
ynh_backup_if_checksum_is_different "$final_path/lstu.conf"
|
|
|
|
cp ../conf/lstu.conf.template "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__DOMAIN__" "$domain" "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__PATH__" "$path_url" "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__DB_NAME__" "$db_name" "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__DB_USER__" "$db_user" "${final_path}/lstu.conf"
|
|
|
|
ynh_replace_string "__DB_PWD__" "$db_pwd" "${final_path}/lstu.conf"
|
2019-02-14 23:39:36 +01:00
|
|
|
ynh_replace_string "__SELECTED_THEME__" "$theme" "${final_path}/lstu.conf"
|
2019-02-14 23:41:28 +01:00
|
|
|
ynh_replace_string "__PASSWORD_HASHED__" "$hashed_password" "${final_path}/lstu.conf"
|
2019-02-03 00:20:19 +01:00
|
|
|
|
|
|
|
ynh_replace_string "__SECRET__" "$secret" "${final_path}/lstu.conf"
|
2019-02-16 00:11:00 +01:00
|
|
|
if [ $is_public -eq 0 ];
|
|
|
|
then
|
|
|
|
ynh_replace_string "__IS_PUBLIC__" "" "${final_path}/lstu.conf"
|
|
|
|
else
|
|
|
|
ynh_replace_string "__IS_PUBLIC__" "#" "${final_path}/lstu.conf"
|
|
|
|
fi
|
2019-02-03 00:20:19 +01:00
|
|
|
ynh_store_file_checksum "${final_path}/lstu.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SECURING FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-03 20:45:02 +01:00
|
|
|
chown -R $app:$app "$final_path"
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Upgrading systemd configuration..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
2019-02-03 00:20:19 +01:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
2019-02-03 00:20:19 +01:00
|
|
|
# Install lstu's dependencies via carton
|
2017-04-21 12:54:39 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-03 00:20:19 +01:00
|
|
|
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
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Upgrading logrotate configuration..."
|
2019-02-03 00:20:19 +01:00
|
|
|
|
2019-02-21 14:08:27 +01:00
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
2019-02-03 00:20:19 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
2017-04-21 12:54:39 +02:00
|
|
|
#=================================================
|
|
|
|
|
2019-02-03 00:20:19 +01:00
|
|
|
yunohost service add $app --log "/var/log/$app.log"
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTART LSTU
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-15 00:20:24 +01:00
|
|
|
ynh_systemd_action -n $app -a reload -l "Reloaded Shortened URLs service." -p "systemd"
|
2017-04-21 12:54:39 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Upgrading SSOwat configuration..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
2019-02-16 00:11:00 +01:00
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
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')
|
|
|
|
ynh_app_setting_set $app protected_regex "$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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2019-02-21 14:08:27 +01:00
|
|
|
ynh_print_info "Reloading nginx web server..."
|
2017-04-21 12:54:39 +02:00
|
|
|
|
2019-02-03 00:20:19 +01:00
|
|
|
systemctl reload nginx
|
|
|
|
yunohost app ssowatconf
|
2019-02-21 14:08:27 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_print_info "Upgrade of $app completed"
|