1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/funkwhale_ynh.git synced 2024-09-03 18:36:24 +02:00

Add change_url script

This commit is contained in:
ericgaspar 2020-12-05 08:53:58 +01:00
parent 56dfe7f117
commit 0f4995de8e
No known key found for this signature in database
GPG key ID: 574F281483054D44
7 changed files with 227 additions and 83 deletions

View file

@ -15,7 +15,6 @@ pkg_dependencies="build-essential curl ffmpeg \
# PERSONAL HELPERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================

View file

@ -27,9 +27,9 @@ ynh_print_info --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
domain=$(ynh_app_setting_get --app="$app" --key=domain)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
@ -40,7 +40,7 @@ ynh_print_info --message="Declaring files to be backed up..."
# BACKUP THE APP MAIN DIR
#=================================================
backup_core_only=$(ynh_app_setting_get --app="$app" --key=backup_core_only)
backup_core_only=$(ynh_app_setting_get --app=$app --key=backup_core_only)
# If backup_core_only have any value in the settings.yml file, do not backup the data directory
if [ -z "$backup_core_only" ]
then
@ -62,7 +62,7 @@ ynh_backup --src_path="/etc/nginx/conf.d/$domain.conf"
#=================================================
ynh_print_info --message="Backing up the PostgreSQL database..."
ynh_psql_dump_db --database="$db_name" > db.sql
ynh_psql_dump_db --database=$db_name > db.sql
#=================================================
# SPECIFIC BACKUP

145
scripts/change_url Normal file
View file

@ -0,0 +1,145 @@
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
old_domain=$YNH_APP_OLD_DOMAIN
old_path=$YNH_APP_OLD_PATH
new_domain=$YNH_APP_NEW_DOMAIN
new_path=$YNH_APP_NEW_PATH
app=$YNH_APP_INSTANCE_NAME
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --time --weight=1
# Needed for helper "ynh_add_nginx_config"
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
# Add settings here as needed by your application
#db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#db_user=$db_name
#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." --time --weight=1
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Remove the new domain config file, the remove script won't do it as it doesn't know yet its location.
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
# Restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# CHECK WHICH PARTS SHOULD BE CHANGED
#=================================================
change_domain=0
if [ "$old_domain" != "$new_domain" ]
then
change_domain=1
fi
change_path=0
if [ "$old_path" != "$new_path" ]
then
change_path=1
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# MODIFY URL IN NGINX CONF
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --time --weight=1
nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the NGINX config file
if [ $change_path -eq 1 ]
then
# Make a backup of the original NGINX config file if modified
ynh_backup_if_checksum_is_different --file="$nginx_conf_path"
# Set global variables for NGINX helper
domain="$old_domain"
path_url="$new_path"
# Create a dedicated NGINX config
ynh_add_nginx_config
fi
# Change the domain for NGINX
if [ $change_domain -eq 1 ]
then
# Delete file checksum for the old conf file location
ynh_delete_file_checksum --file="$nginx_conf_path"
mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf
# Store file checksum for the new config file location
ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
fi
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_systemd_action --action="start" --service_name="${app}-beat"
ynh_systemd_action --action="start" --service_name="${app}-server"
ynh_systemd_action --action="start" --service_name="${app}-worker"
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$new_domain-access.log" --failregex="<HOST>.* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5
#=================================================
# SETUP FAIL2BAN
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..."
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$new_domain-access.log" --failregex="<HOST>.* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Change of URL completed for $app" --last

View file

@ -39,17 +39,17 @@ final_path="/var/www/$app"
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
# Register (book) web path
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
ynh_webpath_register --app=$app --domain="$domain" --path_url="$path_url"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
ynh_app_setting_set --app="$app" --key=path --value="$path_url"
ynh_app_setting_set --app="$app" --key=is_public --value="$is_public"
ynh_app_setting_set --app="$app" --key=admin --value="$admin"
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
ynh_app_setting_set --app=$app --key=is_public --value=$is_public
ynh_app_setting_set --app=$app --key=admin --value=$admin
#=================================================
# STANDARD MODIFICATIONS
@ -61,7 +61,7 @@ ynh_script_progression --message="Configuring firewall..."
# Find a free port
port=$(ynh_find_port --port=5000)
# Open this port
ynh_app_setting_set --app="$app" --key=port --value="$port"
ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# INSTALL DEPENDENCIES
@ -77,21 +77,21 @@ ynh_script_progression --message="Creating a PostgreSQL database..."
ynh_psql_test_if_first_run
db_name=$(ynh_sanitize_dbid "$app")
db_user="$db_name"
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
db_pwd=$(ynh_string_random)
ynh_app_setting_set --app="$app" --key=db_name --value="$db_name"
ynh_app_setting_set --app="$app" --key=psqlpwd --value="$db_pwd"
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
ynh_app_setting_set --app=$app --key=psqlpwd --value=$db_pwd
# Initialize database and store postgres password for upgrade
ynh_psql_setup_db --db_name="$db_name" --db_user="$db_user" --db_pwd="$db_pwd"
ynh_psql_setup_db --db_name=$db_name --db_user=$db_user --db_pwd=$db_pwd
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
ynh_app_setting_set --app="$app" --key=final_path --value="$final_path"
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path/code"
ynh_setup_source --dest_dir="$final_path/code" --source_id="app-frontend"
@ -104,9 +104,9 @@ ynh_setup_source --dest_dir="$final_path/code" --source_id="app-frontend"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring nginx web server..."
ynh_script_progression --message="Configuring NGINX web server..."
# Create a dedicated nginx config
# Create a dedicated NGINX config
ynh_add_nginx_config
#=================================================
@ -115,7 +115,7 @@ ynh_add_nginx_config
ynh_script_progression --message="Configuring system user..."
# Create a system user
ynh_system_user_create --username="$app" --home_dir="$final_path"
ynh_system_user_create --username=$app --home_dir=$final_path
#=================================================
# SPECIFIC SETUP
@ -126,12 +126,12 @@ ynh_system_user_create --username="$app" --home_dir="$final_path"
virtualenv -p python3 "$final_path/code/virtualenv"
(
set +o nounset
source "${final_path}/code/virtualenv/bin/activate"
source "$final_path/code/virtualenv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install --upgrade setuptools
pip install wheel
pip install -r "${final_path}/code/api/requirements.txt"
pip install -r "$final_path/code/api/requirements.txt"
)
#=================================================
@ -145,8 +145,8 @@ cp ../conf/env.prod "$configfile"
key=$(ynh_string_random)
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app="$app" --key=key --value="$key"
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_app_setting_set --app=$app --key=key --value=$key
ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile"
@ -164,7 +164,7 @@ ynh_replace_string --match_string="__KEY__" --replace_string="$key"
admin_mail=$(ynh_user_get_info --username="$admin" --key="mail")
(
set +o nounset
source "${final_path}/code/virtualenv/bin/activate"
source "$final_path/code/virtualenv/bin/activate"
set -o nounset
cd "$final_path/code/"
@ -202,11 +202,11 @@ ynh_store_file_checksum --file="$configfile"
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R "$app": "$final_path"
chown -R $app: "$final_path"
chmod -R 755 "$final_path/code/front/dist/"
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
chown -R $app: "/var/log/$app"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
@ -230,7 +230,7 @@ ynh_systemd_action --action="start" --service_name="${app}-worker"
#=================================================
ynh_script_progression --message="Configuring Fail2Ban..."
# Create a dedicated fail2ban config
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failregex="<HOST>.* \"POST /api/v1/token/ HTTP/1.1\" 400 68.*$" --max_retry=5
#=================================================

View file

@ -16,12 +16,12 @@ ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
port=$(ynh_app_setting_get --app="$app" --key=port)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
db_user="$db_name"
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
domain=$(ynh_app_setting_get --app=$app --key=domain)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
#=================================================
# STANDARD REMOVE
@ -70,7 +70,7 @@ ynh_secure_remove --file="/etc/systemd/system/$app.target"
ynh_script_progression --message="Removing the PostgreSQL database"
# Remove a database if it exists, along with the associated user
ynh_psql_remove_db --db_name="$db_name" --db_user="$db_user"
ynh_psql_remove_db --db_name=$db_name --db_user=$db_user
#=================================================
# REMOVE THE REDIS DATABASE
@ -78,7 +78,7 @@ ynh_psql_remove_db --db_name="$db_name" --db_user="$db_user"
ynh_script_progression --message="Removing the Redis database"
# Remove a database if it exists, along with the associated user
ynh_redis_remove_db "$redis_db"
ynh_redis_remove_db $redis_db
#=================================================
# REMOVE DEPENDENCIES
@ -121,7 +121,7 @@ ynh_remove_fail2ban_config
ynh_script_progression --message="Removing the dedicated system user"
# Delete a system user
ynh_system_user_delete --username="$app"
ynh_system_user_delete --username=$app
#=================================================
# END OF SCRIPT

View file

@ -27,12 +27,12 @@ ynh_script_progression --message="Loading settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
db_user="$db_name"
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#=================================================
# CHECK IF THE APP CAN BE RESTORED
@ -58,7 +58,7 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.conf"
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
backup_core_only=$(ynh_app_setting_get --app="$app" --key=backup_core_only)
backup_core_only=$(ynh_app_setting_get --app=$app --key=backup_core_only)
# If backup_core_only have any value, then restore only code
if [ -z "$backup_core_only" ]
@ -69,9 +69,9 @@ else
fi
# Remove the option backup_core_only if it's in the settings.yml file
ynh_app_setting_delete --app="$app" --key=backup_core_only
ynh_app_setting_delete --app=$app --key=backup_core_only
code_migration=$(ynh_app_setting_get --app="$app" --key=code_migration)
code_migration=$(ynh_app_setting_get --app=$app --key=code_migration)
# make sure we revert the last code organization
if [ "$code_migration" -eq 1 ]
@ -89,18 +89,18 @@ fi
ynh_script_progression --message="Recreating the dedicated system user..."
# Create the dedicated user (if not existing)
ynh_system_user_create --username="$app" --home_dir="$final_path"
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R "$app": "$final_path"
chown -R $app: "$final_path"
chmod -R 755 "$final_path/code/front/dist/"
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
chown -R $app: "/var/log/$app"
#=================================================
# SPECIFIC RESTORATION
@ -118,8 +118,8 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Restoring the PostgreSQL database..."
ynh_psql_test_if_first_run
ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd"
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_psql_execute_file_as_root --file=./db.sql --database=$db_name
#=================================================
# RESTORE SYSTEMD

View file

@ -16,16 +16,16 @@ ynh_script_progression --message="Loading installation settings..."
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app="$app" --key=domain)
path_url=$(ynh_app_setting_get --app="$app" --key=path)
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
final_path=$(ynh_app_setting_get --app="$app" --key=final_path)
db_name=$(ynh_app_setting_get --app="$app" --key=db_name)
db_user="$db_name"
port=$(ynh_app_setting_get --app="$app" --key=port)
db_pwd=$(ynh_app_setting_get --app="$app" --key=psqlpwd)
redis_db=$(ynh_app_setting_get --app="$app" --key=redis_db)
code_migration=$(ynh_app_setting_get --app="$app" --key=code_migration)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
port=$(ynh_app_setting_get --app=$app --key=port)
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
code_migration=$(ynh_app_setting_get --app=$app --key=code_migration)
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
@ -33,9 +33,9 @@ code_migration=$(ynh_app_setting_get --app="$app" --key=code_migration)
ynh_script_progression --message="Ensuring downward compatibility..."
# If redis_db doesn't exist, create it
if [ -z "$redis_db" ]; then
if [ -z $redis_db ]; then
redis_db=0
ynh_app_setting_set --app="$app" --key=redis_db --value="$redis_db"
ynh_app_setting_set --app=$app --key=redis_db --value=$redis_db
fi
# make sure we have the last code organization
@ -58,7 +58,7 @@ fi
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
# Inform the backup/restore process that it should not save the data directory
ynh_app_setting_set --app="$app" --key=backup_core_only --value=1
ynh_app_setting_set --app=$app --key=backup_core_only --value=1
# Backup the current version of the app
ynh_backup_before_upgrade
@ -87,9 +87,9 @@ fi
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --action="stop" --service_name="${app}-beat"
ynh_systemd_action --action="stop" --service_name="${app}-server"
ynh_systemd_action --action="stop" --service_name="${app}-worker"
ynh_systemd_action --action=stop --service_name="${app}-beat"
ynh_systemd_action --action=stop --service_name="${app}-server"
ynh_systemd_action --action=stop --service_name="${app}-worker"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
@ -127,7 +127,7 @@ ynh_install_app_dependencies $pkg_dependencies
ynh_script_progression --message="Making sure dedicated system user exists..."
# Create a dedicated user (if not existing)
ynh_system_user_create --username="$app" --home_dir="$final_path"
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# SPECIFIC UPGRADE
@ -139,12 +139,12 @@ ynh_secure_remove --file="$final_path/code/virtualenv"
virtualenv -p python3 "$final_path/code/virtualenv"
(
set +o nounset
source "${final_path}/code/virtualenv/bin/activate"
source "$final_path/code/virtualenv/bin/activate"
set -o nounset
pip install --upgrade pip
pip install --upgrade setuptools
pip install wheel
pip install -r "${final_path}/code/api/requirements.txt"
pip install -r "$final_path/code/api/requirements.txt"
# https://code.eliotberriot.com/funkwhale/funkwhale/tags/0.16
pip uninstall django-cacheops --yes
@ -162,14 +162,14 @@ key=$(ynh_string_random)
ynh_app_setting_set --app="$app" --key=key --value="$key"
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$configfile"
ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$configfile"
ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$configfile"
ynh_replace_string --match_string="__DBNAME__" --replace_string="$app" --target_file="$configfile"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile"
ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile"
ynh_replace_string --match_string="__REDIS_DB__" --replace_string="$redis_db" --target_file="$configfile"
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$configfile"
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$configfile"
ynh_replace_string --match_string="__DBUSER__" --replace_string="$db_name" --target_file="$configfile"
ynh_replace_string --match_string="__DBPWD__" --replace_string="$db_pwd" --target_file="$configfile"
ynh_replace_string --match_string="__DBNAME__" --replace_string="$app" --target_file="$configfile"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$configfile"
ynh_replace_string --match_string="__KEY__" --replace_string="$key" --target_file="$configfile"
#=================================================
# MIGRATE
@ -177,7 +177,7 @@ ynh_replace_string --match_string="__KEY__" --replace_string="$key"
(
set +o nounset
source "${final_path}/code/virtualenv/bin/activate"
source "$final_path/code/virtualenv/bin/activate"
set -o nounset
cd "$final_path/code"
@ -240,11 +240,11 @@ ynh_add_fail2ban_config --logpath="/var/log/nginx/$domain-access.log" --failrege
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R "$app": "$final_path"
chown -R $app: "$final_path"
chmod -R 755 "$final_path/code/front/dist/"
mkdir -p "/var/log/$app"
chown -R "$app": "/var/log/$app"
chown -R $app: "/var/log/$app"
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
@ -274,7 +274,7 @@ ynh_systemd_action --service_name=nginx --action=reload
# REMOVE CODE MIGRATION FLAG
#=================================================
ynh_app_setting_set --app="$app" --key=code_migration --value=2
ynh_app_setting_set --app=$app --key=code_migration --value=2
#=================================================
# END OF SCRIPT