2021-03-07 19:51:22 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2021-03-07 19:51:22 +01:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
port=$(ynh_app_setting_get --app=$app --key=port)
2021-05-15 14:40:07 +02:00
password=$(ynh_app_setting_get --app=$app --key=password)
2021-03-07 19:51:22 +01:00
#=================================================
# CHECK VERSION
#=================================================
2021-05-15 14:40:07 +02:00
ynh_script_progression --message="Checking version..."
2021-03-07 19:51:22 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2021-05-15 14:40:07 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=15
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# 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
2021-03-07 19:51:22 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=4
2021-03-07 19:51:22 +01:00
# Cleaning legacy permissions
if ynh_legacy_permissions_exists; then
ynh_legacy_permissions_delete_all
ynh_app_setting_delete --app=$app --key=is_public
fi
#=================================================
2021-03-07 23:36:27 +01:00
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
# Create a dedicated NGINX config
ynh_add_nginx_config
2021-03-07 19:51:22 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Upgrading dependencies..." --weight=15
2021-03-07 19:51:22 +01:00
2021-05-15 14:40:07 +02:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADING COUCHDB
#=================================================
ynh_script_progression --message="Upgrading couchdb..." --weight=60
COUCHDB_PASSWORD=$password
echo "couchdb couchdb/mode select standalone
couchdb couchdb/mode seen true
couchdb couchdb/bindaddress string 127.0.0.1
couchdb couchdb/bindaddress seen true
couchdb couchdb/adminpass password ${COUCHDB_PASSWORD}
couchdb couchdb/adminpass seen true
couchdb couchdb/adminpass_again password ${COUCHDB_PASSWORD}
couchdb couchdb/adminpass_again seen true" | debconf-set-selections
DEBIAN_FRONTEND=noninteractive # apt-get install -y --force-yes couchdb
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8756C4F765C9AC3CB6B85D62379CE192D401AB61
ynh_install_extra_app_dependencies --repo="https://apache.bintray.com/couchdb-deb buster main" --package="couchdb"
# ynh_install_extra_app_dependencies --repo="https://apache.bintray.com/couchdb-deb buster main" --package="couchdb" --key="https://apache.bintray.com/couchdb-deb/dists/buster/Release.gpg"
#=================================================
# UPDATE A CONFIG FILE
#=================================================
ynh_script_progression --message="Updating a configuration file..."
ynh_add_config --template="../conf/couch_ynh.ini" --destination="$final_path/etc/local.d/couch_ynh.ini"
2021-03-07 19:51:22 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SETUP LOGROTATE
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2021-03-07 19:51:22 +01:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
2021-03-07 19:51:22 +01:00
yunohost service add $app --description="Open-source document-oriented NoSQL database" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port"
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=3
2021-03-07 19:51:22 +01:00
# Create a dedicated Fail2Ban config
ynh_add_fail2ban_config --logpath="/var/log/couchdb/couchdb.log" --failregex="[warning] .*couch_httpd_auth: Authentication failed for user .+ from <HOST>" --max_retry=5
#=================================================
# RELOAD NGINX
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2021-03-07 19:51:22 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2021-03-07 23:36:27 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last