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
|
|
|
|
2021-05-09 11:06:05 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd" --line_match="Stopped"
|
|
|
|
|
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
|
|
|
|
2021-04-30 13:49:31 +02:00
|
|
|
# Download, check integrity, uncompress the source of vaultwarden from app.src to his build directory
|
2022-10-19 23:05:00 +02:00
|
|
|
docker_arg=""
|
|
|
|
if [ $YNH_ARCH == "armhf" ]
|
|
|
|
then
|
2022-10-20 15:08:16 +02:00
|
|
|
docker_arg="--os_arch_variant=linux/arm/v7"
|
2022-10-19 23:05:00 +02:00
|
|
|
fi
|
2023-06-22 09:09:24 +02:00
|
|
|
ynh_docker_image_extract --dest_dir="$install_dir/build/" --image_spec="$pkg_image:$(ynh_app_upstream_version)" $docker_arg
|
|
|
|
mkdir -p "$install_dir/live/"
|
2019-08-05 01:29:15 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-22 09:09:24 +02:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
2021-04-10 01:38:20 +02:00
|
|
|
|
2019-08-05 01:29:15 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2019-08-12 22:16:54 +02:00
|
|
|
# MAKE UPGRADE
|
2019-08-05 01:29:15 +02:00
|
|
|
#=================================================
|
2020-12-01 22:04:05 +01:00
|
|
|
ynh_script_progression --message="Making upgrade..."
|
2019-08-05 01:29:15 +02:00
|
|
|
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
2023-06-22 09:09:24 +02:00
|
|
|
mv -f "$install_dir/build/vaultwarden" "$install_dir/live/vaultwarden"
|
2023-06-22 09:23:53 +02:00
|
|
|
ynh_secure_remove --file="$install_dir/live/web-vault/"
|
2023-06-22 09:09:24 +02:00
|
|
|
rsync -a "$install_dir/build/web-vault/" "$install_dir/live/web-vault/"
|
2023-06-22 09:23:53 +02:00
|
|
|
ynh_secure_remove --file="$install_dir/build"
|
2019-08-05 01:29:15 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-22 09:09:24 +02:00
|
|
|
chmod 750 "$install_dir"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
2022-07-18 21:17:17 +02:00
|
|
|
|
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-06-22 09:09:24 +02:00
|
|
|
ynh_add_config --template="../conf/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
|
|
|
|
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
|
|
|
|
2022-07-17 05:57:09 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
2023-09-15 14:39:06 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
|
|
|
touch "/var/log/$app/$app.log"
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
|
|
|
|
# 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"
|