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

95 lines
3.2 KiB
Text
Raw Normal View History

2019-08-05 01:29:15 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2022-09-02 22:17:22 +02:00
source ynh_docker_image_extract
2019-08-05 01:29:15 +02:00
source /usr/share/yunohost/helpers
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
2020-12-01 22:04:05 +01:00
ynh_script_progression --message="Stopping a systemd service..."
2019-08-05 01:29:15 +02:00
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopping Vaultwarden Server"
2021-05-09 11:06:05 +02:00
2019-08-05 01:29:15 +02:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2020-12-01 22:04:05 +01:00
ynh_script_progression --message="Upgrading source files..."
2019-08-05 01:29:15 +02:00
2023-12-03 12:08:34 +01:00
_download_vaultwarden_from_docker
2019-08-05 01:29:15 +02:00
fi
2020-12-01 22:04:05 +01:00
#=================================================
2021-04-10 23:52:18 +02:00
# UPDATE A CONFIG FILE
2020-12-01 22:04:05 +01:00
#=================================================
2021-07-29 20:05:36 +02:00
ynh_script_progression --message="Updating a configuration file..."
2020-12-01 22:04:05 +01:00
2023-10-22 18:52:48 +02:00
ynh_add_config --template="vaultwarden.env" --destination="$install_dir/live/.env"
2021-04-10 23:52:18 +02:00
2023-06-22 09:09:24 +02:00
chmod 400 "$install_dir/live/.env"
chown $app:$app "$install_dir/live/.env"
2020-12-01 22:04:05 +01:00
2024-03-13 13:06:25 +01:00
# Fix SMTP configuration
config_file=$data_dir/config.json
if [ -e "$config_file" ]; then
cat <<< $(jq -r --arg domain "$domain" '.smtp_host = $domain' $config_file) > $config_file
cat <<< $(jq -r '.smtp_security = "starttls"' $config_file) > $config_file
if [ ! -s "$config_file" ]; then
ynh_die --message="Something went wrong while setting up $config_file: it ended up empty."
fi
2024-03-13 13:15:52 +01:00
fi
2024-03-13 13:06:25 +01:00
2019-08-05 01:29:15 +02:00
#=================================================
2023-09-15 15:29:47 +02:00
# REAPPLY SYSTEM CONFIGURATIONS
2019-08-05 01:29:15 +02:00
#=================================================
2023-09-15 15:29:47 +02:00
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
2019-08-05 01:29:15 +02:00
2023-09-15 14:39:06 +02:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2021-04-10 23:52:18 +02:00
# Create a dedicated systemd config
ynh_add_systemd_config
2019-08-05 01:29:15 +02:00
# Create log file for fail2ban
2022-07-17 05:57:09 +02:00
mkdir -p "/var/log/$app"
touch "/var/log/$app/$app.log"
2022-07-17 05:57:09 +02:00
chown -R $app:$app "/var/log/$app"
2022-07-17 05:57:09 +02:00
# Use logrotate to manage app-specific logfile(s)
ynh_use_logrotate --non-append
2023-09-15 14:39:06 +02:00
# Create a dedicated Fail2Ban config
2023-09-15 14:56:03 +02:00
ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Username or password is incorrect\. Try again\. IP: <ADDR>\. Username:.*$"
2019-08-05 01:29:15 +02:00
2021-04-30 13:49:31 +02:00
yunohost service add $app --description="$app daemon for vaultwarden" --log="/var/log/$app/$app.log"
2019-08-05 01:29:15 +02:00
#=================================================
2020-12-01 22:04:05 +01:00
# START SYSTEMD SERVICE
2019-08-05 01:29:15 +02:00
#=================================================
2020-12-01 22:04:05 +01:00
ynh_script_progression --message="Starting a systemd service..."
2019-08-05 01:29:15 +02:00
2020-12-01 22:04:05 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Rocket has launched from" --length=100
2019-08-05 01:29:15 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2020-12-01 22:04:05 +01:00
ynh_script_progression --message="Upgrade of $app completed"