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

155 lines
5.5 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
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-02-14 18:19:11 +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
if [[ -n "${html_path:-}" ]]; then
# 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"
fi
2022-12-27 17:59:56 +01:00
2024-01-04 16:57:56 +01:00
# Regenerate the .env file if the document_url was incorrectly set before
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
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"
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
ynh_setup_source --dest_dir="$install_dir"
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-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
#=================================================
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