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

Helpers 2.1 #83

Open
wants to merge 3 commits 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.sw[op]
.DS_Store
3 changes: 2 additions & 1 deletion manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ admindoc = "https://gogs.io/docs"
code = "https://github.com/gogs/gogs"

[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.30"
helpers_version = "2.1"
architectures = "all"
multi_instance = true

Expand Down
2 changes: 1 addition & 1 deletion scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================
23 changes: 10 additions & 13 deletions scripts/backup
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,41 @@
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 DATA DIR
#=================================================

ynh_backup --src_path="$data_dir" --is_big
ynh_backup "$data_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"

ynh_backup --src_path="/etc/logrotate.d/$app"
ynh_backup "/etc/logrotate.d/$app"

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

ynh_backup --src_path="/var/log/$app"
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)."
16 changes: 8 additions & 8 deletions scripts/change_url
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_script_progression "Stopping $app's systemd service..."

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

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

ynh_change_url_nginx_config
ynh_config_change_url_nginx

#=================================================
# SPECIFIC MODIFICATIONS
Expand All @@ -30,20 +30,20 @@ fi

domain=$new_domain

ynh_add_config --template="../conf/app.ini" --destination="$install_dir/custom/conf/app.ini"
ynh_config_add --template="app.ini" --destination="$install_dir/custom/conf/app.ini"

chmod 400 "$install_dir/custom/conf/app.ini"
chown $app:$app "$install_dir/custom/conf/app.ini"

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

ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
ynh_systemctl --service=$app --action="start" --log_path="systemd"

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

ynh_script_progression --message="Change of URL completed for $app" --last
ynh_script_progression "Change of URL completed for $app"
33 changes: 12 additions & 21 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,21 @@ source /usr/share/yunohost/helpers
#=================================================

key=$(ynh_string_random)
ynh_app_setting_set --app=$app --key=key --value=$key
ynh_app_setting_set --key=key --value=$key

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
ynh_script_progression "Setting up source files..."

ynh_setup_source --dest_dir=$install_dir

mkdir -p "$install_dir/custom/conf/auth.d"

chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"

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

if [ "$path" = "/" ]
then
Expand All @@ -34,38 +31,32 @@ else
url="$domain${path%/}"
fi

ynh_add_config --template="app.ini" --destination="$install_dir/custom/conf/app.ini"

chmod 400 "$install_dir/custom/conf/app.ini"
chown $app:$app "$install_dir/custom/conf/app.ini"
ynh_config_add --template="app.ini" --destination="$install_dir/custom/conf/app.ini"

ynh_add_config --template="ldap.conf" --destination="$install_dir/custom/conf/auth.d/ldap.conf"
ynh_config_add --template="ldap.conf" --destination="$install_dir/custom/conf/auth.d/ldap.conf"

#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..." --weight=1

ynh_add_systemd_config
ynh_script_progression "Configuring $app's systemd service..."

ynh_add_nginx_config
ynh_config_add_systemd

ynh_use_logrotate
ynh_config_add_nginx

chown -R $app:$app "/var/log/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
ynh_config_add_logrotate

yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"

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

ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
ynh_systemctl --service=$app --action="start" --log_path="systemd"

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

ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
12 changes: 6 additions & 6 deletions scripts/remove
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ source /usr/share/yunohost/helpers
#=================================================
# REMOVE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Removing system configurations related to $app..." --weight=1
ynh_script_progression "Removing system configurations related to $app..."

if ynh_exec_warn_less yunohost service status $app >/dev/null; then
if ynh_hide_warnings yunohost service status $app >/dev/null; then
yunohost service remove $app
fi

ynh_remove_systemd_config
ynh_config_remove_systemd

ynh_remove_logrotate
ynh_config_remove_logrotate

ynh_remove_nginx_config
ynh_config_remove_nginx

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

ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"
37 changes: 15 additions & 22 deletions scripts/restore
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,51 @@ source /usr/share/yunohost/helpers
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring $app main directory..." --weight=10
ynh_script_progression "Restoring $app main directory..."

ynh_restore_file --origin_path="$install_dir"

chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
ynh_restore "$install_dir"

#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring the data directory..." --weight=1

ynh_restore_file --origin_path="$data_dir" --not_mandatory
ynh_script_progression "Restoring the data directory..."

chown -R $app:www-data "$data_dir"
ynh_restore "$data_dir"

#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=3
ynh_script_progression "Restoring the MySQL database..."

ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
ynh_mysql_db_shell < ./db.sql

#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_script_progression --message="Restoring the systemd configuration..." --weight=5
ynh_script_progression "Restoring $app's systemd service..."

ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"

ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
ynh_restore "/etc/systemd/system/$app.service"
systemctl enable $app.service --quiet

ynh_restore_file --origin_path="/etc/logrotate.d/$app"
ynh_restore "/etc/logrotate.d/$app"

ynh_restore_file --origin_path="/var/log/$app"
chown -R $app:$app "/var/log/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
ynh_restore "/var/log/$app"

yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"

#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
ynh_script_progression "Reloading NGINX web server and $app's service..."

ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
ynh_systemctl --service=$app --action="start" --log_path="systemd"

ynh_systemd_action --service_name=nginx --action=reload
ynh_systemctl --service=nginx --action=reload

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

ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"
26 changes: 10 additions & 16 deletions scripts/upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,39 @@ source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=2
ynh_script_progression "Stopping $app's systemd service..."

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

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
ynh_script_progression "Setting up source files..."

ynh_setup_source --dest_dir=$install_dir --keep="custom/conf/app.ini custom/conf/auth.d/ldap.conf"

chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"

#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1

ynh_add_systemd_config
ynh_script_progression "Restoring system configurations related to $app..."

ynh_add_nginx_config
ynh_config_add_systemd

ynh_use_logrotate
ynh_config_add_nginx

chown -R $app:$app "/var/log/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
ynh_config_add_logrotate

yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"

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

ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
ynh_systemctl --service=$app --action="start" --log_path="systemd"

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

ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"