mirror of
https://github.com/YunoHost-Apps/simplytranslate_ynh.git
synced 2024-09-03 20:16:26 +02:00
118 lines
4.7 KiB
Bash
Executable file
118 lines
4.7 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# IMPORT SOME CONFIG
|
|
#=================================================
|
|
|
|
libretranslate_enable=$(ynh_app_setting_get -a $app -k libretranslate_enable)
|
|
libretranslate_instance=$(ynh_app_setting_get -a $app -k libretranslate_instance)
|
|
libretranslate_api=$(ynh_app_setting_get -a $app -k libretranslate_api)
|
|
google_enable=$(ynh_app_setting_get -a $app -k google_enable)
|
|
deepl_enable=$(ynh_app_setting_get -a $app -k deepl_enable)
|
|
iciba_enable=$(ynh_app_setting_get -a $app -k iciba_enable)
|
|
reverso_enable=$(ynh_app_setting_get -a $app -k reverso_enable)
|
|
port=$(ynh_app_setting_get -a $app -k port)
|
|
|
|
#=================================================
|
|
# 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="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD...)
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --weight=1
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/simplytranslate"
|
|
fi
|
|
|
|
chown -R $app:www-data "$install_dir"
|
|
|
|
#=================================================
|
|
# CONFIGURATION FOR SUBPATH
|
|
#=================================================
|
|
|
|
if [ "$path" = "/" ]; then
|
|
st_path=""
|
|
else
|
|
st_path=$path
|
|
fi
|
|
|
|
ynh_replace_string -m "\"/?engine" -r "\"$st_path/?engine" -f "$install_dir/simplytranslate/templates/index.html"
|
|
ynh_replace_string -m "/prefs" -r "$st_path/prefs" -f "$install_dir/simplytranslate/templates/index.html"
|
|
ynh_replace_string -m "/switchlanguages" -r "$st_path/switchlanguages" -f "$install_dir/simplytranslate/templates/index.html"
|
|
ynh_replace_string -m "\"/\"" -r "\"$st_path/\"" -f "$install_dir/simplytranslate/templates/prefs.html"
|
|
ynh_replace_string -m "/prefs" -r "$st_path/prefs" -f "$install_dir/simplytranslate/templates/prefs.html"
|
|
ynh_replace_string -m "/api" -r "$st_path/api" -f "$install_dir/simplytranslate/main.py"
|
|
ynh_replace_string -m "/prefs" -r "$st_path/prefs" -f "$install_dir/simplytranslate/main.py"
|
|
ynh_replace_string -m "/switchlanguages" -r "$st_path/switchlanguages" -f "$install_dir/simplytranslate/main.py"
|
|
ynh_replace_string -m "f\"/?" -r "f\"$st_path/?" -f "$install_dir/simplytranslate/main.py"
|
|
ynh_replace_string -m "\"/\"" -r "\"$st_path/\"" -f "$install_dir/simplytranslate/main.py"
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
ynh_add_nginx_config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
yunohost service add $app --description="Web interface for SimplyTranslate" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
ynh_add_config --template="config.conf.template" --destination="$install_dir/simplytranslate/config.conf"
|
|
|
|
chmod 400 "$install_dir/simplytranslate/config.conf"
|
|
chown $app:$app "$install_dir/simplytranslate/config.conf"
|
|
|
|
#=================================================
|
|
# REBUILDING THE APP
|
|
#=================================================
|
|
ynh_script_progression --message="Rebuilding the app..." --weight=1
|
|
|
|
ynh_secure_remove "$install_dir/venv"
|
|
mkdir "$install_dir/venv"
|
|
python3 -m venv "$install_dir/venv"
|
|
"$install_dir/venv/bin/python3" -m pip install -r "$install_dir/simplytranslate/requirements.txt"
|
|
|
|
chown -R $app:$app "$install_dir/venv"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|