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

143 lines
5.3 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source ynh_mongo_db__2
source /usr/share/yunohost/helpers
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICES
#=================================================
ynh_script_progression --message="Stopping systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="stop" --log_path="/var/log/$app/$app.log"
done
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
if [[ -n "${html_path:-}" ]]; then
# Migrate html_path to data_dir
mv "$html_path/index.html" "$html_path/docs" "$data_dir"
ynh_secure_remove --file="$html_path"
ynh_app_setting_delete --app="$app" --key=html_path
# FIXME: other settings
chmod -R o-rwx "$data_dir"
chown -R "$app:www-data" "$data_dir"
# Update the path in .env file
ynh_backup_if_checksum_is_different --file="$install_dir/.env"
ynh_replace_string --match_string="$old_doc_path" --replace_string="$document_path" --target_file="$install_dir/.env"
ynh_store_file_checksum --file="$install_dir/.env"
fi
# 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
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]; then
ynh_script_progression --message="Upgrading source files..." --weight=1
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$install_dir"
fi
chmod -R o-rwx "$install_dir"
chown -R "$app:$app" "$install_dir"
#=================================================
# Configure document storage
#=================================================
ynh_script_progression --message="Configuring document storage..." --weight=1
ynh_add_config --template="index.html" --destination="$data_dir/index.html"
chmod o-rwx "$data_dir/index.html"
chown "$app:www-data" "$data_dir/index.html"
#=================================================
# ADD SSH ACCESS
#=================================================
if [ -n "$public_key" ]; then
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
# Enable restarting of services from ssh
ynh_add_config --template="restart-services.sh" --destination="$install_dir/restart-services.sh"
chown "$app:$app" "$install_dir/restart-services.sh"
chmod o-rwx,gu=rwx "$install_dir/restart-services.sh"
# Add sudoers file for this specific command
ynh_add_config --template="dont-code-sudoers" --destination="/etc/sudoers.d/$app-sudoers"
chown root:root "/etc/sudoers.d/$app-sudoers"
chmod o-rwx,gu=r "/etc/sudoers.d/$app-sudoers"
fi
#=================================================
# UPGRADE MongoDB
#=================================================
ynh_script_progression --message="Upgrading MongoDB..." --weight=1
# Install the required version of Mongo
ynh_install_mongo --mongo_version=$mongo_version
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
ynh_add_nginx_config
ynh_use_logrotate --non-append
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"
done
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting systemd services..." --weight=1
for service_name in "${SERVICES_LIST[@]}"; do
ynh_systemd_action --service_name="${app}-${service_name}" --action="start" --log_path="/var/log/$app/$app.log"
done
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Upgrade of $app completed" --last