1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/streams_ynh.git synced 2024-09-03 20:26:20 +02:00

[autopatch] Automatic patch attempt for helpers 2.1

This commit is contained in:
Yunohost-Bot 2024-08-31 03:03:46 +02:00 committed by Alexandre Aubin
parent ddf1cc2751
commit 390b801947
12 changed files with 163 additions and 235 deletions

View file

@ -1,4 +1,4 @@
# Run poller periodically to update your website # 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 # Daily software update job
30 05 * * * root /bin/bash __DATA_DIR__/daily-update.sh >> __DATA_DIR__/daily-updates.log 2>&1 30 05 * * * root /bin/bash __DATA_DIR__/daily-update.sh >> __DATA_DIR__/daily-updates.log 2>&1

View file

@ -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

View file

@ -109,7 +109,7 @@ App::$config['system']['max_import_size'] = 200000;
// Location of PHP command line processor // 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. // Configure how we communicate with directory servers.
// Deprecated. Please do not change. // Deprecated. Please do not change.

View file

@ -16,7 +16,7 @@ location __PATH__/ {
location ~* \.php$ { location ~* \.php$ {
try_files $uri =404; 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; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

View file

@ -14,7 +14,8 @@ license = "Unlicense"
code = "https://codeberg.org/streams/streams" code = "https://codeberg.org/streams/streams"
[integration] [integration]
yunohost = ">= 11.2" yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all" architectures = "all"
multi_instance = true multi_instance = true
ldap = false ldap = false
@ -51,6 +52,7 @@ ram.runtime = "50M"
[resources.system_user] [resources.system_user]
[resources.install_dir] [resources.install_dir]
group = "www-data:r-x"
[resources.data_dir] [resources.data_dir]

View file

@ -1,22 +1,10 @@
#!/bin/bash #!/bin/bash
#================================================= #=================================================
# COMMON VARIABLES # COMMON VARIABLES AND CUSTOM HELPERS
#================================================= #=================================================
# PHP APP SPECIFIC # PHP APP SPECIFIC
#================================================= #=================================================
YNH_COMPOSER_VERSION="2.5.8" composer_version="2.5.8"
YNH_PHP_VERSION="8.2" YNH_PHP_VERSION="8.2"
#=================================================
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================

View file

@ -1,44 +1,35 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= ynh_print_info "Declaring files to be backed up..."
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
#================================================= #=================================================
# BACKUP THE APP MAIN DIR # BACKUP THE APP MAIN DIR
#================================================= #=================================================
ynh_backup --src_path="$install_dir" ynh_backup "$install_dir"
#================================================= #=================================================
# BACKUP THE NGINX CONFIGURATION # 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 # 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 # BACKUP FAIL2BAN CONFIGURATION
#================================================= #=================================================
ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup "/etc/fail2ban/jail.d/$app.conf"
ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" ynh_backup "/etc/fail2ban/filter.d/$app.conf"
#================================================= #=================================================
# SPECIFIC BACKUP # SPECIFIC BACKUP
@ -46,24 +37,24 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf"
# BACKUP LOGROTATE # BACKUP LOGROTATE
#================================================= #=================================================
ynh_backup --src_path="/etc/logrotate.d/$app" ynh_backup "/etc/logrotate.d/$app"
#================================================= #=================================================
# BACKUP CRON JOBS # BACKUP CRON JOBS
#================================================= #=================================================
ynh_backup --src_path="/etc/cron.d/$app" ynh_backup "/etc/cron.d/$app"
ynh_backup --src_path="$data_dir" ynh_backup "$data_dir"
#================================================= #=================================================
# BACKUP THE DATABASE # 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 # 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)."

View file

@ -1,22 +1,16 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
ynh_abort_if_errors #REMOVEME? ynh_abort_if_errors
#================================================= #=================================================
# RETRIEVE ARGUMENTS # RETRIEVE ARGUMENTS
#================================================= #=================================================
phpversion="$YNH_PHP_VERSION" php_version="$YNH_PHP_VERSION"
current_fpm_footprint=$(ynh_app_setting_get --app=$app --key=fpm_footprint) current_fpm_footprint=$(ynh_app_setting_get --key=fpm_footprint)
#================================================= #=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY # 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() { get__git_branch_mode() {
# Git branch mode status # 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" if echo $git_branch_mode_status | grep -q "release"
then then
echo "0" echo "0"
@ -32,7 +26,7 @@ get__git_branch_mode() {
then then
echo "1" echo "1"
else 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 exit 0
fi fi
} }
@ -64,7 +58,6 @@ get__free_footprint() {
# SPECIFIC SETTERS FOR TOML SHORT KEYS # SPECIFIC SETTERS FOR TOML SHORT KEYS
#================================================= #=================================================
set__git_branch_mode() { set__git_branch_mode() {
if [ "$git_branch_mode" -eq "0" ] if [ "$git_branch_mode" -eq "0" ]
then then
@ -73,52 +66,50 @@ set__git_branch_mode() {
then then
# If git_branch was set to 0, switch to "release" branch # If git_branch was set to 0, switch to "release" branch
ynh_print_info "Switching 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" ynh_print_info "Full update of the website"
(cd /home/yunohost.app/"$app" && bash daily-update.sh >> daily-updates.log 2>&1) (cd /home/yunohost.app/"$app" && bash daily-update.sh >> daily-updates.log 2>&1)
else 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 exit 1
fi fi
elif [ "$git_branch_mode" -eq "1" ]; then elif [ "$git_branch_mode" -eq "1" ]; then
# If git_branch was set to 1, switch to "dev" branch # 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" ynh_print_info "Switching to \"dev\" branch"
fi 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() { #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | set__fpm_footprint() {
if [ "$fpm_footprint" != "specific" ] #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" != "specific" ]
then 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 fi
} }
set__fpm_free_footprint() { #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | set__fpm_free_footprint() {
if [ "$fpm_footprint" = "specific" ] #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ]
then 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 fi
} }
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
ynh_app_config_validate() { ynh_app_config_validate() {
_ynh_app_config_validate _ynh_app_config_validate
if [ "${changed[fpm_usage]}" == "true" ] || [ "${changed[fpm_footprint]}" == "true" ] || [ "${changed[fpm_free_footprint]}" == "true" ]; then 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. #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | # If fpm_footprint is set to 'specific', use $fpm_free_footprint value.
if [ "$fpm_footprint" = "specific" ] #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" = "specific" ]
then then
fpm_footprint=$fpm_free_footprint #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | fpm_footprint=$fpm_free_footprint
fi fi
if [ "$fpm_footprint" == "0" ] #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ "$fpm_footprint" == "0" ]
then 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 exit 0
fi fi
@ -128,7 +119,7 @@ ynh_app_config_validate() {
ynh_app_config_apply() { ynh_app_config_apply() {
_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 ynh_app_config_run $1

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -16,80 +10,80 @@ source /usr/share/yunohost/helpers
email=$(ynh_user_get_info --username=$admin --key=mail) email=$(ynh_user_get_info --username=$admin --key=mail)
upload="256M" upload="256M"
random_string="$(ynh_string_random --length=48)" random_string="$(ynh_string_random --length=48)"
fpm_footprint="medium" #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | fpm_footprint="medium"
fpm_free_footprint=0 #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | fpm_free_footprint=0
fpm_usage="medium" #REMOVEME? Everything about fpm_usage is removed in helpers2.1... | fpm_usage="medium"
git_branch_mode="0" git_branch_mode="0"
#================================================= #=================================================
# STORE SETTINGS FROM MANIFEST # 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 --key=email --value=$email
ynh_app_setting_set --app=$app --key=upload --value=$upload ynh_app_setting_set --key=upload --value=$upload
ynh_app_setting_set --app=$app --key=random_string --value=$random_string ynh_app_setting_set --key=random_string --value=$random_string
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
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_free_footprint --value=$fpm_free_footprint
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage #REMOVEME? Everything about fpm_usage is removed in helpers2.1... | ynh_app_setting_set --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=git_branch_mode --value="$git_branch_mode"
#================================================= #=================================================
# CREATE A DATABASE # 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;" <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
#================================================= #=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE # 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" 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 # 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 git config --system --add safe.directory $install_dir
touch "$install_dir/php.log" touch "$install_dir/php.log"
mkdir -p "$install_dir/store" mkdir -p "$install_dir/store"
mkdir -p "$install_dir/cache/smarty3" 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 chmod -R 775 $install_dir/store $install_dir/cache
#================================================= #=================================================
# PHP-FPM CONFIGURATION # PHP-FPM CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Configuring PHP-FPM..." --weight=1 ynh_script_progression "Configuring PHP-FPM..."
# Create a dedicated PHP-FPM config # 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 # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
#================================================= #=================================================
# COMPOSER # 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" ynh_composer_install
chown -R $app:www-data "$install_dir" 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 # ADDONS
#================================================= #=================================================
ynh_script_progression --message="Installing addons..." ynh_script_progression "Installing addons..."
pushd $install_dir pushd $install_dir
ynh_exec_as $app git config pull.rebase false 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 util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons
cd /var/www/$app/extend/addon/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 popd
#================================================= #=================================================
@ -97,14 +91,14 @@ popd
#================================================= #=================================================
# PROVISION DATABASE # 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 # ADD A CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_script_progression "Adding $app's configuration..."
timezone=$(</etc/timezone) timezone=$(</etc/timezone)
@ -115,48 +109,46 @@ else
max_imported_follow=0 max_imported_follow=0
fi fi
ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php" ynh_config_add --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php"
ynh_store_file_checksum --file=$install_dir/.htconfig.php ynh_store_file_checksum $install_dir/.htconfig.php
chmod 600 "$install_dir/.htconfig.php" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/.htconfig.php"
chown $app:$app "$install_dir/.htconfig.php" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/.htconfig.php"
ynh_exec_as $app touch $data_dir/extra_conf.php ynh_exec_as_app touch $data_dir/extra_conf.php
#================================================= #=================================================
# SET CRON JOBS # SET CRON JOBS
#================================================= #=================================================
ynh_script_progression --message="Setuping cron job..." --weight=1 ynh_script_progression "Setuping cron job..."
# Set up cron job # Set up cron job
ynh_add_config --template="../conf/cronjobs" --destination="/etc/cron.d/$app" ynh_config_add --template="cronjobs" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 644 "/etc/cron.d/$app"
# Add daily update script # Add daily update script
ynh_add_config --template="../conf/daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh" ynh_config_add --template="daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh"
chown root: "/home/yunohost.app/$app/daily-update.sh" chown root: "/home/yunohost.app/$app/daily-update.sh"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Configuring log rotation..." --weight=1 ynh_script_progression "Configuring log rotation..."
# Use logrotate to manage application logfile(s) # Use logrotate to manage application logfile(s)
ynh_use_logrotate "$install_dir/php.log" ynh_config_add_logrotate "$install_dir/php.log"
#================================================= #=================================================
# SETUP FAIL2BAN # SETUP FAIL2BAN
#================================================= #=================================================
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 ynh_script_progression "Configuring Fail2Ban..."
# Create a dedicated Fail2Ban config # Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$" --max_retry="5" ynh_config_add_fail2ban --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Installation of $app completed" --last ynh_script_progression "Installation of $app completed"

View file

@ -1,39 +1,33 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# REMOVE NGINX CONFIGURATION # REMOVE NGINX CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 ynh_script_progression "Removing system configurations related to $app..."
# Remove the dedicated NGINX config # Remove the dedicated NGINX config
ynh_remove_nginx_config ynh_config_remove_nginx
# Remove the dedicated PHP-FPM config # Remove the dedicated PHP-FPM config
ynh_remove_fpm_config ynh_config_remove_phpfpm
# Remove the app-specific logrotate config # Remove the app-specific logrotate config
ynh_remove_logrotate ynh_config_remove_logrotate
# Remove the dedicated Fail2Ban config # Remove the dedicated Fail2Ban config
ynh_remove_fail2ban_config ynh_config_remove_fail2ban
# Remove a cron file # Remove a cron file
ynh_secure_remove --file="/etc/cron.d/$app" ynh_safe_rm "/etc/cron.d/$app"
# Remove daily updates logfile # Remove daily updates logfile
ynh_secure_remove --file="$data_dir/daily-updates.log" ynh_safe_rm "$data_dir/daily-updates.log"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Removal of $app completed" --last ynh_script_progression "Removal of $app completed"

View file

@ -1,11 +1,5 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts # Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
@ -13,58 +7,55 @@ source /usr/share/yunohost/helpers
#================================================= #=================================================
# RESTORE THE APP MAIN DIR # RESTORE THE APP MAIN DIR
#================================================= #=================================================
ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_script_progression "Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir" ynh_restore "$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"
#================================================= #=================================================
# RESTORE THE DATABASE # RESTORE THE DATABASE
#================================================= #=================================================
ynh_script_progression --message="Restoring MySQL database..." --weight=1 ynh_script_progression "Restoring MySQL 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;" <<< "ALTER DATABASE $db_name CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
ynh_mysql_execute_file_as_root --file="./db.sql" --database=$db_name ynh_mysql_db_shell < "./db.sql""
#================================================= #=================================================
# RESTORE FAIL2BAN CONFIGURATION # RESTORE FAIL2BAN CONFIGURATION
#================================================= #=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 ynh_script_progression "Restoring the Fail2Ban configuration..."
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" ynh_restore "/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_restore "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban ynh_systemctl --action=restart --service=fail2ban
#================================================= #=================================================
# RESTORE CRON JOBS # RESTORE CRON JOBS
#================================================= #=================================================
ynh_restore_file --origin_path="/etc/cron.d/$app" ynh_restore "/etc/cron.d/$app"
ynh_restore_file --origin_path="$data_dir" ynh_restore "$data_dir"
#================================================= #=================================================
# RESTORE LOGROTATE # RESTORE LOGROTATE
#================================================= #=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app" ynh_restore "/etc/logrotate.d/$app"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# RELOAD NGINX AND PHP-FPM # RELOAD NGINX AND PHP-FPM
#================================================= #=================================================
ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." --weight=1 ynh_script_progression "Reloading NGINX web server and PHP-FPM..."
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf" ynh_restore "/etc/php/$php_version/fpm/pool.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload ynh_systemctl --service=php$php_version-fpm --action=reload
ynh_systemd_action --service_name=nginx --action=reload ynh_systemctl --service=nginx --action=reload
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Restoration completed for $app" --last ynh_script_progression "Restoration completed for $app"

View file

@ -1,64 +1,50 @@
#!/bin/bash #!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh source _common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
#================================================= #=================================================
# LOAD SETTINGS # LOAD SETTINGS
#================================================= #=================================================
ynh_script_progression --message="Loading settings..." --weight=1 ynh_script_progression "Loading settings..."
email=$(ynh_user_get_info --username=$admin --key=mail) email=$(ynh_user_get_info --username=$admin --key=mail)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#================================================= #=================================================
# ENSURE DOWNWARD COMPATIBILITY # ENSURE DOWNWARD COMPATIBILITY
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression "Ensuring downward compatibility..."
# If fpm_footprint doesn't exist, create it # If fpm_footprint doesn't exist, create it
if [ -z "$fpm_footprint" ]; then #REMOVEME? Everything about fpm_footprint is removed in helpers2.1... | if [ -z "$fpm_footprint" ]; then
fpm_footprint=low fpm_footprint=low
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 fi
# If fpm_free_footprint doesn't exist, create it # If fpm_free_footprint doesn't exist, create it
if [ -z "$fpm_free_footprint" ]; then #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | if [ -z "$fpm_free_footprint" ]; then
fpm_free_footprint=0 fpm_free_footprint=0
ynh_app_setting_set --app=$app --key=fpm_free_footprint --value=$fpm_free_footprint #REMOVEME? Everything about fpm_free_footprint is removed in helpers2.1... | ynh_app_setting_set --key=fpm_free_footprint --value=$fpm_free_footprint
fi fi
# If fpm_usage doesn't exist, create it # If fpm_usage doesn't exist, create it
if [ -z "$fpm_usage" ]; then #REMOVEME? Everything about fpm_usage is removed in helpers2.1... | if [ -z "$fpm_usage" ]; then
fpm_usage=low fpm_usage=low
ynh_app_setting_set --app=$app --key=fpm_usage --value=$fpm_usage #REMOVEME? Everything about fpm_usage is removed in helpers2.1... | ynh_app_setting_set --key=fpm_usage --value=$fpm_usage
fi fi
# Make sure that git_branch_mode exists with relevant value # Make sure that git_branch_mode exists with relevant value
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" if echo $git_branch_mode_status | grep -q "release"
then then
git_branch_mode="0" 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" elif echo $git_branch_mode_status | grep -q "dev"
then then
git_branch_mode="1" 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 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 exit 0
fi fi
@ -66,9 +52,10 @@ fi
# DOWNLOAD, CHECK AND UNPACK SOURCE # 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 then
ynh_script_progression --message="Upgrading source files..." --weight=1 ynh_script_progression "Upgrading source files..."
# First we save what we need to keep # First we save what we need to keep
mv $install_dir/store $data_dir/ mv $install_dir/store $data_dir/
@ -76,111 +63,107 @@ then
mv $install_dir/php.log $data_dir/ mv $install_dir/php.log $data_dir/
# Then we remove the previous install # Then we remove the previous install
ynh_secure_remove $install_dir ynh_safe_rm $install_dir
# We make the install cloning the repo # We make the install cloning the repo
mkdir -p "$install_dir" 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"
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 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" ] if [[ -n $git_branch_mode ]] && [ "$git_branch_mode" -eq "1" ]
then then
ynh_print_info "Switching to \"dev\" branch" ynh_print_info "Switching to \"dev\" branch"
(cd "$install_dir" && ynh_exec_as $app git checkout dev) (cd "$install_dir" && ynh_exec_as_app git checkout dev)
fi fi
# We restore what we previously saved # We restore what we previously saved
mv $data_dir/store $install_dir/ mv $data_dir/store $install_dir/
mv $data_dir/cache $install_dir/ mv $data_dir/cache $install_dir/
mv $data_dir/php.log $install_dir/ mv $data_dir/php.log $install_dir/
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"
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"
chmod -R 775 $install_dir/store $install_dir/cache chmod -R 775 $install_dir/store $install_dir/cache
fi fi
#================================================= #=================================================
# PHP-FPM CONFIGURATION # 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 # 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 # Create a dedicated NGINX config
ynh_add_nginx_config ynh_config_add_nginx
#================================================= #=================================================
# COMPOSER # COMPOSER
#================================================= #=================================================
ynh_script_progression --message="Pulling in external libraries with Composer..." ynh_script_progression "Pulling in external libraries with Composer..."
ynh_install_composer ynh_composer_install
chown -R $app:www-data "$install_dir" 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 # ADDONS
#================================================= #=================================================
ynh_script_progression --message="Installing addons..." ynh_script_progression "Installing addons..."
pushd $install_dir pushd $install_dir
ynh_exec_as $app git config pull.rebase false 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 util/add_addon_repo https://codeberg.org/streams/streams-addons.git zaddons
cd /var/www/$app/extend/addon/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 popd
#=================================================
# SPECIFIC UPGRADE
#================================================= #=================================================
# UPDATE A CONFIG FILE # UPDATE A CONFIG FILE
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=1 ynh_script_progression "Updating configuration..."
timezone=$(</etc/timezone) timezone=$(</etc/timezone)
max_imported_follow=10 max_imported_follow=10
ynh_add_config --template="../conf/htconfig.sample.php" --destination="$install_dir/.htconfig.php" ynh_config_add --template="htconfig.sample.php" --destination="$install_dir/.htconfig.php"
chmod 600 "$install_dir/.htconfig.php" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 600 "$install_dir/.htconfig.php"
chown $app:$app "$install_dir/.htconfig.php" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/.htconfig.php"
if [ ! -f $data_dir/extra_conf.php ] if [ ! -f $data_dir/extra_conf.php ]
then then
ynh_exec_as $app touch $data_dir/extra_conf.php ynh_exec_as_app touch $data_dir/extra_conf.php
fi fi
#================================================= #=================================================
# UPGRADE CRON JOB # UPGRADE CRON JOB
#================================================= #=================================================
ynh_script_progression --message="Setuping cron job..." --weight=1 ynh_script_progression "Setuping cron job..."
# Set up cron job # Set up cron job
ynh_add_config --template="../conf/cronjobs" --destination="/etc/cron.d/$app" ynh_config_add --template="cronjobs" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown root: "/etc/cron.d/$app"
chmod 644 "/etc/cron.d/$app" #REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 644 "/etc/cron.d/$app"
# Add daily update script # Add daily update script
ynh_add_config --template="../conf/daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh" ynh_config_add --template="daily-update.sh" --destination="/home/yunohost.app/$app/daily-update.sh"
chown root: "/home/yunohost.app/$app/daily-update.sh" chown root: "/home/yunohost.app/$app/daily-update.sh"
#=================================================
# GENERIC FINALIZATION
#================================================= #=================================================
# SETUP LOGROTATE # SETUP LOGROTATE
#================================================= #=================================================
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 ynh_script_progression "Upgrading logrotate configuration..."
# Use logrotate to manage app-specific logfile(s) # Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate "$install_dir/php.log" ynh_config_add_logrotate "$install_dir/php.log"
# Create a dedicated Fail2Ban config # Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$" --max_retry="5" ynh_config_add_fail2ban --logpath="$install_dir/php.log" --failregex="^.*auth\.php.*failed login attempt.*from IP <HOST>.*$"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression "Upgrade of $app completed"