diff --git a/manifest.toml b/manifest.toml index 7b5d699..6aaceb2 100644 --- a/manifest.toml +++ b/manifest.toml @@ -38,10 +38,10 @@ ram.runtime = "50M" default = "visitors" [resources] - [resources.sources.main] - url = "https://github.com/Requarks/wiki/releases/download/v2.5.298/wiki-js.tar.gz" - sha256 = "3bb290d77e3387dba5958c906629a6c5f751c17787903f1a021cbfa51cc88f1a" - in_subdir = false + [resources.sources.main] + url = "https://github.com/Requarks/wiki/releases/download/v2.5.298/wiki-js.tar.gz" + sha256 = "3bb290d77e3387dba5958c906629a6c5f751c17787903f1a021cbfa51cc88f1a" + in_subdir = false [resources.ports] diff --git a/scripts/change_url b/scripts/change_url index 40bd355..8123f1e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -33,7 +33,7 @@ ynh_change_url_nginx_config ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:" +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="HTTP Server:" #================================================= # END OF SCRIPT diff --git a/scripts/install b/scripts/install index 341a064..cf1fa10 100644 --- a/scripts/install +++ b/scripts/install @@ -10,25 +10,21 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST +# INITIALIZE AND STORE SETTINGS #================================================= ldap_user="svc_${app}_ldap" ldap_password=$(ynh_string_random --length=8) -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= - -ynh_app_setting_set --app=$app --key=ldap_user --value=$ldap_user -ynh_app_setting_set --app=$app --key=ldap_password --value=$ldap_password +ynh_app_setting_set --app="$app" --key=ldap_user --value="$ldap_user" +ynh_app_setting_set --app="$app" --key=ldap_password --value="$ldap_password" #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." +ynh_script_progression --message="Installing NodeJS..." -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_exec_warn_less ynh_install_nodejs --nodejs_version="$nodejs_version" ynh_use_nodejs #================================================= @@ -47,29 +43,7 @@ ynh_script_progression --message="Setting up source files..." ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# Create a dedicated NGINX config -ynh_add_nginx_config - -# Create a dedicated systemd config -ynh_add_systemd_config - -yunohost service add $app --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" - -#================================================= -# SPECIFIC SETUP -#================================================= -# CREATE LDAP USER -#================================================= -ynh_script_progression --message="Creating LDAP user..." - -yunohost user create $ldap_user --fullname "SvcWikijsLdap" --domain $domain --password $ldap_password -q 0 +chown -R "$app:$app" "$install_dir" #================================================= # ADD A CONFIGURATION @@ -79,7 +53,26 @@ ynh_script_progression --message="Adding a configuration file..." ynh_add_config --template="config.sample.yml" --destination="$install_dir/config.yml" chmod 400 "$install_dir/config.yml" -chown $app:$app "$install_dir/config.yml" +chown "$app:$app" "$install_dir/config.yml" + +#================================================= +# SYSTEM CONFIGURATION +#================================================= +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" + +#================================================= +# CREATE LDAP USER +#================================================= +ynh_script_progression --message="Creating LDAP user..." + +yunohost user create "$ldap_user" --fullname "SvcWikijsLdap" --domain "$domain" --password "$ldap_password" -q 0 #================================================= # START SYSTEMD SERVICE @@ -87,7 +80,7 @@ chown $app:$app "$install_dir/config.yml" ynh_script_progression --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:" +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="HTTP Server:" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 91fc551..6d2a91b 100644 --- a/scripts/remove +++ b/scripts/remove @@ -16,10 +16,9 @@ source /usr/share/yunohost/helpers #================================================= # 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 - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app +if ynh_exec_warn_less yunohost service status $app >/dev/null; then + ynh_script_progression --message="Removing $app service integration..." + yunohost service remove "$app" fi # Remove the dedicated systemd config diff --git a/scripts/restore b/scripts/restore index fb636d3..2d6a1d9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,6 +10,15 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers +#================================================= +# REINSTALL DEPENDENCIES +#================================================= +ynh_script_progression --message="Reinstalling NodeJS..." + +# Define and install dependencies +ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version +ynh_use_nodejs + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -18,25 +27,7 @@ ynh_script_progression --message="Restoring the app main directory..." ynh_restore_file --origin_path="$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version -ynh_use_nodejs - -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +chown -R "$app:$app" "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE @@ -47,28 +38,24 @@ ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --datab ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= -# CREATE LDAP USER +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Creating LDAP user..." +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -yunohost user create $ldap_user --fullname "SvcWikijsLdap" --domain $domain --password $ldap_password -q 0 - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet +systemctl enable "$app.service" --quiet +yunohost service add "$app" --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" -yunohost service add $app --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" +yunohost user create "$ldap_user" --fullname "SvcWikijsLdap" --domain "$domain" --password "$ldap_password" -q 0 #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:" +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="HTTP Server:" ynh_systemd_action --service_name=nginx --action=reload diff --git a/scripts/upgrade b/scripts/upgrade index 5fdc6e9..6a8e0c3 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -30,49 +30,14 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd ynh_script_progression --message="Ensuring downward compatibility..." # If ldap_user doesn't exist, retrieve it or create it -if [[ -z "$ldap_user" ]]; then - ldap_user="svc_${app}_ldap" - ldap_password=$(ynh_string_random --length=8) - ynh_app_setting_set "$app" ldap_user "$ldap_user" - ynh_app_setting_set "$app" ldap_password "$ldap_password" - yunohost user create $ldap_user --fullname "SvcWikijsLdap" --domain $domain --password $ldap_password -q 0 +if [[ -z "${ldap_user:-}" ]]; then + ldap_user="svc_${app}_ldap" + ldap_password=$(ynh_string_random --length=8) + ynh_app_setting_set "$app" ldap_user "$ldap_user" + ynh_app_setting_set "$app" ldap_password "$ldap_password" + yunohost user create "$ldap_user" --fullname "SvcWikijsLdap" --domain $domain --password $ldap_password -q 0 fi -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." - - config_file="$install_dir/config.yml" - tmpdir="$(mktemp -d)" - - rsync -a "$config_file" "$tmpdir/." - if [ -d "$install_dir/.ssh" ]; then - rsync -a "$install_dir/.ssh" "$tmpdir/." - fi - if [ -d "$install_dir/data" ]; then - rsync -a "$install_dir/data" "$tmpdir/." - fi - ynh_secure_remove --file="$install_dir" - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" - - rsync -a "$tmpdir/config.yml" "$install_dir/." - if [ -d "$tmpdir/.ssh" ]; then - rsync -a "$tmpdir/.ssh" "$install_dir/." - fi - if [ -d "$tmpdir/data" ]; then - rsync -a "$tmpdir/data" "$install_dir/." - fi -fi - -chmod -R o-rwx "$install_dir" -chown -R $app:$app "$install_dir" - #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -82,20 +47,15 @@ ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_use_nodejs #================================================= -# NGINX CONFIGURATION +# DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." +ynh_script_progression --message="Upgrading source files..." -# Create a dedicated NGINX config -ynh_add_nginx_config +ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep="config.yml .ssh data" -# Create a dedicated systemd config -ynh_add_systemd_config +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" -yunohost service add $app --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" - -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE A CONFIG FILE #================================================= @@ -104,14 +64,26 @@ ynh_script_progression --message="Updating a configuration file..." ynh_add_config --template="config.sample.yml" --destination="$install_dir/config.yml" chmod 400 "$install_dir/config.yml" -chown $app:$app "$install_dir/config.yml" +chown "$app:$app" "$install_dir/config.yml" + +#================================================= +# REAPPLY SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 + +# Create a dedicated NGINX config +ynh_add_nginx_config + +# Create a dedicated systemd config +ynh_add_systemd_config +yunohost service add "$app" --description="$app daemon for Wiki.js" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="HTTP Server:" +ynh_systemd_action --service_name="$app" --action="start" --log_path=systemd --line_match="HTTP Server:" #================================================= # END OF SCRIPT