diff --git a/conf/.env b/conf/dot_env similarity index 100% rename from conf/.env rename to conf/dot_env diff --git a/scripts/backup b/scripts/backup index eb3754a..c900e22 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,29 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading settings..." - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -45,15 +22,11 @@ ynh_print_info --message="Declaring files to be backed up..." ynh_backup --src_path="$install_dir" #================================================= -# BACKUP THE NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -#================================================= -# BACKUP THE PHP-FPM CONFIGURATION -#================================================= - ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= @@ -61,8 +34,8 @@ ynh_backup --src_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" #================================================= if [ "$database" = "mysql" ]; then - ynh_print_info --message="Backing up the MySQL database..." - ynh_mysql_dump_db --database="$db_name" > db.sql + ynh_print_info --message="Backing up the MySQL database..." + ynh_mysql_dump_db --database="$db_name" > db.sql fi #================================================= diff --git a/scripts/install b/scripts/install index 137911a..d830cb7 100755 --- a/scripts/install +++ b/scripts/install @@ -47,7 +47,7 @@ chmod 400 "$install_dir/config/packages/local.yaml" chown "$app:$app" "$install_dir/config/packages/local.yaml" # Configure environement -ynh_add_config --template=".env" --destination="$install_dir/.env" +ynh_add_config --template="dot_env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" chown "$app:$app" "$install_dir/.env" @@ -55,7 +55,7 @@ chown "$app:$app" "$install_dir/.env" #================================================= # BUILD KIMAI2 #================================================= -ynh_script_progression --message="Building Kimai2..." --weight=1 +ynh_script_progression --message="Building $app..." --weight=1 ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir" --install_args="--optimize-autoloader --no-interaction" ynh_composer_exec --phpversion="$phpversion" --workdir="$install_dir" --commands="require laminas/laminas-ldap" @@ -69,7 +69,7 @@ setfacl -R -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" #================================================= # INSTALL KIMAI2 #================================================= -ynh_script_progression --message="Installing Kimai2..." --weight=1 +ynh_script_progression --message="Installing $app..." --weight=1 pushd "$install_dir" ynh_exec_as "$app" "php$phpversion" bin/console kimai:install -n diff --git a/scripts/remove b/scripts/remove index 4952dba..5b17c2d 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,73 +10,16 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= - -if [ "$database" = "mysql" ]; then -#REMOVEME? ynh_script_progression --message="Removing the MySQL database..." --weight=1 - - # Remove a database if it exists, along with the associated user -#REMOVEME? ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name -fi - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -#REMOVEME? ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -#REMOVEME? ynh_secure_remove --file="$install_dir" - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1 +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the dedicated NGINX config ynh_remove_nginx_config -#================================================= -# REMOVE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Removing PHP-FPM configuration..." --weight=1 - # Remove the dedicated PHP-FPM config ynh_remove_fpm_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove metapackage and its dependencies -#REMOVEME? ynh_remove_app_dependencies - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Removing the dedicated system user..." --weight=1 - -# Delete a system user -#REMOVEME? ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 48cc359..ff226f6 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,49 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -#REMOVEME? ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) -#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -#REMOVEME? test ! -d $install_dir \ - || ynh_die --message="There is already a directory: $install_dir " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 - -# Create the dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -63,44 +20,27 @@ ynh_restore_file --origin_path="$install_dir" chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app:www-data "$install_dir" -setfacl -dR -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" -setfacl -R -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=1 - -# Define and install dependencies -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the PHP-FPM configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" - -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +setfacl -dR -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" +setfacl -R -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" #================================================= # RESTORE THE MYSQL DATABASE #================================================= - if [ "$database" = "mysql" ]; then -#REMOVEME? ynh_script_progression --message="Restoring the MySQL database..." --weight=1 -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -#REMOVEME? ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd - ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql + ynh_script_progression --message="Restoring the MySQL database..." --weight=1 + ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql fi +#================================================= +# RESTORE SYSTEM CONFIGURATIONS +#================================================= +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 + +ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" + +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # GENERIC FINALIZATION #================================================= @@ -108,7 +48,7 @@ fi #================================================= ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 -ynh_systemd_action --service_name=php$phpversion-fpm --action=reload +ynh_systemd_action --service_name="php$phpversion-fpm" --action=reload ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 32c349d..10044a7 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,191 +9,91 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading settings..." --weight=1 - -#REMOVEME? app=$YNH_APP_INSTANCE_NAME - -#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) -#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) -#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) -#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) -#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#REMOVEME? db_user=$db_name -#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -#REMOVEME? registration=$(ynh_app_setting_get --app=$app --key=registration) -#REMOVEME? database=$(ynh_app_setting_get --app=$app --key=database) -#REMOVEME? random_key=$(ynh_app_setting_get --app=$app --key=random_key) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." --weight=1 - -upgrade_type=$(ynh_check_app_version_changed) - -if [ "$database" == "sqlite" ] -then - ynh_script_progression --message="Sqlite is not more supported by Kimai2..." - ynh_script_progression --message="Kimai2 will be upgraded to last available version : 1.13" - if ynh_compare_current_package_version --comparison ge --version 1.17.1~ynh1 - then - ynh_script_progression --message="Kimai2 sqlite version is already to the last available version, no upgrade will be made" - ynh_die --message="" 0 - fi -fi - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -#REMOVEME? ynh_backup_before_upgrade -#REMOVEME? ynh_clean_setup () { - # Restore it if the upgrade fails -#REMOVEME? ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -#REMOVEME? ynh_abort_if_errors - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# If install_dir doesn't exist, create it -if [ -z "$install_dir" ]; then -#REMOVEME? install_dir=/var/www/$app -#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir +if [ "$database" == "sqlite" ]; then + ynh_script_progression --message="Sqlite is not supported by Kimai2 anymore..." + ynh_script_progression --message="Kimai2 will be upgraded to last available version : 1.13" + if ynh_compare_current_package_version --comparison ge --version 1.17.1~ynh1; then + ynh_script_progression --message="Kimai2 sqlite version is already to the last available version, no upgrade will be made" + ynh_die --message="" 0 + fi fi -# Cleaning legacy permissions -#REMOVEME? if ynh_legacy_permissions_exists; then -#REMOVEME? ynh_legacy_permissions_delete_all +# #REMOVEME? if ! ynh_permission_exists --permission="teamlead"; then +# #REMOVEME? ynh_permission_create --permission="teamlead" +# fi - ynh_app_setting_delete --app=$app --key=is_public +# #REMOVEME? if ! ynh_permission_exists --permission="admin"; then +# #REMOVEME? ynh_permission_create --permission="admin" +# fi + +# #REMOVEME? if ! ynh_permission_exists --permission="super_admin"; then +# #REMOVEME? ynh_permission_create --permission="super_admin" --allowed="$admin" +# fi + +if [ -z "${registration:-}" ]; then + registration=0 + ynh_app_setting_set --app="$app" --key=registration --value="$registration" fi -#REMOVEME? if ! ynh_permission_exists --permission="teamlead"; then -#REMOVEME? ynh_permission_create --permission="teamlead" -fi - -#REMOVEME? if ! ynh_permission_exists --permission="admin"; then -#REMOVEME? ynh_permission_create --permission="admin" -fi - -#REMOVEME? if ! ynh_permission_exists --permission="super_admin"; then -#REMOVEME? ynh_permission_create --permission="super_admin" --allowed="$admin" -fi - -if [ -z "$registration" ]; then - registration_enabled="false" - ynh_app_setting_set --app=$app --key=registration --value=$registration -fi - -#================================================= -# CREATE DEDICATED USER -#================================================= -#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 - -# Create a dedicated user (if not existing) -#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --weight=1 +if ynh_compare_current_package_version --comparison le --version 1.30.0~ynh1; then + ynh_script_progression --message="Doing a hard cache flush for major Kimai 2 update from version 1.x to 2.x" - if ynh_compare_current_package_version --comparison le --version 1.30.0~ynh1 - then - ynh_script_progression --message="Doing a hard cache flush for major Kimai 2 update from version 1.x to 2.x" - - # Download, check integrity, uncompress and patch the source from app.src - # Remove local.yaml as recommended for major version upgrade https://github.com/kimai/kimai/blob/main/UPGRADING.md - # As a full_replace (see https://www.kimai.org/documentation/updates.html) is performed keep .env file - ynh_setup_source --dest_dir="$install_dir" --keep=".env var/invoices/ var/data/" --full_replace=1 - else - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --keep="config/packages/local.yaml var/invoices/ var/data/" - fi + # Download, check integrity, uncompress and patch the source from app.src + # Remove local.yaml as recommended for major version upgrade https://github.com/kimai/kimai/blob/main/UPGRADING.md + # As a full_replace (see https://www.kimai.org/documentation/updates.html) is performed keep .env file + ynh_setup_source --dest_dir="$install_dir" --keep=".env var/invoices/ var/data/" --full_replace=1 +else + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$install_dir" --keep="config/packages/local.yaml var/invoices/ var/data/" fi chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -setfacl -dR -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" -setfacl -R -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1 - -#REMOVEME? ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 - -# Create a dedicated PHP-FPM config -ynh_add_fpm_config -#REMOVEME? phpversion=$(ynh_app_setting_get --app=$app --key=phpversion) - -#================================================= -# NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1 - -# Create a dedicated NGINX config -ynh_add_nginx_config - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# BUILD KIMAI2 -#================================================= -ynh_script_progression --message="Building $app..." --weight=1 - -ynh_install_composer --phpversion="$YNH_PHP_VERSION" --workdir="$install_dir" --install_args="--optimize-autoloader --no-interaction" -ynh_composer_exec --phpversion="$YNH_PHP_VERSION" --workdir="$install_dir" --commands="require laminas/laminas-ldap --optimize-autoloader" - -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" -setfacl -dR -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" -setfacl -R -m g:"www-data":rwX -m u:$app:rwX "$install_dir/var/" +chown -R "$app:www-data" "$install_dir" +setfacl -dR -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" +setfacl -R -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" #================================================= # UPDATE A CONFIG FILE #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 -if [ $registration -eq 1 ] -then - registration="true" -else - registration="false" -fi +registration=$(boolstr "$registration") -ynh_add_config --template="../conf/local.yaml" --destination="$install_dir/config/packages/local.yaml" +ynh_add_config --template="local.yaml" --destination="$install_dir/config/packages/local.yaml" chmod 400 "$install_dir/config/packages/local.yaml" -chown $app:$app "$install_dir/config/packages/local.yaml" +chown "$app:$app" "$install_dir/config/packages/local.yaml" # Configure environement -ynh_add_config --template="../conf/.env" --destination="$install_dir/.env" +ynh_add_config --template="dot_env" --destination="$install_dir/.env" chmod 400 "$install_dir/.env" -chown $app:$app "$install_dir/.env" +chown "$app:$app" "$install_dir/.env" + +#================================================= +# BUILD KIMAI2 +#================================================= +ynh_script_progression --message="Building $app..." --weight=1 + +ynh_install_composer --phpversion="$phpversion" --workdir="$install_dir" --install_args="--optimize-autoloader --no-interaction" +ynh_composer_exec --phpversion="$phpversion" --workdir="$install_dir" --commands="require laminas/laminas-ldap --optimize-autoloader" + +chmod 750 "$install_dir" +chmod -R o-rwx "$install_dir" +chown -R "$app:www-data" "$install_dir" +setfacl -dR -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" +setfacl -R -m g:"www-data":rwX -m u:"$app":rwX "$install_dir/var/" #================================================= # INSTALL KIMAI2 @@ -201,17 +101,19 @@ chown $app:$app "$install_dir/.env" ynh_script_progression --message="Installing $app..." --weight=1 pushd "$install_dir" - ynh_exec_as $app php$YNH_PHP_VERSION bin/console kimai:update -n + ynh_exec_as "$app" "php$phpversion" bin/console kimai:update -n popd #================================================= -# GENERIC FINALIZATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -# RELOAD NGINX -#================================================= -#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 -#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload +# Create a dedicated PHP-FPM config +ynh_add_fpm_config + +# Create a dedicated NGINX config +ynh_add_nginx_config #================================================= # END OF SCRIPT