From 5d4ff496f1f9070a87d535c647a8a3ec86ca7dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?E=CC=81ric=20Gaspar?= <46165813+ericgaspar@users.noreply.github.com> Date: Thu, 19 Oct 2023 19:16:11 +0200 Subject: [PATCH] cleaning --- scripts/backup | 2 -- scripts/change_url | 1 - scripts/install | 25 +++++---------- scripts/remove | 5 +-- scripts/restore | 8 ++--- scripts/upgrade | 78 ++++++++++++++++------------------------------ 6 files changed, 40 insertions(+), 79 deletions(-) diff --git a/scripts/backup b/scripts/backup index 54e1793..9083697 100755 --- a/scripts/backup +++ b/scripts/backup @@ -40,8 +40,6 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" -#================================================= -# SPECIFIC BACKUP #================================================= # BACKUP LOGROTATE #================================================= diff --git a/scripts/change_url b/scripts/change_url index 41f7d60..3e26186 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -59,7 +59,6 @@ ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" #================================================= ynh_print_info --message="Don't forget to add a new redirction url in your Slack app settings !" - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/install b/scripts/install index 1952589..4b1f86b 100755 --- a/scripts/install +++ b/scripts/install @@ -63,10 +63,10 @@ ynh_app_setting_set --app=$app --key=dex_user_uri --value=$dex_user_uri #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=1 +ynh_script_progression --message="Installing dependencies..." --weight=7 # Install nodejs -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION 2>&1 +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION #================================================= # CREATE A POSTGRESQL DATABASE @@ -115,20 +115,6 @@ chmod 644 "$cron_path" yunohost service add $app --description="Outline server" --log="/var/log/$app/$app.log" -#================================================= -# BUILD YARN DEPENDENCIES -#================================================= - -pushd "$install_dir" - ynh_use_nodejs -#REMOVEME? ynh_script_progression --message="Fetching Yarn production dependencies... This can be very long, be patient !" --weight=18 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 2>&1 - ynh_script_progression --message="Building... This can be very long, be patient !" --weight=18 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_OPTIONS="--max-old-space-size=3200" yarn build 2>&1 - ynh_script_progression --message="Cleaning cache... " --weight=3 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean 2>&1 -popd - #================================================= # ADD A CONFIGURATION #================================================= @@ -140,12 +126,15 @@ chmod 400 "$install_dir/.env" chown $app:$app "$install_dir/.env" #================================================= -# RUN DB MIGRATION +# BUILD YARN DEPENDENCIES #================================================= -ynh_script_progression --message="Running DB initial migration..." --weight=3 +ynh_script_progression --message="Building $app..." --weight=10 pushd "$install_dir" ynh_use_nodejs + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_OPTIONS="--max-old-space-size=3200" yarn build + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn db:migrate popd diff --git a/scripts/remove b/scripts/remove index 67b02f6..dc1bf63 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,10 +10,11 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# STANDARD REMOVE +# REMOVE SYSTEM CONFIGURATIONS #================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # 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 diff --git a/scripts/restore b/scripts/restore index 7363cd6..18891f7 100755 --- a/scripts/restore +++ b/scripts/restore @@ -19,7 +19,7 @@ if ! yunohost app list | grep -q "id: $dex_app"; then echo "Dex is not installed. Installing... " yunohost tools update if yunohost app list | grep -q "$dex_domain$dex_path"; then - ynh_die "The domain provided for Dex is already used by another app. Please chose another one !" + ynh_die "The domain provided for Dex is already used by another app. Please chose another one!" fi yunohost app install https://github.com/YunoHost-Apps/dex_ynh --force --args "domain=$dex_domain&path=$dex_path&OIDC_name=$oidc_name&OIDC_secret=$oidc_secret&OIDC_callback=$oidc_callback" fi @@ -49,7 +49,7 @@ chown -R $app:www-data "/var/lib/outline" #================================================= ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=6 -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql #================================================= # SPECIFIC RESTORATION @@ -59,7 +59,7 @@ ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name ynh_script_progression --message="Reinstalling dependencies..." --weight=1 # Install nodejs -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION 2>&1 +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" @@ -77,8 +77,6 @@ yunohost service add $app --description="Outline server" --log="/var/log/$app/$a #================================================= # UPDATING A CONFIGURATION #================================================= - -#REMOVEME? ynh_secure_remove --file="$install_dir/.env" ynh_script_progression --message="Updating the configuration file..." --weight=1 ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" diff --git a/scripts/upgrade b/scripts/upgrade index 12cd69a..5cacd4c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -42,16 +42,11 @@ chown -R $app:www-data "$install_dir" #======================================================= # MIGRATE MINIO BUCKET IF UPGRADING FROM AN OLD VERSION #======================================================= - ynh_script_progression --message="Checking if a migration is needed" + if ynh_compare_current_package_version --comparison le --version 0.69.2.2~ynh1 then ynh_script_progression --message="Migrating MinIO data to local directory" - -#REMOVEME? minio_domain=$(ynh_app_setting_get --app=$app --key=minio_domain) -#REMOVEME? minio_admin=$(ynh_app_setting_get --app=$app --key=minio_admin) -#REMOVEME? minio_password=$(ynh_app_setting_get --app=$app --key=minio_password) -#REMOVEME? mc_path=$(ynh_app_setting_get --app=$app --key=mc_path) mkdir -p "/var/lib/$app/data" chown -R minio:www-data "/var/lib/$app" @@ -59,8 +54,6 @@ then chown -R $app:www-data "/var/lib/$app" ynh_script_progression --message="Data migration finished" - ynh_script_progression --message="Data bucket was kept for safety, just in case !" - ynh_script_progression --message="Don't forget to remove MinIO app if you don't use it !" else ynh_script_progression --message="No migration to be done" fi @@ -73,49 +66,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config -# Install Nodejs -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION - -#================================================= -# UPGRADE YARN DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Building Yarn dependencies... This can be very long, be patient !" --weight=10 - -pushd "$install_dir" - ynh_use_nodejs -#REMOVEME? ynh_script_progression --message="Fetching Yarn production dependencies... This can be very long, be patient !" --weight=18 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 2>&1 - ynh_script_progression --message="Building... This can be very long, be patient !" --weight=18 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_OPTIONS="--max-old-space-size=3900" yarn build 2>&1 - ynh_script_progression --message="Cleaning cache... " --weight=3 - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean 2>&1 -popd - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 - -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" - -chmod 400 "$install_dir/.env" -chown $app:$app "$install_dir/.env" - -#================================================= -# RUN DB MIGRATION -#================================================= -ynh_script_progression --message="Running DB initial migration..." - -pushd "$install_dir" - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn db:migrate -popd - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 - # Create a dedicated systemd config ynh_add_systemd_config @@ -129,6 +79,32 @@ chmod 644 "$cron_path" yunohost service add $app --description="Outline server" --log="/var/log/$app/$app.log" +# Install Nodejs +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$NODEJS_VERSION + +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + +ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" + +chmod 400 "$install_dir/.env" +chown $app:$app "$install_dir/.env" + +#================================================= +# UPGRADE YARN DEPENDENCIES +#================================================= +ynh_script_progression --message="Building $app" --weight=10 + +pushd "$install_dir" + ynh_use_nodejs + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn install --frozen-lockfile --network-timeout 1000000000 + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_OPTIONS="--max-old-space-size=3900" yarn build + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn cache clean + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH yarn db:migrate +popd + #================================================= # START SYSTEMD SERVICE #=================================================