2022-02-27 16:11:02 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2022-02-28 02:36:15 +01:00
|
|
|
source ynh_redis
|
|
|
|
source ynh_uwsgi_service__2
|
2022-02-27 16:11:02 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
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)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
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)
|
|
|
|
redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
|
|
|
|
secret_key=$(ynh_app_setting_get --app=$app --key=secret_key)
|
|
|
|
salt_email=$(ynh_app_setting_get --app=$app --key=salt_email)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
|
2022-02-28 02:36:15 +01:00
|
|
|
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_ci --action="stop" --log_path="systemd"
|
|
|
|
#ynh_systemd_action --service_name=${app}_ev_server --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_gitolite_worker --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_loadjson --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_logcom --action="stop" --log_path="systemd"
|
|
|
|
#ynh_systemd_action --service_name=${app}_milters --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_mirror --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_webhook --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name=${app}_worker --action="stop" --log_path="systemd"
|
|
|
|
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="stop" --log_path="systemd"
|
2022-02-27 16:11:02 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
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"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/pagure.cfg.sample" --destination="$final_path/pagure.cfg"
|
|
|
|
|
|
|
|
chmod 400 "$final_path/pagure.cfg"
|
|
|
|
chown $app:$app "$final_path/pagure.cfg"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config --service="${app}_authorized_keys_worker" --template="pagure_authorized_keys_worker.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_ci" --template="pagure_ci.service"
|
|
|
|
#ynh_add_systemd_config --service="${app}_ev_server" --template="pagure_ev_server.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_gitolite_worker" --template="pagure_gitolite_worker.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_loadjson" --template="pagure_loadjson.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_logcom" --template="pagure_logcom.service"
|
|
|
|
#ynh_add_systemd_config --service="${app}_milters" --template="pagure_milters.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_mirror" --template="pagure_mirror.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_webhook" --template="pagure_webhook.service"
|
|
|
|
ynh_add_systemd_config --service="${app}_worker" --template="pagure_worker.service"
|
|
|
|
|
|
|
|
ynh_add_config --template="../conf/pagure.wsgi" --destination="$final_path/pagure.wsgi"
|
|
|
|
ynh_add_uwsgi_service --service="$app" --template="uwsgi.ini"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BUILD APP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Building app..."
|
|
|
|
|
|
|
|
pushd "$final_path"
|
2022-03-02 22:30:39 +01:00
|
|
|
ynh_secure_remove --file="${final_path}/venv"
|
2022-02-27 16:11:02 +01:00
|
|
|
python3 -m venv venv
|
|
|
|
source ./venv/bin/activate
|
|
|
|
pip install --upgrade pip
|
|
|
|
pip install wheel
|
|
|
|
pip install cffi
|
|
|
|
pip install psycopg2
|
|
|
|
pip install pyyaml
|
2022-03-04 08:27:37 +01:00
|
|
|
pip install pygit2
|
2022-02-27 16:11:02 +01:00
|
|
|
pip install -r requirements.txt
|
|
|
|
mkdir -p "${final_path}"/lcl/{repos,remotes,attachments,releases}
|
|
|
|
ynh_add_config --template="../conf/alembic.ini" --destination="$final_path/alembic.ini"
|
2022-02-28 03:42:38 +01:00
|
|
|
PAGURE_CONFIG=${final_path}/pagure.cfg alembic upgrade head 2>&1
|
2022-02-27 16:11:02 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
ynh_replace_string --match_string="validators.Required" --replace_string="validators.DataRequired" --target_file="$final_path/pagure/forms.py"
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
|
|
|
yunohost service add ${app}_authorized_keys_worker
|
|
|
|
yunohost service add ${app}_ci
|
|
|
|
#yunohost service add ${app}_ev_server
|
|
|
|
yunohost service add ${app}_gitolite_worker
|
|
|
|
yunohost service add ${app}_loadjson
|
|
|
|
yunohost service add ${app}_logcom
|
|
|
|
#yunohost service add ${app}_milters
|
|
|
|
yunohost service add ${app}_mirror
|
|
|
|
yunohost service add ${app}_webhook
|
|
|
|
yunohost service add ${app}_worker
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=${app}_authorized_keys_worker --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_ci --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
#ynh_systemd_action --service_name=${app}_ev_server --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_gitolite_worker --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_loadjson --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_logcom --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
#ynh_systemd_action --service_name=${app}_milters --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_mirror --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_webhook --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name=${app}_worker --action="start" --log_path="systemd" --line_match="ready"
|
|
|
|
ynh_systemd_action --service_name="uwsgi-app@$app.service" --action="start" --log_path="systemd" --line_match="Started"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|