diff --git a/check_process b/check_process index 7b095d0..6095ca9 100644 --- a/check_process +++ b/check_process @@ -2,7 +2,6 @@ ; Manifest domain="domain.tld" path="/path" - admin="john" is_public=1 ; Checks pkg_linter=1 @@ -13,8 +12,11 @@ setup_public=1 upgrade=1 #upgrade=1 from_commit=cf621e81a3df37b77cdc97a305e10dfb27631c6a + # 12.2.0~ynh10 + upgrade=1 from_commit=88e894a01858a723ea62b154103867cafb49dfa8 backup_restore=1 multi_instance=0 + port_already_use=0 change_url=1 ;;; Options Email= diff --git a/conf/systemd.service b/conf/systemd.service index 4d70a71..8932b81 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -3,11 +3,12 @@ Description=Droppy: self-hosted file storage server After=network.target [Service] +Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__ +WorkingDirectory=__FINALPATH__/ Environment="NODE_ENV=production" -Environment="PATH=__ENV_PATH__" +Environment="__YNH_NODE_LOAD_PATH__" ExecStart= __FINALPATH__/droppy.js start -c __FINALPATH__/config -f /home/yunohost.app/__APP__/files AmbientCapabilities=CAP_NET_BIND_SERVICE Restart=always @@ -16,4 +17,4 @@ StandardOutput=journal StandardError=journal [Install] -WantedBy=multi-user.target \ No newline at end of file +WantedBy=multi-user.target diff --git a/manifest.json b/manifest.json index e96fb1f..8a977f5 100644 --- a/manifest.json +++ b/manifest.json @@ -24,7 +24,7 @@ "nginx" ], "arguments": { - "install" : [ + "install": [ { "name": "domain", "type": "domain" diff --git a/scripts/backup b/scripts/backup index 1724afa..2a41ab0 100644 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -14,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -41,18 +42,18 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$final_path" -#================================================= -# BACKUP THE NGINX CONFIGURATION -#================================================= - -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" - #================================================= # BACKUP THE DATA DIR #================================================= ynh_backup --src_path="$data_path" --is_big +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # SPECIFIC BACKUP #================================================= diff --git a/scripts/change_url b/scripts/change_url index 9a4d93a..aae96c9 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -31,17 +31,18 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) #================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +# BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up $app before changing its URL (may take a while)..." --weight=1 +ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --weight=1 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { + ynh_clean_check_starting # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - # restore it if the upgrade fails + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script diff --git a/scripts/install b/scripts/install index e3eb573..376cfb7 100644 --- a/scripts/install +++ b/scripts/install @@ -56,7 +56,7 @@ ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_script_progression --message="Finding an available port..." --weight=2 # Find an available port -port=$(ynh_find_port --port=8989) +port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port #================================================= @@ -64,7 +64,6 @@ ynh_app_setting_set --app=$app --key=port --value=$port #================================================= ynh_script_progression --message="Installing dependencies..." --weight=2 -# Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= @@ -73,7 +72,7 @@ ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -82,7 +81,12 @@ ynh_script_progression --message="Setting up source files..." --weight=5 ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src -ynh_setup_source --dest_dir=$final_path +ynh_setup_source --dest_dir="$final_path" +mkdir -p $final_path/config + +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" #================================================= # NGINX CONFIGURATION @@ -94,57 +98,47 @@ ynh_add_nginx_config #================================================= # SPECIFIC SETUP -#============================================== -# INSTALL DROPPY -#============================================== -ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=26 +#================================================= +# BUILD APP +#================================================= +ynh_script_progression --message="Building app... (this will take some time and resources!)" --weight=26 pushd "$final_path" ynh_use_nodejs - ynh_exec_warn_less $ynh_npm install + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install popd #================================================= -# CREATE DIRECTORY FOR DATA AND CONFIG +# CREATE DATA DIRECTORY #================================================= -ynh_script_progression --message="Creating the data directory..." --weight=1 +ynh_script_progression --message="Creating a data directory..." --weight=1 -# Define app's data directory data_path=/home/yunohost.app/$app ynh_app_setting_set --app=$app --key=data_path --value=$data_path -# Create datadir folder mkdir -p $data_path -# Give permission to the datadir chmod 750 "$data_path" chmod -R o-rwx "$data_path" -chown -R $app:www-data "$data_path" +chown -R $app:$app "$data_path" #================================================= -# SETUP SYSTEMD +# ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 - -env_path="$PATH" -ynh_add_systemd_config - -#================================================= -# MODIFY A CONFIG FILE -#================================================= -ynh_script_progression --message="Modifying a config file..." --weight=1 - -# Create config folder -mkdir -p $final_path/config +ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="../conf/config.json.example" --destination="$final_path/config/config.json" chmod 600 "$final_path/config/config.json" chown $app:$app "$final_path/config/config.json" -chmod 755 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" +#================================================= +# SETUP SYSTEMD +#================================================= +ynh_script_progression --message="Configuring a systemd service..." --weight=1 + +# Create a dedicated systemd config +ynh_add_systemd_config #================================================= # GENERIC FINALIZATION @@ -176,9 +170,11 @@ ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_ #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -# Make app public if necessary or protect it +# Make app public if necessary if [ $is_public -eq 1 ] then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi diff --git a/scripts/remove b/scripts/remove index 7856701..34052de 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,9 +27,10 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= +# 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..." --weight=1 + ynh_script_progression --message="Removing $app service integration..." --weight=1 yunohost service remove $app fi @@ -41,13 +42,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -ynh_remove_nodejs - #================================================= # REMOVE APP MAIN DIR #================================================= @@ -66,6 +60,7 @@ then ynh_script_progression --message="Removing app data directory..." --weight=1 ynh_secure_remove --file="$data_path" fi + #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -74,6 +69,13 @@ ynh_script_progression --message="Removing NGINX web server configuration..." -- # Remove the dedicated NGINX config ynh_remove_nginx_config +#================================================= +# REMOVE DEPENDENCIES +#================================================= +ynh_script_progression --message="Removing dependencies..." --weight=1 + +ynh_remove_nodejs + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index 04845f2..e1b06df 100644 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -22,7 +23,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -36,14 +37,15 @@ data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=2 -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring 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" @@ -53,15 +55,32 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring $app main directory..." --weight=20 +ynh_script_progression --message="Restoring the app main directory..." --weight=20 ynh_restore_file --origin_path="$final_path" +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + +#================================================= +# RESTORE THE DATA DIRECTORY +#================================================= +ynh_script_progression --message="Restoring the data directory..." --weight=1 + +ynh_restore_file --origin_path="$data_path" --not_mandatory + +mkdir -p $data_path + +chmod 750 "$data_path" +chmod -R o-rwx "$data_path" +chown -R $app:$app "$data_path" + #================================================= # SPECIFIC RESTORATION #================================================= @@ -80,23 +99,6 @@ ynh_script_progression --message="Restoring the systemd configuration..." --weig ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# RESTORE THE DATA DIRECTORY -#================================================= -ynh_script_progression --message="Restoring the data directory..." --weight=1 - -ynh_restore_file --origin_path="$data_path" --not_mandatory - -mkdir -p $data_path - -chmod 750 "$data_path" -chmod -R o-rwx "$data_path" -chown -R $app:www-data "$data_path" - -chmod 755 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" - #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 546d263..7d8a1de 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,27 +20,39 @@ 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) port=$(ynh_app_setting_get --app=$app --key=port) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up $app before upgrading (may take a while)..." --weight=2 +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=2 # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + ynh_clean_check_starting + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=9 + +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -53,22 +65,17 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=9 - -ynh_systemd_action --service_name=$app --action=stop --log_path=systemd - +if [ -z "$data_path" ]; then + data_path=/home/yunohost.app/$app + ynh_app_setting_set --app=$app --key=data_path --value=$data_path +fi #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 # Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir=$final_path +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -79,9 +86,13 @@ then ynh_script_progression --message="Upgrading source files..." --weight=10 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir=$final_path --keep="$final_path/config/config.json" + ynh_setup_source --dest_dir=$final_path --keep="config/config.json" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:$app "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -95,35 +106,29 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." --weight=2 -# Install Nodejs ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version #================================================= # SPECIFIC UPGRADE #============================================== -# INSTALL DROPPY +# BUILD APP #============================================== if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Building $app... (this will take some time and resources!)" --weight=25 + ynh_script_progression --message="Building app... (this will take some time and resources!)" --weight=25 pushd "$final_path" ynh_use_nodejs - ynh_exec_warn_less $ynh_npm install + ynh_exec_warn_less ynh_exec_as $app $ynh_node_load_PATH $ynh_npm install popd fi -chmod 755 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app: "$final_path" - #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=2 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=2 -env_path="$PATH" # Create a dedicated systemd config ynh_add_systemd_config