diff --git a/conf/nginx.conf b/conf/nginx.conf index fd2b377..e5d33a5 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -2,7 +2,7 @@ location __PATH__/ { # Path to source - alias __FINALPATH__/ ; + alias __FINALPATH__/htdocs/ ; # Force usage of https if ($scheme = http) { diff --git a/scripts/backup b/scripts/backup index a546584..a5ef263 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,6 @@ ynh_script_progression --message="Loading installation settings..." --time --wei app=$YNH_APP_INSTANCE_NAME -src_path=$(ynh_app_setting_get --app=$app --key=src_path) 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) @@ -36,7 +35,7 @@ db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 -ynh_backup --src_path="$src_path" +ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 8ff4844..e621976 100644 --- a/scripts/install +++ b/scripts/install @@ -55,13 +55,9 @@ ynh_script_progression --message="Validating installation parameters..." --time ### If the app uses nginx as web server (written in HTML/PHP in most cases), the final path should be "/var/www/$app". ### If the app provides an internal web server (or uses another application server such as uwsgi), the final path should be "/opt/yunohost/$app" final_path=/var/www/$app -src_path=$final_path test ! -e "$final_path" || ynh_die --message="This path already contains a folder" -# Then adjust to dolibarr specificity (app is in htdocs sub-directory) -final_path=/var/www/$app/htdocs/ - # Register (book) web path ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url @@ -107,15 +103,14 @@ ynh_script_progression --message="Setting up source files..." --time --weight=1 ### `ynh_setup_source` use the file conf/app.src ynh_app_setting_set --app=$app --key=final_path --value=$final_path -ynh_app_setting_set --app=$app --key=src_path --value=$src_path # Download, check integrity, uncompress and patch the source from app.src ynh_script_progression --message="Download source files..." --time --weight=1 -ynh_setup_source --dest_dir="$src_path" +ynh_setup_source --dest_dir="$final_path" # Create necessary files -datadir=$src_path/documents -touch $final_path/conf/conf.php +datadir=$final_path/documents +touch $final_path/htdocs/conf/conf.php mkdir -p $datadir chmod go-w $datadir @@ -162,7 +157,7 @@ ynh_add_fpm_config # PREPARE AND INSTALL APP #================================================= -finstall="$final_path/install/install.forced.php" +finstall="$final_path/htdocs/install/install.forced.php" cp ../conf/install.forced.php "$finstall" # Change variables in Wordpress configuration @@ -180,7 +175,7 @@ fi fhook=../hooks/post_user_create ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$fhook" ynh_replace_string --match_string="__MEMBER__" --replace_string="$member" --target_file="$fhook" -ynh_replace_string --match_string="__SRCPATH__" --replace_string="$src_path" --target_file="$fhook" +ynh_replace_string --match_string="__SRCPATH__" --replace_string="$final_path" --target_file="$fhook" #================================================= @@ -193,7 +188,7 @@ ynh_replace_string --match_string="__SRCPATH__" --replace_string="$src_path" --t ### forms. # Set right permissions for curl install -chown -R $app "$src_path" +chown -R $app "$final_path" # Set the app as temporarily public for curl call @@ -245,7 +240,7 @@ ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < .. # Populate the database with YNH users. ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap_user.sql -if php $src_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then +if php $final_path/scripts/user/sync_users_ldap2dolibarr.php commitiferror --server=localhost -y; then ynh_print_info --message="ldap user update ok" else ynh_print_warn --message="ldap user update ended with error" @@ -256,7 +251,7 @@ if [ $member -eq 1 ] then ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name < ../conf/sql/ldap_member.sql - if php $src_path/scripts/members/sync_members_ldap2dolibarr.php commitiferror 1 --server=localhost -y; then + if php $final_path/scripts/members/sync_members_ldap2dolibarr.php commitiferror 1 --server=localhost -y; then ynh_print_info --message="ldap member update ok" else ynh_print_warn --message="ldap member update ended with error" @@ -278,7 +273,7 @@ fi # Setup HTTP auth in conf ynh_script_progression --message="configuring config file" --time --weight=4 -ynh_replace_string --match_string="dolibarr_main_authentication='dolibarr'" --replace_string="dolibarr_main_authentication='http'" --target_file="$final_path/conf/conf.php" +ynh_replace_string --match_string="dolibarr_main_authentication='dolibarr'" --replace_string="dolibarr_main_authentication='http'" --target_file="$final_path/htdocs/conf/conf.php" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -289,7 +284,7 @@ ynh_replace_string --match_string="dolibarr_main_authentication='dolibarr'" --re ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$final_path/conf/conf.php" +ynh_store_file_checksum --file="$final_path/htdocs/conf/conf.php" #================================================= # ADD A CRON JOB @@ -308,9 +303,9 @@ touch $cron_path ### that really need such authorization. # Set permissions to app files -chown -R root "$src_path" +chown -R root "$final_path" chown -R $app "$datadir" -chmod 644 "$final_path/conf/conf.php" +chmod 644 "$final_path/htdocs/conf/conf.php" #================================================= # SETUP LOGROTATE @@ -326,7 +321,7 @@ ynh_script_progression --message="Configuring log rotation..." --time --weight=1 ### - And the section "SETUP LOGROTATE" in the upgrade script # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$src_path/documents/dolibarr.log" +ynh_use_logrotate --logfile="$final_path/documents/dolibarr.log" #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 2e88b5f..7256a06 100644 --- a/scripts/remove +++ b/scripts/remove @@ -21,7 +21,6 @@ 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) -src_path=$(ynh_app_setting_get --app=$app --key=src_path) #================================================= # STANDARD REMOVE @@ -58,7 +57,7 @@ ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name ynh_script_progression --message="Removing app main directory..." --time --weight=1 # Remove the app directory securely -ynh_secure_remove --file="$src_path" +ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION diff --git a/scripts/restore b/scripts/restore index 8687b29..2128d8b 100755 --- a/scripts/restore +++ b/scripts/restore @@ -30,7 +30,6 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -src_path=$(ynh_app_setting_get --app=$app --key=src_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name @@ -42,8 +41,8 @@ ynh_script_progression --message="Validating restoration parameters..." --time - ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d $src_path \ - || ynh_die --message="There is already a directory: $src_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -58,7 +57,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 -ynh_restore_file --origin_path="$src_path" +ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER @@ -73,7 +72,7 @@ ynh_system_user_create --username=$app #================================================= # Restore permissions on app files -chown -R root: $src_path +chown -R root: $final_path #================================================= # RESTORE THE PHP-FPM CONFIGURATION diff --git a/scripts/upgrade b/scripts/upgrade index 82c973a..cf057cc 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,12 +21,11 @@ path_url=$(ynh_app_setting_get --app=$app --key=path) admin=$(ynh_app_setting_get --app=$app --key=admin) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -src_path=$(ynh_app_setting_get --app=$app --key=src_path) language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) current_version=$(ynh_app_setting_get --app=$app --key=version) update_version=$(ynh_app_upstream_version "../manifest.json") -datadir=$src_path/documents +datadir=$final_path/documents #================================================= # CHECK VERSION @@ -62,13 +61,9 @@ fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then - src_path=/var/www/$app - - # Then adjust to dolibarr specificity (app is in htdocs sub-directory) - final_path=$src_path/htdocs/ + final_path=/var/www/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path - ynh_app_setting_set --app=$app --key=src_path --value=$src_path fi #================================================= @@ -108,7 +103,7 @@ then ynh_script_progression --message="Upgrading source files..." --time --weight=1 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$src_path" + ynh_setup_source --dest_dir="$final_path" fi #================================================= @@ -140,32 +135,34 @@ ynh_add_fpm_config #================================================= # LAUNCH UPGRADE #================================================= -ynh_script_progression --message="Upgrading app from $current_version to $update_version" --time --weight=1 +if [ "$upgrade_type" == "UPGRADE_APP" ] +then + ynh_script_progression --message="Upgrading app from $current_version to $update_version" --time --weight=1 -chown -R $app "$src_path" + chown -R $app "$final_path" + # Remove the lock if it exists + lock=$final_path/documents/install.lock + [[ -f $lock ]] && sudo rm $lock -# Remove the lock if it exists -lock=$src_path/documents/install.lock -[[ -f $lock ]] && sudo rm $lock - -# Upgrade with CURL -cd $final_path/install/ -if php upgrade.php $current_version $update_version > /var/log/$app/upgrade.html; then - ynh_print_info --message="Step 1 upgrading ended successfully" -else - ynh_print_warn --message="Step 1 upgrading ended with error" -fi -if php upgrade2.php $current_version $update_version > /var/log/$app/upgrade2.html; then - ynh_print_info --message="Step 2 upgrading ended successfully" -else - ynh_print_warn --message="Step 2 upgrading ended with error" -fi -if php step5.php $current_version $update_version > /var/log/$app/upgrade3.html; then - ynh_print_info --message="Step 3 upgrading ended successfully" -else - ynh_print_warn --message="Step 3 upgrading ended with error" + # Upgrade with CURL + cd $final_path/htdocs/install/ + if php upgrade.php $current_version $update_version > /var/log/$app/upgrade.html; then + ynh_print_info --message="Step 1 upgrading ended successfully" + else + ynh_print_warn --message="Step 1 upgrading ended with error" + fi + if php upgrade2.php $current_version $update_version > /var/log/$app/upgrade2.html; then + ynh_print_info --message="Step 2 upgrading ended successfully" + else + ynh_print_warn --message="Step 2 upgrading ended with error" + fi + if php step5.php $current_version $update_version > /var/log/$app/upgrade3.html; then + ynh_print_info --message="Step 3 upgrading ended successfully" + else + ynh_print_warn --message="Step 3 upgrading ended with error" + fi fi #================================================= @@ -174,9 +171,9 @@ fi ### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/conf/conf.php" +ynh_backup_if_checksum_is_different --file="$final_path/htdocs/conf/conf.php" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/conf/conf.php" +ynh_store_file_checksum --file="$final_path/htdocs/conf/conf.php" #================================================= # SETUP LOGROTATE @@ -194,8 +191,8 @@ ynh_use_logrotate --non-append # Set permissions on app files # Set permissions to app files -chown -R root "$src_path" -chmod 644 "$final_path/conf/conf.php" +chown -R root "$final_path" +chmod 644 "$final_path/htdocs/conf/conf.php" chown -R $app "$datadir" chmod go-w $datadir