1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/simplytranslate_ynh.git synced 2024-09-03 20:16:26 +02:00

penambahan skrip pengelolaan

This commit is contained in:
Neko Nekowazarashi 2023-06-04 14:41:03 +07:00
parent b53095cab5
commit 9df1697dea
7 changed files with 436 additions and 0 deletions

17
scripts/_common.sh Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

41
scripts/backup Executable file
View file

@ -0,0 +1,41 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#=================================================
# BACKUP THE APP MAIN DIR
#=================================================
ynh_backup --src_path="$install_dir"
#=================================================
# BACKUP THE NGINX CONFIGURATION
#=================================================
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================
ynh_backup --src_path="/etc/systemd/system/$app.service"
#=================================================
# END OF SCRIPT
#=================================================
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

71
scripts/change_url Normal file
View file

@ -0,0 +1,71 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# 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"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_change_url_nginx_config
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
# CONFIGURATION FOR SUBPATH
#=================================================
if [ $change_path -eq 1 ]
then
if [ "$old_path" = "/" ]; then
old_st_path=""
else
old_st_path=$old_path
fi
if [ "$new_path" = "/" ]; then
new_st_path=""
else
new_st_path=$new_path
fi
ynh_replace_string -m "\"$old_st_path/?engine" -r "\"$new_st_path/?engine" -f "$install_dir/simplytranslate/templates/index.html"
ynh_replace_string -m "$old_st_path/prefs" -r "$new_st_path/prefs" -f "$install_dir/simplytranslate/templates/index.html"
ynh_replace_string -m "\"$old_st_path/\"" -r "\"$new_st_path/\"" -f "$install_dir/simplytranslate/templates/prefs.html"
ynh_replace_string -m "$old_st_path/prefs" -r "$new_st_path/prefs" -f "$install_dir/simplytranslate/templates/prefs.html"
ynh_replace_string -m "$old_st_path/api" -r "$new_st_path/api" -f "$install_dir/simplytranslate/main.py"
ynh_replace_string -m "$old_st_path/prefs" -r "$new_st_path/prefs" -f "$install_dir/simplytranslate/main.py"
ynh_replace_string -m "$old_st_path/switchlanguages" -r "$new_st_path/switchlanguages" -f "$install_dir/simplytranslate/main.py"
ynh_replace_string -m "f\"$old_st_path/?" -r "f\"$new_st_path/?" -f "$install_dir/simplytranslate/main.py"
ynh_replace_string -m "\"$old_st_path/\"" -r "\"$new_st_path/\"" -f "$install_dir/simplytranslate/main.py"
fi
#=================================================
# GENERIC FINALISATION
#=================================================
# 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="Change of URL completed for $app" --last

107
scripts/install Executable file
View file

@ -0,0 +1,107 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC)
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_setup_source --dest_dir="$install_dir/simplytranslate"
chown -R $app:www-data "$install_dir"
#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding 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"
#=================================================
# APP INITIAL CONFIGURATION
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1
# some default config
ynh_app_setting_set -a $app -k libretranslate_enable -v false
ynh_app_setting_set -a $app -k libretranslate_instance -v ""
ynh_app_setting_set -a $app -k libretranslate_api -v ""
ynh_app_setting_set -a $app -k google_enable -v true
ynh_app_setting_set -a $app -k deepl_enable -v false
ynh_app_setting_set -a $app -k reverso_enable -v false
ynh_app_setting_set -a $app -k iciba_enable -v false
# load the above 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)
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"
#=================================================
# 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 "\"/\"" -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"
#=================================================
# BUILD THE APP
#=================================================
ynh_script_progression --message="Building the app..." --weight=1
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"
#=================================================
# GENERIC FINALIZATION
#=================================================
# 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="Installation of $app completed" --last

33
scripts/remove Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
# REMOVE SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
if ynh_exec_warn_less yunohost service status $app >/dev/null
then
ynh_script_progression --message="Removing $app service integration..." --weight=1
yunohost service remove $app
fi
ynh_remove_systemd_config
ynh_remove_nginx_config
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Removal of $app completed" --last

50
scripts/restore Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1
ynh_restore_file --origin_path="$install_dir"
chown -R $app:www-data "$install_dir"
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet
yunohost service add $app --description="Web interface for SimplyTranslate" --log="/var/log/$app/$app.log"
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last

117
scripts/upgrade Executable file
View file

@ -0,0 +1,117 @@
#!/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 "\"/\"" -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