diff --git a/conf/cronjobs b/conf/cronjobs index 79d98e2..3dd3c45 100644 --- a/conf/cronjobs +++ b/conf/cronjobs @@ -1,4 +1,4 @@ # Run poller periodically to update your website -*/10 * * * * __APP__ /usr/bin/php__PHPVERSION__ -f Code/Daemon/Run.php Cron > /dev/null 2>&1 +*/10 * * * * __APP__ /usr/bin/php__PHP_VERSION__ -f Code/Daemon/Run.php Cron > /dev/null 2>&1 # Daily software update job 30 05 * * * root /bin/bash __DATA_DIR__/daily-update.sh >> __DATA_DIR__/daily-updates.log 2>&1 diff --git a/conf/extra_php-fpm.conf b/conf/extra_php-fpm.conf deleted file mode 100644 index 14c8d27..0000000 --- a/conf/extra_php-fpm.conf +++ /dev/null @@ -1,4 +0,0 @@ -; Additional php.ini defines, specific to this pool of workers. - -php_admin_value[upload_max_filesize] = 50M -php_admin_value[post_max_size] = 50M \ No newline at end of file diff --git a/conf/htconfig.sample.php b/conf/htconfig.sample.php index e2e9ebe..4af080b 100644 --- a/conf/htconfig.sample.php +++ b/conf/htconfig.sample.php @@ -109,7 +109,7 @@ App::$config['system']['max_import_size'] = 200000; // Location of PHP command line processor -App::$config['system']['php_path'] = '/usr/bin/php__PHPVERSION__'; +App::$config['system']['php_path'] = '/usr/bin/php__PHP_VERSION__'; // Configure how we communicate with directory servers. // Deprecated. Please do not change. diff --git a/conf/nginx.conf b/conf/nginx.conf index f5d2b44..1fdac22 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -16,7 +16,7 @@ location __PATH__/ { location ~* \.php$ { try_files $uri =404; - fastcgi_pass unix:/var/run/php/php__PHPVERSION__-fpm-__NAME__.sock; + fastcgi_pass unix:/var/run/php/php__PHP_VERSION__-fpm-__APP__.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; diff --git a/manifest.toml b/manifest.toml index 92663b6..98f8191 100644 --- a/manifest.toml +++ b/manifest.toml @@ -14,7 +14,8 @@ license = "Unlicense" code = "https://codeberg.org/streams/streams" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = false @@ -51,6 +52,7 @@ ram.runtime = "50M" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.data_dir] diff --git a/scripts/_common.sh b/scripts/_common.sh index ea5fe64..519f979 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,22 +1,10 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= # PHP APP SPECIFIC #================================================= -YNH_COMPOSER_VERSION="2.5.8" +composer_version="2.5.8" YNH_PHP_VERSION="8.2" - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS -#================================================= diff --git a/scripts/backup b/scripts/backup index b1c66e8..7bea1e1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,44 +1,35 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# 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 -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/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" +ynh_backup "/etc/php/$php_version/fpm/pool.d/$app.conf" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +ynh_backup "/etc/fail2ban/jail.d/$app.conf" +ynh_backup "/etc/fail2ban/filter.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -46,24 +37,24 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP CRON JOBS #================================================= -ynh_backup --src_path="/etc/cron.d/$app" -ynh_backup --src_path="$data_dir" +ynh_backup "/etc/cron.d/$app" +ynh_backup "$data_dir" #================================================= # BACKUP THE DATABASE #================================================= -ynh_print_info --message="Backup of the MySQL database..." +ynh_print_info "Backup of the MySQL database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_mysql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/config b/scripts/config index bf78e56..4fe4408 100644 --- a/scripts/config +++ b/scripts/config @@ -1,22 +1,16 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS #================================================= -phpversion="$YNH_PHP_VERSION" -current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) +php_version="$YNH_PHP_VERSION" +current_fpm_footprint=$(ynh_app_setting_get --key=fpm_footprint) #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY @@ -24,7 +18,7 @@ current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) get__git_branch_mode() { # Git branch mode status - git_branch_mode_status="$(cd "$install_dir" && sudo -u $app git branch --show-current)" 2> /dev/null + git_branch_mode_status="$(cd "$install_dir" && ynh_exec_as_app git branch --show-current)" 2> /dev/null if echo $git_branch_mode_status | grep -q "release" then echo "0" @@ -32,7 +26,7 @@ get__git_branch_mode() { then echo "1" else - ynh_print_err --message="Not using \"release\" or \"dev\" branch, please handle this in command line" + ynh_print_warn "Not using \"release\" or \"dev\" branch, please handle this in command line" exit 0 fi } @@ -64,7 +58,6 @@ get__free_footprint() { # SPECIFIC SETTERS FOR TOML SHORT KEYS #================================================= - set__git_branch_mode() { if [ "$git_branch_mode" -eq "0" ] then @@ -73,52 +66,50 @@ set__git_branch_mode() { then # If git_branch was set to 0, switch to "release" branch ynh_print_info "Switching to \"release\" branch" - (cd "$install_dir" && ynh_exec_as "$app" git checkout release) + (cd "$install_dir" && ynh_exec_as_app git checkout release) ynh_print_info "Full update of the website" (cd /home/yunohost.app/"$app" && bash daily-update.sh >> daily-updates.log 2>&1) else - ynh_die --message="\"release\" branch is behind your local \"dev\" branch, rolling back is not allowed here" + ynh_die "\"release\" branch is behind your local \"dev\" branch, rolling back is not allowed here" exit 1 fi elif [ "$git_branch_mode" -eq "1" ]; then # If git_branch was set to 1, switch to "dev" branch - (cd "$install_dir" && ynh_exec_as "$app" git checkout dev) + (cd "$install_dir" && ynh_exec_as_app git checkout dev) ynh_print_info "Switching to \"dev\" branch" fi - ynh_app_setting_set --app=$app --key=git_branch_mode --value="$git_branch_mode" + ynh_app_setting_set --key=git_branch_mode --value="$git_branch_mode" } -set__fpm_footprint() { - if [ "$fpm_footprint" != "specific" ] +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | set__fpm_footprint() { +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" != "specific" ] then - ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_footprint" +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value="$fpm_footprint" fi } -set__fpm_free_footprint() { - if [ "$fpm_footprint" = "specific" ] +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | set__fpm_free_footprint() { +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ] then - ynh_app_setting_set --app=$app --key=fpm_footprint --value="$fpm_free_footprint" +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value="$fpm_free_footprint" fi } -#================================================= -# GENERIC FINALIZATION #================================================= ynh_app_config_validate() { _ynh_app_config_validate if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then - # If fpm_footprint is set to 'specific', use $fpm_free_footprint value. - if [ "$fpm_footprint" = "specific" ] +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | # If fpm_footprint is set to 'specific', use $fpm_free_footprint value. +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ] then - fpm_footprint=$fpm_free_footprint +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | fpm_footprint=$fpm_free_footprint fi - if [ "$fpm_footprint" == "0" ] +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" == "0" ] then - ynh_print_err --message="When selecting 'specific', you have to set a footprint value into the field below." + ynh_print_warn "When selecting 'specific', you have to set a footprint value into the field below." exit 0 fi @@ -128,7 +119,7 @@ ynh_app_config_validate() { ynh_app_config_apply() { _ynh_app_config_apply - ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint + ynh_config_add_phpfpm } ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index 6ad146d..52ea764 100755 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -16,80 +10,80 @@ source /usr/share/yunohost/helpers email=$(ynh_user_get_info --username=$admin --key=mail) upload="256M" random_string="$(ynh_string_random --length=48)" -fpm_footprint="medium" -fpm_free_footprint=0 -fpm_usage="medium" +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | fpm_footprint="medium" +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | fpm_free_footprint=0 +#REMOVEME? Everything about fpm_usage is removed in helpers2.1... | fpm_usage="medium" git_branch_mode="0" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 +ynh_script_progression "Storing installation settings..." -ynh_app_setting_set --app=$app --key=email --value=$email -ynh_app_setting_set --app=$app --key=upload --value=$upload -ynh_app_setting_set --app=$app --key=random_string --value=$random_string -ynh_app_setting_set --app=$app --key=fpm_footprint --value=$fpm_footprint -ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint -ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage -ynh_app_setting_set --app=$app --key=git_branch_mode --value="$git_branch_mode" +ynh_app_setting_set --key=email --value=$email +ynh_app_setting_set --key=upload --value=$upload +ynh_app_setting_set --key=random_string --value=$random_string +#REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_footprint --value=$fpm_footprint +#REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_free_footprint --value=$fpm_free_footprint +#REMOVEME? Everything about fpm_usage is removed in helpers2.1... | ynh_app_setting_set --key=fpm_usage --value=$fpm_usage +ynh_app_setting_set --key=git_branch_mode --value="$git_branch_mode" #================================================= # CREATE A DATABASE #================================================= -ynh_script_progression --message="Creating a database..." --weight=2 +ynh_script_progression "Creating a database..." -ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name \ +ynh_mysql_db_shell \ <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=1 +ynh_script_progression "Setting up source files..." mkdir -p "$install_dir" -chown -R $app:www-data "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" # Download, check integrity, uncompress and patch the source from GitHub -ynh_exec_as $app git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet +ynh_exec_as_app git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet git config --system --add safe.directory $install_dir touch "$install_dir/php.log" mkdir -p "$install_dir/store" mkdir -p "$install_dir/cache/smarty3" -chmod -R o-rwx "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" chmod -R 775 $install_dir/store $install_dir/cache #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 +ynh_script_progression "Configuring PHP-FPM..." # Create a dedicated PHP-FPM config -ynh_add_fpm_config --usage=$fpm_usage --footprint=$fpm_footprint +ynh_config_add_phpfpm # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # COMPOSER #================================================= -ynh_script_progression --message="Pulling in external libraries with Composer..." +ynh_script_progression "Pulling in external libraries with Composer..." -ynh_install_composer --workdir="$install_dir" -chown -R $app:www-data "$install_dir" +ynh_composer_install +ynh_composer_exec install --no-dev +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # ADDONS #================================================= -ynh_script_progression --message="Installing addons..." +ynh_script_progression "Installing addons..." pushd $install_dir - ynh_exec_as $app git config pull.rebase false - ynh_exec_as $app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons + ynh_exec_as_app git config pull.rebase false + ynh_exec_as_app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons cd /var/www/$app/extend/addon/zaddons - ynh_exec_as $app git config pull.rebase false + ynh_exec_as_app git config pull.rebase false popd #================================================= @@ -97,14 +91,14 @@ popd #================================================= # PROVISION DATABASE #================================================= -ynh_script_progression --message="Provisionning database..." --weight=1 +ynh_script_progression "Provisionning database..." -ynh_mysql_connect_as --user="$db_name" --password="$db_pwd" --database="$db_name" < $install_dir/install/schema_mysql.sql +ynh_mysql_db_shell < $install_dir/install/schema_mysql.sql #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." timezone=$( /dev/null +git_branch_mode_status="$(cd "$install_dir" && ynh_exec_as_app git branch --show-current)" 2> /dev/null if echo $git_branch_mode_status | grep -q "release" then git_branch_mode="0" - ynh_app_setting_set --app=$app --key=git_branch_mode --value="$git_branch_mode" + ynh_app_setting_set --key=git_branch_mode --value="$git_branch_mode" elif echo $git_branch_mode_status | grep -q "dev" then git_branch_mode="1" - ynh_app_setting_set --app=$app --key=git_branch_mode --value="$git_branch_mode" + ynh_app_setting_set --key=git_branch_mode --value="$git_branch_mode" else - ynh_print_err --message="You need to use \"release\" or \"dev\" branch, please handle this in command line" + ynh_print_warn "You need to use \"release\" or \"dev\" branch, please handle this in command line" exit 0 fi @@ -66,9 +52,10 @@ fi # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then - ynh_script_progression --message="Upgrading source files..." --weight=1 + ynh_script_progression "Upgrading source files..." # First we save what we need to keep mv $install_dir/store $data_dir/ @@ -76,111 +63,107 @@ then mv $install_dir/php.log $data_dir/ # Then we remove the previous install - ynh_secure_remove $install_dir + ynh_safe_rm $install_dir # We make the install cloning the repo mkdir -p "$install_dir" - chown -R $app:www-data "$install_dir" - - ynh_exec_as $app git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" + ynh_exec_as_app git clone https://codeberg.org/streams/streams.git "$install_dir" --quiet git config --system --add safe.directory $install_dir - ynh_app_setting_get --app=$app --key=git_branch_mode + ynh_app_setting_get --key=git_branch_mode if [[ -n $git_branch_mode ]] && [ "$git_branch_mode" -eq "1" ] then ynh_print_info "Switching to \"dev\" branch" - (cd "$install_dir" && ynh_exec_as $app git checkout dev) - fi + (cd "$install_dir" && ynh_exec_as_app git checkout dev) + fi # We restore what we previously saved mv $data_dir/store $install_dir/ mv $data_dir/cache $install_dir/ mv $data_dir/php.log $install_dir/ - chmod -R o-rwx "$install_dir" - chown -R $app:www-data "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" chmod -R 775 $install_dir/store $install_dir/cache fi #================================================= # PHP-FPM CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading PHP-FPM configuration..." --weight=1 +ynh_script_progression "Upgrading PHP-FPM configuration..." # Create a dedicated PHP-FPM config -ynh_add_fpm_config --phpversion=$phpversion --usage=$fpm_usage --footprint=$fpm_footprint +ynh_config_add_phpfpm # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx #================================================= # COMPOSER #================================================= -ynh_script_progression --message="Pulling in external libraries with Composer..." +ynh_script_progression "Pulling in external libraries with Composer..." -ynh_install_composer -chown -R $app:www-data "$install_dir" +ynh_composer_install +ynh_composer_exec install --no-dev +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "$install_dir" #================================================= # ADDONS #================================================= -ynh_script_progression --message="Installing addons..." +ynh_script_progression "Installing addons..." pushd $install_dir - ynh_exec_as $app git config pull.rebase false - ynh_exec_as $app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons + ynh_exec_as_app git config pull.rebase false + ynh_exec_as_app util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons cd /var/www/$app/extend/addon/zaddons - ynh_exec_as $app git config pull.rebase false + ynh_exec_as_app git config pull.rebase false popd -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=1 +ynh_script_progression "Updating configuration..." timezone=$(