From 184a3766031a773730fdadbdfb1d8dcc840a5092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Mon, 11 Mar 2024 22:49:59 +0100 Subject: [PATCH] Move sources to sources/ --- conf/systemd.service | 4 ++-- scripts/_common.sh | 3 +-- scripts/install | 14 +++++++------- scripts/restore | 4 ++-- scripts/upgrade | 20 ++++++++++++++++---- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/conf/systemd.service b/conf/systemd.service index 4891f80..9ba2ce4 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -6,9 +6,9 @@ After=network.target Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__INSTALL_DIR__/ +WorkingDirectory=__INSTALL_DIR__/sources/ Environment=NODE_ENV=production -Environment=NODE_CONFIG_DIR=__INSTALL_DIR__/config +Environment=NODE_CONFIG_DIR=__INSTALL_DIR__/config/ Environment="__YNH_NODE_LOAD_PATH__" ExecStart=__YNH_NPM__ start StandardOutput=syslog diff --git a/scripts/_common.sh b/scripts/_common.sh index 8b0530d..88d2211 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -17,8 +17,7 @@ bool_to_str() { } dato_setup_config_files() { - # create config directory (if it doesn't exist yet) - [ -d "$install_dir/config/" ] || mkdir "$install_dir/config/" + mkdir -p "$install_dir/config/" # setup public dato config ynh_add_config --template="public.js" --destination="$install_dir/config/public.js" diff --git a/scripts/install b/scripts/install index e46a9aa..00c8141 100755 --- a/scripts/install +++ b/scripts/install @@ -28,17 +28,17 @@ ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_script_progression --message="Setting up source files..." --weight=2 # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" +ynh_setup_source --dest_dir="$install_dir/sources" -chmod -R o-rwx "$install_dir" -chown -R "$app:www-data" "$install_dir" +chmod -R o-rwx "$install_dir/sources" +chown -R "$app:www-data" "$install_dir/sources" #================================================= # BUILD NODE DEPENDENCIES #================================================= ynh_script_progression --message="Building node dependencies..." --weight=90 -pushd "$install_dir" +pushd "$install_dir/sources" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install --loglevel warn popd @@ -62,7 +62,7 @@ if [[ $autosynchronize == true ]]; then ynh_script_progression --message="Customizing couch config..." --weight=2 # make sure that couchdb has CORS enabled and that it accepts requests from dato domain - ynh_add_config --template="../conf/couch.ini" --destination="/opt/couchdb/etc/local.d/$app.ini" + ynh_add_config --template="couch.ini" --destination="/opt/couchdb/etc/local.d/$app.ini" # restart couchdb service so that it takes into consideration the changes yunohost service restart couchdb @@ -110,8 +110,8 @@ fi # SECURE FILES AND DIRECTORIES #================================================= -[ -d "$install_dir/dist" ] || mkdir "$install_dir/dist" -chown -R $app:$app $install_dir/dist $install_dir/global $install_dir/config +mkdir -p "$install_dir/sources/dist" +chown -R "$app:$app" "$install_dir/sources/dist" "$install_dir/config" #================================================= # SYSTEM CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 0c4dd90..fc62449 100755 --- a/scripts/restore +++ b/scripts/restore @@ -26,8 +26,8 @@ ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" -mkdir -p "$install_dir/dist" -chown -R "$app:$app" "$install_dir/dist" "$install_dir/global" "$install_dir/config" +mkdir -p "$install_dir/sources/dist" +chown -R "$app:$app" "$install_dir/sources/dist" "$install_dir/sources/global" "$install_dir/config" #================================================= # RESTORE VARIOUS FILES diff --git a/scripts/upgrade b/scripts/upgrade index 6e49387..4a34a6f 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -14,6 +14,18 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 + +# Cleanup legacy install dir +if [ ! -d "$install_dir/sources" ]; then + mkdir "$install_dir/sources" + find . -mindepth 1 -maxdepth 1 ! -name "sources" -exec mv -t "$install_dir/sources" "{}" + + mv "$install_dir/sources/config" "$install_dir" +fi + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -27,13 +39,13 @@ ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_script_progression --message="Upgrading source files..." --weight=3 # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="config/public.js config/private.js" +ynh_setup_source --dest_dir="$install_dir/sources" --full_replace=1 chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" -mkdir "$install_dir/dist" -chown -R "$app:$app" "$install_dir/dist" "$install_dir/global" "$install_dir/config" +mkdir -p "$install_dir/sources/dist" +chown -R "$app:$app" "$install_dir/sources/dist" "$install_dir/sources/global" "$install_dir/config" #================================================= # SPECIFIC UPGRADE @@ -42,7 +54,7 @@ chown -R "$app:$app" "$install_dir/dist" "$install_dir/global" "$install_dir/con #================================================= ynh_script_progression --message="Building node dependencies..." --weight=20 -pushd "$install_dir" +pushd "$install_dir/sources" ynh_use_nodejs ynh_exec_warn_less ynh_exec_as "$app" "$ynh_node_load_PATH" "$ynh_npm" install --loglevel warn popd