From a271f12f9d0038539a6c7054c11a008d93294ad5 Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sun, 24 Oct 2021 16:01:02 -0400 Subject: [PATCH] Add Beolingus support --- check_process | 2 ++ conf/beolingus.src | 7 +++++++ conf/languagetool.conf | 1 + manifest.json | 17 +++++++++++++++-- scripts/_common.sh | 35 +++++++++++++++++++++++++++++++---- scripts/backup | 2 +- scripts/change_url | 11 ++++------- scripts/install | 2 ++ scripts/remove | 9 ++------- scripts/restore | 27 ++++++++------------------- scripts/upgrade | 25 ++++++++++--------------- 11 files changed, 83 insertions(+), 55 deletions(-) create mode 100644 conf/beolingus.src diff --git a/check_process b/check_process index 0f76337..08dd561 100644 --- a/check_process +++ b/check_process @@ -7,6 +7,8 @@ ; Manifest domain="domain.tld" (DOMAIN) use_ngram=0 (USE_NGRAM) + use_word2vec=1 (USE_WORD2VEC) + use_beolingus=1 (USE_BEOLINGUS) ; Checks pkg_linter=1 setup_sub_dir=0 diff --git a/conf/beolingus.src b/conf/beolingus.src new file mode 100644 index 0000000..91be2f7 --- /dev/null +++ b/conf/beolingus.src @@ -0,0 +1,7 @@ +SOURCE_URL=https://ftp.tu-chemnitz.de/pub/Local/urz/ding/de-en/de-en.txt.zip +SOURCE_SUM=e6b98900d5a700fc94e31139898a0700596477201c78ee860b13dfe9a67638fa +SOURCE_SUM_PRG=sha256sum +SOURCE_FORMAT=zip +SOURCE_IN_SUBDIR=false +SOURCE_FILENAME=de-en.txt.zip +SOURCE_EXTRACT=true diff --git a/conf/languagetool.conf b/conf/languagetool.conf index 26f4180..380daf6 100644 --- a/conf/languagetool.conf +++ b/conf/languagetool.conf @@ -2,4 +2,5 @@ __LANGUAGE_MODEL_CONFIG_LINE__ __WORD2VEC_MODEL_CONFIG_LINE__ __FASTTEXT_MODEL_CONFIG_LINE__ __FASTTEXT_BINARY_CONFIG_LINE__ +__BEOLINGUS_FILE_CONFIG_LINE__ __GRAMMALECTE_SERVER_CONFIG_LINE__ diff --git a/manifest.json b/manifest.json index 5c3510d..a001530 100644 --- a/manifest.json +++ b/manifest.json @@ -21,7 +21,7 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain", @@ -92,6 +92,19 @@ }, "default": false }, + { + "name": "use_beolingus", + "type": "boolean", + "ask": { + "en": "Use Beolingus German-English word list?", + "fr": "Utilizer liste de mots allemand-anglais Beolingus?" + }, + "help": { + "en": "~8 MB, download", + "fr": "Téléchargement de ~8 MB" + }, + "default": false + }, { "name": "grammalecte_server", "type": "string", @@ -109,4 +122,4 @@ } ] } -} +} \ No newline at end of file diff --git a/scripts/_common.sh b/scripts/_common.sh index 81aface..4cd40b6 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -18,7 +18,7 @@ function download_data { ynh_setup_source --dest_dir="$data_path/ngrams/es" --source_id="ngrams-es" ynh_setup_source --dest_dir="$data_path/ngrams/fr" --source_id="ngrams-fr" ynh_setup_source --dest_dir="$data_path/ngrams/nl" --source_id="ngrams-nl" - + if [ $use_untested_ngram -eq 1 ]; then ynh_setup_source --dest_dir="$data_path/ngrams/he" --source_id="ngram-he" ynh_setup_source --dest_dir="$data_path/ngrams/it" --source_id="ngram-it" @@ -41,6 +41,10 @@ function download_data { fi ynh_setup_source --dest_dir="$final_path/fasttext" --source_id="fasttext" fi + + if [ $use_beolingus -eq 1 ]; then + ynh_setup_source --dest_dir="$data_path/beolingus" --source_id="beolingus" + fi } function add_languagetool_config { @@ -68,6 +72,12 @@ function add_languagetool_config { fasttext_binary_config_line="" fi + if [ $use_beolingus -eq 1 ]; then + beolingus_file_config_line="beolingusFile=$data_path/beolingus/de-en.txt" + else + beolingus_file_config_line="" + fi + if [ ! -z $grammalecte_server ]; then grammalecte_server_config_line="grammalecteServer=$grammalecte_server/gc_text/fr" else @@ -82,9 +92,9 @@ function compile_fasttext { ynh_script_progression --message="Compiling fasttext..." --weight=15 pushd "$final_path/fasttext" || ynh_die - chown -R $app:$app $final_path/fasttext - sudo -u $app make - chown -R root:root $final_path/fasttext + chown -R $app:$app $final_path/fasttext + sudo -u $app make + chown -R root:root $final_path/fasttext popd || ynh_die fi } @@ -96,6 +106,23 @@ function set_permissions { chmod -R g=u,g-w,o-rwx $data_path } +function load_installation_settings { + 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) + data_path=$(ynh_app_setting_get --app=$app --key=data_path) + use_ngram=$(ynh_app_setting_get --app=$app --key=use_ngram) + use_untested_ngram=$(ynh_app_setting_get --app=$app --key=use_untested_ngram) + use_word2vec=$(ynh_app_setting_get --app=$app --key=use_word2vec) + use_fasttext=$(ynh_app_setting_get --app=$app --key=use_fasttext) + use_compressed_fasttext=$(ynh_app_setting_get --app=$app --key=use_compressed_fasttext) + use_beolingus=$(ynh_app_setting_get --app=$app --key=use_beolingus) + grammalecte_server=$(ynh_app_setting_get --app=$app --key=grammalecte_server) + port=$(ynh_app_setting_get --app=$app --key=port) +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 7f4537b..579b668 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +ynh_clean_setup() { true } # Exit if an error occurs during the execution of the script diff --git a/scripts/change_url b/scripts/change_url index 2a9b852..1ca03be 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -26,8 +26,7 @@ app=$YNH_APP_INSTANCE_NAME #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 -# Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app=$app --key=final_path) +load_installation_settings #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -36,7 +35,7 @@ ynh_script_progression --message="Backing up the app before changing its URL (ma # Backup the current version of the app ynh_backup_before_upgrade -ynh_clean_setup () { +ynh_clean_setup() { # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" @@ -51,8 +50,7 @@ ynh_abort_if_errors #================================================= change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then +if [ "$old_domain" != "$new_domain" ]; then change_domain=1 fi change_path=0 @@ -74,8 +72,7 @@ ynh_script_progression --message="Updating NGINX web server configuration..." -- nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # Change the domain for NGINX -if [ $change_domain -eq 1 ] -then +if [ $change_domain -eq 1 ]; then # Delete file checksum for the old conf file location ynh_delete_file_checksum --file="$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf diff --git a/scripts/install b/scripts/install index 94e1ae7..2bb3d0b 100755 --- a/scripts/install +++ b/scripts/install @@ -31,6 +31,7 @@ use_untested_ngram=$YNH_APP_ARG_USE_UNTESTED_NGRAM use_word2vec=$YNH_APP_ARG_USE_WORD2VEC use_fasttext=$YNH_APP_ARG_USE_FASTTEXT use_compressed_fasttext=$YNH_APP_ARG_USE_COMPRESSED_FASTTEXT +use_beolingus=$YNH_APP_ARG_USE_BEOLINGUS grammalecte_server=$YNH_APP_ARG_GRAMMALECTE_SERVER app=$YNH_APP_INSTANCE_NAME @@ -59,6 +60,7 @@ ynh_app_setting_set --app=$app --key=use_untested_ngram --value=$use_untested_ng ynh_app_setting_set --app=$app --key=use_word2vec --value=$use_word2vec ynh_app_setting_set --app=$app --key=use_fasttext --value=$use_fasttext ynh_app_setting_set --app=$app --key=use_compressed_fasttext --value=$use_compressed_fasttext +ynh_app_setting_set --app=$app --key=use_beolingus --value=$use_beolingus ynh_app_setting_set --app=$app --key=grammalecte_server --value=$grammalecte_server #================================================= diff --git a/scripts/remove b/scripts/remove index 3e76c8d..5f15d06 100755 --- a/scripts/remove +++ b/scripts/remove @@ -14,11 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) +load_installation_settings #================================================= # STANDARD REMOVE @@ -27,8 +23,7 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then +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 diff --git a/scripts/restore b/scripts/restore index 20f9192..b0f44de 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= -ynh_clean_setup () { +ynh_clean_setup() { true } # Exit if an error occurs during the execution of the script @@ -25,30 +25,19 @@ ynh_abort_if_errors #================================================= 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) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -use_ngram=$(ynh_app_setting_get --app=$app --key=use_ngram) -use_untested_ngram=$(ynh_app_setting_get --app=$app --key=use_untested_ngram) -use_word2vec=$(ynh_app_setting_get --app=$app --key=use_word2vec) -use_fasttext=$(ynh_app_setting_get --app=$app --key=use_fasttext) -use_compressed_fasttext=$(ynh_app_setting_get --app=$app --key=use_compressed_fasttext) -grammalecte_server=$(ynh_app_setting_get --app=$app --key=grammalecte_server) +load_installation_settings #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " -test ! -d $data_path \ - || ynh_die --message="There is already a directory: $data_path " +ynh_webpath_available --domain=$domain --path_url=$path_url || + ynh_die --message="Path not available: ${domain}${path_url}" +test ! -d $final_path || + ynh_die --message="There is already a directory: $final_path " +test ! -d $data_path || + ynh_die --message="There is already a directory: $data_path " #================================================= # STANDARD RESTORATION STEPS diff --git a/scripts/upgrade b/scripts/upgrade index f7c3262..2caad71 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,19 +14,15 @@ source /usr/share/yunohost/helpers #================================================= ynh_script_progression --message="Loading installation settings..." --weight=1 -app=$YNH_APP_INSTANCE_NAME +load_installation_settings -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) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -use_ngram=$(ynh_app_setting_get --app=$app --key=use_ngram) -use_untested_ngram=$(ynh_app_setting_get --app=$app --key=use_untested_ngram) -use_word2vec=$(ynh_app_setting_get --app=$app --key=use_word2vec) -use_fasttext=$(ynh_app_setting_get --app=$app --key=use_fasttext) -use_compressed_fasttext=$(ynh_app_setting_get --app=$app --key=use_compressed_fasttext) -grammalecte_server=$(ynh_app_setting_get --app=$app --key=grammalecte_server) -port=$(ynh_app_setting_get --app=$app --key=port) +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +if [ -z "$use_beolingus" ]; then + use_beolingus=0 + ynh_app_setting_set --app=$app --key=use_beolingus --value=$use_beolingus +fi #================================================= # CHECK VERSION @@ -41,7 +37,7 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade -ynh_clean_setup () { +ynh_clean_setup() { # Restore it if the upgrade fails ynh_restore_upgradebackup } @@ -61,8 +57,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then +if [ "$upgrade_type" == "UPGRADE_APP" ]; then ynh_script_progression --message="Upgrading source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src