mirror of
https://github.com/YunoHost-Apps/dont-code_ynh.git
synced 2024-09-03 18:26:34 +02:00
156 lines
5.5 KiB
Bash
156 lines
5.5 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
|
|
|
|
# Missing settings ?
|
|
if [ -z "${public_key+x}" ]; then
|
|
public_key=""
|
|
ynh_app_setting_set --app="$app" --key=public_key --value="$public_key"
|
|
fi
|
|
|
|
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
|
|
|
|
if [[ -n "${html_path:-}" ]]; then
|
|
|
|
# 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
|
|
|
|
# Migrate html_path to data_dir
|
|
mv "$html_path/index.html" "$html_path/docs" "$data_dir"
|
|
old_doc_dir="$html_path/docs"
|
|
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_dir" --replace_string="$document_dir" --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 -R o-rwx "$data_dir"
|
|
chown -R "$app:www-data" "$data_dir"
|
|
|
|
#=================================================
|
|
# ADD SSH ACCESS
|
|
#=================================================
|
|
|
|
if [ -n "$public_key" ]; then
|
|
ynh_script_progression --message="Upgrading ssh access for dev..." --weight=1
|
|
_install_restart_script_and_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
|