#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) salt=$(ynh_app_setting_get --app=$app --key=salt) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # CHECK VERSION #================================================= ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) #================================================= # 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 () { # 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 --action="stop" --log_path=systemd --line_match="Stopped" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # Previous versions did not set the DB name as a setting, so we need to set it now (will be used on # remove). if [ -z "$db_name" ] then db_name=$(ynh_sanitize_dbid --db_name=$app) ynh_app_setting_set --app=$app --key=db_name --value=$db_name db_user=$db_name fi # If final_path doesn't exist, create it if [ -z "$final_path" ] then final_path=/var/www/$app ynh_app_setting_set "$app" final_path "$final_path" fi if [ -d "/home/ynh$app" ] then mv "/home/ynh$app/data" "$final_path/data" ynh_secure_remove --file="/home/ynh$app" fi if [ -z "$salt" ] then salt=$(ynh_string_random 40) ynh_app_setting_set "$app" salt "$salt" fi usermod -d $final_path $app #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # 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 ynh_script_progression --message="Upgrading source files..." --weight=1 tmpdir="$(mktemp -d)" cp "$final_path/config.ini" "$tmpdir/config.ini" ynh_secure_remove --file="$final_path" # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" cp "$tmpdir/config.ini" "$final_path/config.ini" ynh_secure_remove --file="$tmpdir" mkdir -p "$final_path/data" fi chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:www-data "$final_path" #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=1 ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_exec_warn_less ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg" # Now that postgresql is installed, check the db exists and the user is set up if [ -z "$db_pwd" ] then ynh_script_progression --message="Setting up database" ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) fi #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 # Create a dedicated NGINX config ynh_add_nginx_config #================================================= # SPECIFIC UPGRADE #================================================= # INSTALL WOOB WITH PIP #================================================= ynh_script_progression --message="Installing woob..." --weight=1 locale-gen C.UTF-8 update-locale C.UTF-8 ynh_secure_remove --file="${final_path}/venv" ynh_exec_as $app virtualenv --python=python3 --system-site-packages "${final_path}/venv" ( set +o nounset source "${final_path}/venv/bin/activate" set -o nounset ynh_exec_warn_less ynh_exec_as $app RUSTUP_HOME="$final_path"/.rustup CARGO_HOME="$final_path"/.cargo bash -c 'curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -q -y' export PATH="$final_path/.cargo/bin:$PATH" ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade pip ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install --upgrade setuptools ynh_exec_warn_less ynh_exec_as $app env PATH=$PATH pip install woob simplejson BeautifulSoup4 PyExecJS typing-extensions pdfminer.six Pillow --ignore-installed ynh_secure_remove --file="$final_path/.cargo" ynh_secure_remove --file="$final_path/.rustup" ynh_secure_remove --file="$final_path/.cache" ynh_secure_remove --file="$final_path/.local" ) #================================================= # INSTALL KRESUS WITH NPM #================================================= ynh_script_progression --message="Installing app..." --weight=1 ynh_use_nodejs ( cd "$final_path" # In case of nodejs upgrade, remove the current node_modules to make sure there are no errors # linked to modules compiled for the previous version. ynh_secure_remove --file="$final_path/node_modules" ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn install ynh_exec_warn_less ynh_exec_as $app env $ynh_node_load_PATH yarn cache clean --all ynh_secure_remove --file="$final_path/.cache" ynh_secure_remove --file="$final_path/.yarn" ) #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_add_config --template="../conf/config.ini" --destination="$final_path/config.ini" chmod 400 "$final_path/config.ini" chown $app:$app "$final_path/config.ini" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config #================================================= # GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 mkdir -p "/var/log/$app/" touch "/var/log/$app/$app.log" chown -R $app:$app "/var/log/$app/" # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add $app --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Server is ready" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # SEND README TO ADMIN #================================================= ynh_script_progression --message="Sending ReadMe to admin..." --weight=1 message=" Kresus was successfully updated! Domain: $domain Path : $path_url Config: $final_path/config.ini Note about config.ini: this package will regenerate the config file on upgrade. If you changed it manually and upgrade Kresus, you'll find a backup in $final_path. Are you facing an issue, want to improve this app or say thank you? Please open a new issue in this project: https://github.com/YunoHost-Apps/kresus_ynh " ynh_send_readme_to_admin "$message" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed" --last