diff --git a/check_process b/check_process index b8bc603..de67898 100644 --- a/check_process +++ b/check_process @@ -19,7 +19,7 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=202cc0725652d4b8fbca52630267247bd58c8de1 + upgrade=1 from_commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8 backup_restore=1 multi_instance=1 port_already_use=0 @@ -43,11 +43,11 @@ setup_private=1 setup_public=1 upgrade=1 - upgrade=1 from_commit=202cc0725652d4b8fbca52630267247bd58c8de1 + upgrade=1 from_commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8 ;;; Options Email=kemenaran@gmail.com Notification=none ;;; Upgrade options - ; commit=202cc0725652d4b8fbca52630267247bd58c8de1 - name=Merge pull request #196 from amyblais/patch-51 + ; commit=4fa3ee4ad82a6154f2eb858a3da285a35afecef8 + name= Merge pull request #268 from YunoHost-Apps/testing \ No newline at end of file diff --git a/scripts/backup b/scripts/backup index 941ad87..fd92d5e 100755 --- a/scripts/backup +++ b/scripts/backup @@ -26,6 +26,7 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -42,7 +43,7 @@ ynh_backup --src_path="$final_path" # BACKUP THE APP DATA #================================================= -ynh_backup --src_path="/home/yunohost.app/$app" --is_big +ynh_backup --src_path="$data_path" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 8144413..2ef3c9b 100644 --- a/scripts/install +++ b/scripts/install @@ -69,6 +69,14 @@ ynh_script_progression --message="Finding an available port..." --weight=3 port=$(ynh_find_port --port=8065) ynh_app_setting_set --app=$app --key=port --value=$port +#================================================= +# CREATE DEDICATED USER +#================================================= +ynh_script_progression --message="Configuring system user..." --weight=3 + +# Create a system user +ynh_system_user_create --username=$app --home_dir="$final_path" + #================================================= # CREATE A MYSQL DATABASE #================================================= @@ -76,18 +84,9 @@ ynh_script_progression --message="Creating a MySQL database..." --weight=10 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name - ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=3 - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -104,17 +103,23 @@ elif [ "$version" = "Team" ]; then ynh_setup_source --dest_dir="$final_path" --source_id="$architecture" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # CREATE DIRECTORY FOR DATA #================================================= ynh_script_progression --message="Creating the data directory..." --weight=1 -# Create datadir folder -mkdir -p "/home/yunohost.app/$app" -# Define app's data directory -data_path="/home/yunohost.app/$app" -# Give permission to the datadir -chown -R $app: "$data_path" +data_path=/home/yunohost.app/$app +ynh_app_setting_set --app=$app --key=data_path --value=$data_path + +mkdir -p $data_path + +chmod 750 "$data_path" +chmod -R o-rwx "$data_path" +chown -R $app:www-data "$data_path" #================================================= # HANDLE LOG FILES AND LOGROTATE @@ -142,13 +147,6 @@ url=https://$domain$path_url ynh_add_config --template="../conf/config.json" --destination="$final_path/config/config.json" -#================================================= -# SECURE FILES AND DIRECTORIES -#================================================= - -chown -R $app: $final_path -chmod -R g+w $final_path - #================================================= # NGINX CONFIGURATION #================================================= diff --git a/scripts/remove b/scripts/remove index 783d0d0..cbb87ee 100755 --- a/scripts/remove +++ b/scripts/remove @@ -20,6 +20,7 @@ port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name final_path=$(ynh_app_setting_get --app=$app --key=final_path) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # STANDARD REMOVE @@ -59,7 +60,7 @@ ynh_script_progression --message="Removing $app main directory..." --weight=6 ynh_secure_remove --file="$final_path" # We don't delete this dir as it is marked as is-big -# ynh_secure_remove --file="/home/yunohost.app/$app" +# ynh_secure_remove --file="$data_path" #================================================= # REMOVE NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 6ece5f9..a5d42d6 100644 --- a/scripts/restore +++ b/scripts/restore @@ -32,14 +32,13 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name +data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -ynh_webpath_available --domain=$domain --path_url=$path_url \ - || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -51,6 +50,14 @@ test ! -d $final_path \ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +#================================================= +# RECREATE THE DEDICATED USER +#================================================= +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" + #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -58,20 +65,22 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" #================================================= -# RESTORE THE APP DATA +# RESTORE THE DATA DIRECTORY #================================================= +ynh_script_progression --message="Restoring the data directory..." --weight=4 -ynh_restore_file --origin_path="/home/yunohost.app/$app" --not_mandatory -chown -R $app: "/home/yunohost.app/$app" +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" #================================================= # RESTORE THE MYSQL DATABASE @@ -86,10 +95,6 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./ # RESTORE USER RIGHTS #================================================= -# Restore permissions on app files -chown -R $app: $final_path -chmod -R g+w $final_path - logs_path="/var/log/$app" mkdir -p $logs_path chown -R $app: $logs_path diff --git a/scripts/upgrade b/scripts/upgrade index 486e0e1..00d02f1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -34,6 +34,7 @@ language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) architecture=$(ynh_detect_arch) version=$(ynh_app_setting_get --app=$app --key=version) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) #================================================= # CHECK VERSION @@ -43,6 +44,20 @@ ynh_script_progression --message="Checking version..." --weight=1 previous_upstream_version="$(ynh_app_upstream_version --manifest="/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json")" upgrade_type=$(ynh_check_app_version_changed) +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -70,6 +85,12 @@ if [ -z "$db_name" ]; then ynh_app_setting_set --app=$app --key=db_name --value=$db_name fi +# If final_path doesn't exist, create it +if [ -z "$data_path" ]; then + data_path="/home/yunohost.app/$app" + ynh_app_setting_set --app=$app --key=data_path --value=$data_path +fi + # Cleaning legacy permissions if ynh_legacy_permissions_exists; then ynh_legacy_permissions_delete_all @@ -77,20 +98,6 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # 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 #================================================= @@ -100,6 +107,14 @@ ynh_script_progression --message="Stopping a systemd service..." --weight=3 ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +#================================================= +# 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" + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -130,6 +145,10 @@ then ynh_secure_remove --file="$tmpdir" fi +chmod 750 "$final_path" +chmod -R o-rwx "$final_path" +chown -R $app:www-data "$final_path" + #================================================= # NGINX CONFIGURATION #================================================= @@ -138,14 +157,6 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated NGINX config ynh_add_nginx_config -#================================================= -# 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 - #================================================= # SETUP SYSTEMD #================================================= @@ -154,26 +165,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=2 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# CREATE DIRECTORY FOR DATA -#================================================= -ynh_script_progression --message="Creating the data directory..." --weight=1 - -# Define app's data directory -data_path="/home/yunohost.app/$app" -# Create datadir folder -mkdir -p $data_path -# Give permission to the datadir -chown -R $app: "$data_path" - -#================================================= -# RESTORE FILE PERMISSIONS -#================================================= - -chown -R $app: $final_path -chmod -R g+w $final_path -chown -R $app: "/var/log/$app" - #================================================= # SETUP LOGROTATE #=================================================