1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/dont-code_ynh.git synced 2024-09-03 18:26:34 +02:00
dont-code_ynh/scripts/upgrade

179 lines
6.3 KiB
Text
Raw Normal View History

2022-12-27 17:59:56 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2023-01-02 19:03:27 +01:00
source ynh_mongo_db__2
2022-12-27 17:59:56 +01:00
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
2023-01-02 19:03:27 +01:00
# STOP SYSTEMD SERVICES
2022-12-27 17:59:56 +01:00
#=================================================
2023-01-02 19:03:27 +01:00
ynh_script_progression --message="Stopping systemd services..." --weight=1
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
for service_name in "${SERVICES_LIST[@]}"; do
2023-01-02 19:03:27 +01:00
ynh_systemd_action --service_name="${app}-${service_name}" --action="stop" --log_path="/var/log/$app/$app.log"
done
2022-12-27 17:59:56 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2024-01-04 16:57:56 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2023-01-03 14:51:52 +01:00
2024-01-05 23:15:27 +01:00
# Missing settings ?
if [ -z "${public_key+x}" ]; then
public_key=""
ynh_app_setting_set --app="$app" --key=public_key --value="$public_key"
fi
# Set default tenant to empty if needed
if [ -z "${tenant+x}" ]; then
tenant=""
ynh_app_setting_set --app="$app" --key=tenant --value="$tenant"
fi
2024-04-01 15:03:51 +02:00
# The .env needs db_password
2024-04-01 14:44:15 +02:00
new_db_pwd=$(ynh_string_random) # Generate a random password
2024-04-01 14:28:27 +02:00
db_pwd="${db_pwd:-$new_db_pwd}"
2024-01-05 17:43:17 +01:00
if [[ -n "${document_path:-}" ]]; then
# Renamed setting key
document_dir="$document_path"
ynh_app_setting_delete --app="$app" --key=document_path
ynh_app_setting_set --app="$app" --key=document_dir --value="$document_dir"
fi
2024-01-04 16:57:56 +01:00
if [[ -n "${html_path:-}" ]]; then
2024-02-15 15:30:59 +01:00
# document dir has moved from html_path to data_dir, so set the variable accordingly
if [[ ${document_dir} == ${html_path}* ]]; then
document_dir=$data_dir/docs
ynh_app_setting_set --app="$app" --key=document_dir --value="$document_dir"
fi
2024-01-04 16:57:56 +01:00
# Migrate html_path to data_dir
mv "$html_path/index.html" "$html_path/docs" "$data_dir"
old_doc_dir="$html_path/docs"
2024-01-04 16:57:56 +01:00
ynh_secure_remove --file="$html_path"
ynh_app_setting_delete --app="$app" --key=html_path
# FIXME: other settings
2023-01-03 14:51:52 +01:00
2024-01-04 16:57:56 +01:00
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
# Update the path in .env file
ynh_backup_if_checksum_is_different --file="$install_dir/.env"
ynh_replace_string --match_string="$old_doc_dir" --replace_string="$document_dir" --target_file="$install_dir/.env"
2024-01-04 16:57:56 +01:00
ynh_store_file_checksum --file="$install_dir/.env"
2024-02-15 15:30:59 +01:00
2024-01-04 16:57:56 +01:00
fi
2022-12-27 17:59:56 +01:00
# Recalculate the document_url if it was incorrectly set before
2024-01-04 16:57:56 +01:00
correct_document_url=$(append_uri "https://${domain}${path}" "docs")
if [ "$correct_document_url" != "$document_url" ]; then
ynh_script_progression --message="Updading url for documents" --weight=1
old_doc_url=$document_url
document_url=$correct_document_url
ynh_app_setting_set --app=$app --key=document_url --value=$document_url
fi
2022-12-27 17:59:56 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2024-01-04 16:57:56 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading source files..." --weight=1
2023-01-02 19:03:27 +01:00
2024-01-04 16:57:56 +01:00
# Download, check integrity, uncompress and patch the source from app.src
2024-03-13 17:12:49 +01:00
ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep ".env .ssh/authorized_keys restart_services.sh"
# Always update .env
ynh_add_config --template=".env" --destination="$install_dir/.env"
# FIXME: this should be handled by the core in the future
# You may need to use chmod 600 instead of 400,
# for example if the app is expected to be able to modify its own config
chmod 400 "$install_dir/.env"
chown $app:$app "$install_dir/.env"
2022-12-27 17:59:56 +01:00
fi
2024-01-03 23:19:38 +01:00
chmod -R o-rwx "$install_dir"
2024-01-04 16:57:56 +01:00
chown -R "$app:$app" "$install_dir"
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
# Configure document storage
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
ynh_script_progression --message="Configuring document storage..." --weight=1
2023-01-03 14:51:52 +01:00
2024-01-04 16:57:56 +01:00
ynh_add_config --template="index.html" --destination="$data_dir/index.html"
2023-01-03 14:51:52 +01:00
2024-04-05 18:34:23 +02:00
# Add the repository pages
ynh_add_config --template="repository-next.json" --destination="$data_dir/repository-next.json"
ynh_add_config --template="repository-stable.json" --destination="$data_dir/repository-stable.json"
2024-01-05 18:49:33 +01:00
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
# ADD SSH ACCESS
2022-12-27 17:59:56 +01:00
#=================================================
2023-01-02 19:03:27 +01:00
2024-01-04 16:57:56 +01:00
if [ -n "$public_key" ]; then
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
2024-01-05 16:27:40 +01:00
_install_restart_script_and_sudoers
2023-01-07 10:31:21 +01:00
fi
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
# UPGRADE MongoDB
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
ynh_script_progression --message="Upgrading MongoDB..." --weight=1
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
2022-12-27 17:59:56 +01:00
# We are now assigning the user to the database, so update the user's rights
for db_name in "${MONGO_DB_LIST[@]}"; do
ynh_mongo_setup_db --db_user="$db_user" --db_pwd="$db_pwd" --db_name="dontCode$tenant${db_name}"
done
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
# REAPPLY SYSTEM CONFIGURATIONS
2022-12-27 17:59:56 +01:00
#=================================================
2024-01-04 16:57:56 +01:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
ynh_add_nginx_config
2022-12-27 17:59:56 +01:00
ynh_use_logrotate --non-append
2024-01-04 16:57:56 +01:00
for i in "${!SERVICES_LIST[@]}"; do
service_name="${SERVICES_LIST[i]}"
port="${PORT_LIST[i]}"
ynh_add_systemd_config --service="${app}-${service_name}"
yunohost service add "${app}-${service_name}" --description="Dont-code platform ${service_name} service" --log="/var/log/${app}/${service_name}-${app}.log"
2023-01-02 19:03:27 +01:00
done
2022-12-27 17:59:56 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2023-01-02 19:03:27 +01:00
ynh_script_progression --message="Starting systemd services..." --weight=1
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
2023-01-02 19:03:27 +01:00
done
2022-12-27 17:59:56 +01:00
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last