Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[autopatch] Automatic patch attempt for helpers 2.1 #70

Open
wants to merge 1 commit into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ code = "https://github.com/spiral-project/ihatemoney"
demo = "https://ihatemoney.org/demo/"

[integration]
yunohost = ">= 11.1.21"
yunohost = ">= 11.2.18"
helpers_version = "2.1"
architectures = "all"
multi_instance = true
ldap = false
Expand Down Expand Up @@ -59,6 +60,7 @@ ram.runtime = "100M"

[resources.install_dir]
group = "www-data:r-x"
group = "www-data:r-x"

[resources.permissions]
main.url = "/"
Expand Down
15 changes: 1 addition & 14 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

pip_dependencies=(
Expand All @@ -10,11 +10,6 @@ pip_dependencies=(
'PyMySQL>=0.9,<1.1'
)


#=================================================
# PERSONAL HELPERS
#=================================================

wait_gunicorn_start() {
# line_match isn't enough because ihatemoney may stop if database upgrades
for _ in {1..20}; do
Expand Down Expand Up @@ -60,11 +55,3 @@ _hash_password() {
password=$1
python3 -c "$HASH_PASSWORD_PYTHON" "$password"
}

#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
25 changes: 8 additions & 17 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
#!/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"

#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================

ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.service"

#=================================================
# BACKUP LOG
#=================================================

ynh_backup --src_path="/var/log/$app" --is_big=1
ynh_backup "/var/log/$app"

#=================================================
# BACKUP THE MYSQL DATABASE
#=================================================
ynh_print_info --message="Backing up the MySQL database..."
ynh_print_info "Backing up 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)."
26 changes: 8 additions & 18 deletions scripts/change_url
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
#!/bin/bash

#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
ynh_script_progression "Stopping $app's systemd service..."

ynh_systemd_action --service_name=$app --action="stop"
ynh_systemctl --service=$app --action="stop"

#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_script_progression "Updating NGINX web server configuration..."

python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# SPECIFIC MODIFICATIONS
Expand All @@ -39,24 +31,22 @@ domain="$new_domain"
# Allows to comment some config lines if not using sub path
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"

ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"
ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"

chmod 640 "$install_dir/ihatemoney.cfg"
chown "$app:$app" "$install_dir/ihatemoney.cfg"

#=================================================
# GENERIC FINALISATION
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=5
ynh_script_progression "Starting $app's systemd service..."

# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start"
ynh_systemctl --service="$app" --action="start"
wait_gunicorn_start

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
41 changes: 16 additions & 25 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

Expand All @@ -14,72 +8,69 @@ source /usr/share/yunohost/helpers
#=================================================
# BUILD VENV
#=================================================
ynh_script_progression --message="Building venv..." --weight=6
ynh_script_progression "Building venv..."

__ynh_python_venv_setup --venv_dir="$install_dir/venv" --packages "${pip_dependencies[*]}"
python_venv_site_packages=$(__ynh_python_venv_get_site_packages_dir -d "$install_dir/venv")

#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
ynh_script_progression "Configuring NGINX web server..."

# Create a dedicated NGINX config
## Needs $python_venv_site_packages
ynh_add_nginx_config
ynh_config_add_nginx

#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
ynh_script_progression "Adding $app's configuration..."

# Secret key for cookies encryption.
secret_key=$(ynh_string_random --length=32)
ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key"
ynh_app_setting_set --key=secret_key --value="$secret_key"

hashed_password=$(_hash_password "$password")
ynh_app_setting_set --app="$app" --key=hashed_password --value="$hashed_password"
ynh_app_setting_set --key=hashed_password --value="$hashed_password"

# Allows to comment some config lines if not using sub path
sub_path_only="$(if [[ "$path" == "/" ]]; then echo '# ' ; else echo ''; fi)"

ynh_add_config --template="../conf/gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_add_config --template="../conf/ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"

chown -R "$app:www-data" "$install_dir"
ynh_config_add --template="gunicorn.conf.py" --destination="$install_dir/gunicorn.conf.py"
ynh_config_add --template="ihatemoney.cfg" --destination="$install_dir/ihatemoney.cfg"

#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"
# Configure log directory
mkdir -p "/var/log/$app"
chown -R "$app:$app" "/var/log/$app"
#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "/var/log/$app"

#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1
ynh_script_progression "Configuring $app's systemd service..."

# Create a dedicated systemd config
ynh_add_systemd_config
ynh_config_add_systemd

#=================================================
# GENERIC FINALIZATION
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
ynh_script_progression "Integrating service in YunoHost..."

yunohost service add "$app" --description="$app daemon for IHateMoney" --log=systemd

#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=1
ynh_script_progression "Starting $app's systemd service..."

# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --line_match="Listening at"
ynh_systemctl --service="$app" --action="start" --wait_until="Listening at"
wait_gunicorn_start

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
20 changes: 7 additions & 13 deletions scripts/remove
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

Expand All @@ -14,35 +8,35 @@ source /usr/share/yunohost/helpers
#=================================================
# REMOVE SERVICE INTEGRATION IN YUNOHOST
#=================================================
ynh_script_progression --message="Removing $app service integration..." --weight=1
ynh_script_progression "Removing $app service integration..."

yunohost service remove "$app"

#=================================================
# STOP AND REMOVE SERVICE
#=================================================
ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1
ynh_script_progression "Stopping and removing the systemd service..."

ynh_remove_systemd_config
ynh_config_remove_systemd

#=================================================
# REMOVE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Removing NGINX web server configuration..." --weight=1
ynh_script_progression "Removing NGINX web server configuration..."

ynh_remove_nginx_config
ynh_config_remove_nginx

#=================================================
# SPECIFIC REMOVE
#=================================================
# REMOVE VARIOUS FILES
#=================================================
ynh_script_progression --message="Removing various files..." --weight=1
ynh_script_progression "Removing various files..."

# Remove the log files

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"
Loading