From a78a92b8d636faf781670d9205355329fd78a91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Thu, 19 Jan 2023 20:29:54 +0100 Subject: [PATCH] Write helpers to move code to _common.sh --- scripts/_common.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 45 ++++--------------------------------- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index cc5a186..3001199 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -30,6 +30,62 @@ pkg_dependencies=( # PERSONAL HELPERS #================================================= +__ynh_endi_patch_src() { + # Patching requirements.txt to use system provided Cython + cython_version=$(cython3 --version 2>&1 | sed 's|Cython version ||') + sed -i "s|Cython=.*|Cython==$cython_version|" "$final_path/endi/requirements.txt" +} + +__ynh_endi_build() { + #================================================= + # NPM setup + #================================================= + ynh_use_nodejs + ynh_install_nodejs --nodejs_version=16 + + pushd "$final_path/endi" 2>&1 + ynh_script_progression --message="Downloading NPM dependencies..." --weight=1 + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --prefix js_sources install 2>&1 + ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --prefix vue_sources install 2>&1 + + ynh_script_progression --message="Building Web interface code..." --weight=1 + ynh_exec_as $app make prodjs devjs prodjs2 devjs2 2>&1 \ + || ynh_die --message="Build of javascript code failed, maybe because of high RAM usage!" + popd 2>&1 + + #================================================= + # Python + Virtualenv setup + #================================================= + ynh_script_progression --message="Installing Python dependencies and Endi..." --weight=1 + + __ynh_python_venv_setup --venv_dir="$final_path/venv" + python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$final_path/venv") + chown -R $app:www-data "$final_path/venv" + + pushd "$final_path/endi" 2>&1 + ynh_exec_as $app "$final_path/venv/bin/python3" ./setup.py install 2>&1 + popd + + chmod 750 "$final_path" + chmod -R o-rwx "$final_path" + chown -R $app:www-data "$final_path" +} + +__ynh_endi_migratedb() { + ynh_exec_as $app "$final_path/venv/bin/endi-admin" "$final_path/endi.ini" \ + syncdb +} + +__ynh_endi_add_admin() { + ynh_exec_as $app "$final_path/venv/bin/endi-admin" "$final_path/endi.ini" \ + useradd --group=admin --user="admin" --pwd="$password" --email="admin@$domain" +} + + +#================================================= +# Python Venv HELPERS +#================================================= + __ynh_python_venv_setup() { local -A args_array=( [d]=venv_dir= [p]=packages= ) local venv_dir diff --git a/scripts/install b/scripts/install index cf6b644..b4230f8 100755 --- a/scripts/install +++ b/scripts/install @@ -111,9 +111,7 @@ ynh_script_progression --message="Setting up source files..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path ynh_setup_source --dest_dir="$final_path/endi" -# Patching requirements.txt to use system provided Cython -cython_version=$(cython3 --version 2>&1 | sed 's|Cython version ||') -sed -i "s|Cython=.*|Cython==$cython_version|" "$final_path/endi/requirements.txt" +__ynh_endi_patch_src chmod 750 "$final_path" chmod -R o-rwx "$final_path" @@ -128,37 +126,8 @@ ynh_add_nginx_config #================================================= # SPECIFIC SETUP #================================================= -# NPM setup -#================================================= -ynh_use_nodejs -ynh_install_nodejs --nodejs_version=16 -pushd "$final_path/endi" 2>&1 - ynh_script_progression --message="Downloading NPM dependencies..." --weight=1 - ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --prefix js_sources install 2>&1 - ynh_exec_as $app $ynh_node_load_PATH $ynh_npm --prefix vue_sources install 2>&1 - - ynh_script_progression --message="Building Web interface code..." --weight=1 - ynh_exec_as $app make prodjs devjs prodjs2 devjs2 2>&1 \ - || ynh_die --message="Build of javascript code failed, maybe because of high RAM usage!" -popd 2>&1 - -#================================================= -# Python + Virtualenv setup -#================================================= -ynh_script_progression --message="Installing Python dependencies and Endi..." --weight=1 - -__ynh_python_venv_setup --venv_dir="$final_path/venv" -python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$final_path/venv") -chown -R $app:www-data "$final_path/venv" - -pushd "$final_path/endi" 2>&1 - ynh_exec_as $app "$final_path/venv/bin/python3" ./setup.py install 2>&1 -popd - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:www-data "$final_path" +__ynh_endi_build #================================================= # ADD A CONFIGURATION @@ -183,14 +152,8 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Configuring enDI..." --weight=1 -pushd "$final_path" 2>&1 - ynh_exec_as $app "$final_path/venv/bin/endi-admin" endi.ini syncdb - - # ynh_exec_as $app "$final_path/venv/bin/endi-migrate" app.ini syncdb --pkg=endi_payment - - ynh_exec_as $app "$final_path/venv/bin/endi-admin" endi.ini useradd --group=admin --user="admin" --pwd="$password" \ - --email="admin@$domain" -popd 2>&1 +__ynh_endi_migratedb +__ynh_endi_add_admin #================================================= # GENERIC FINALIZATION