1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/languagetool_ynh.git synced 2024-09-03 19:35:58 +02:00
languagetool_ynh/scripts/_common.sh
2021-10-24 16:05:00 -04:00

132 lines
4.5 KiB
Bash

#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
# dependencies used by the app
pkg_dependencies="default-jre build-essential"
#=================================================
# PERSONAL HELPERS
#=================================================
function download_data {
if [ $use_ngram -eq 1 ]; then
ynh_setup_source --dest_dir="$data_path/ngrams/de" --source_id="ngrams-de"
ynh_setup_source --dest_dir="$data_path/ngrams/en" --source_id="ngrams-en"
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"
ynh_setup_source --dest_dir="$data_path/ngrams/ru" --source_id="ngram-ru"
ynh_setup_source --dest_dir="$data_path/ngrams/zh" --source_id="ngram-zh"
fi
fi
if [ $use_word2vec -eq 1 ]; then
ynh_setup_source --dest_dir="$data_path/word2vec/de" --source_id="word2vec-de"
ynh_setup_source --dest_dir="$data_path/word2vec/en" --source_id="word2vec-en"
ynh_setup_source --dest_dir="$data_path/word2vec/pt" --source_id="word2vec-pt"
fi
if [ $use_fasttext -eq 1 ]; then
if [ $use_compressed_fasttext -eq 1 ]; then
ynh_setup_source --dest_dir="$data_path/fasttext" --source_id="fasttext-model-compressed"
else
ynh_setup_source --dest_dir="$data_path/fasttext" --source_id="fasttext-model"
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 {
if [ $use_ngram -eq 1 ]; then
language_model_config_line="languageModel=$data_path/ngrams"
else
language_model_config_line=""
fi
if [ $use_word2vec -eq 1 ]; then
word2vec_model_config_line="word2vecModel=$data_path/word2vec"
else
word2vec_model_config_line=""
fi
if [ $use_fasttext -eq 1 ]; then
if [ $use_compressed_fasttext -eq 1 ]; then
fasttext_model_config_line="fasttextModel=$data_path/fasttext/lid.176.ftz"
else
fasttext_model_config_line="fasttextModel=$data_path/fasttext/lid.176.bin"
fi
fasttext_binary_config_line="fasttextBinary=$final_path/fasttext/fasttext"
else
fasttext_model_config_line=""
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
grammalecte_server_config_line=""
fi
ynh_add_config --template="languagetool.conf" --destination="$final_path/languagetool.conf"
}
function compile_fasttext {
if [ $use_fasttext -eq 1 ]; then
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
popd || ynh_die
fi
}
function set_permissions {
chown -R root:$app $final_path
chmod -R g=u,g-w,o-rwx $final_path
chown -R root:$app $data_path
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
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================