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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
|
|
#=================================================
|
|
|
|
|
2020-07-24 00:32:36 +02:00
|
|
|
admin_mail=$(ynh_user_get_info --username=$admin --key=mail)
|
2019-08-05 01:29:15 +02:00
|
|
|
admin_token=$(ynh_string_random --length=48 | base64)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STORE SETTINGS FROM MANIFEST
|
|
|
|
#=================================================
|
2023-06-22 09:23:53 +02:00
|
|
|
ynh_script_progression --message="Storing installation settings..."
|
2019-08-05 01:29:15 +02:00
|
|
|
|
2023-06-22 09:23:53 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=admin_token --value=$admin_token
|
2021-04-10 01:38:20 +02:00
|
|
|
|
2019-08-05 01:29:15 +02:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2020-12-01 22:04:05 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2019-08-05 01:29:15 +02:00
|
|
|
|
2023-12-03 12:08:34 +01:00
|
|
|
_download_vaultwarden_from_docker
|
|
|
|
|
2023-12-03 13:54:05 +01:00
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION FILE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Adding a configuration file..."
|
2022-02-16 01:04:09 +01:00
|
|
|
|
2023-12-03 13:54:05 +01:00
|
|
|
ynh_add_config --template="vaultwarden.env" --destination="$install_dir/live/.env"
|
|
|
|
|
|
|
|
chmod 400 "$install_dir/live/.env"
|
|
|
|
chown $app:$app "$install_dir/live/.env"
|
2021-04-10 23:52:18 +02:00
|
|
|
|
2019-08-05 01:29:15 +02:00
|
|
|
#=================================================
|
2023-09-15 15:29:47 +02:00
|
|
|
# SYSTEM CONFIGURATION
|
2019-08-05 01:29:15 +02:00
|
|
|
#=================================================
|
2023-09-15 15:29:47 +02:00
|
|
|
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
|
2019-08-05 01:29:15 +02:00
|
|
|
|
2020-09-21 09:02:06 +02:00
|
|
|
# Create a dedicated NGINX config
|
2021-07-29 20:05:36 +02:00
|
|
|
ynh_add_nginx_config
|
2019-08-05 01:29:15 +02:00
|
|
|
|
2023-09-15 13:59:51 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2023-12-03 13:54:05 +01:00
|
|
|
# Create log file for fail2ban
|
2023-09-15 13:59:51 +02:00
|
|
|
mkdir -p "/var/log/$app"
|
2023-12-03 13:54:05 +01:00
|
|
|
touch "/var/log/$app/$app.log"
|
2023-09-15 13:59:51 +02:00
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
|
2023-12-03 13:54:05 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2023-09-15 13:59:51 +02:00
|
|
|
ynh_use_logrotate
|
|
|
|
|
2023-09-15 14:39:06 +02:00
|
|
|
# Create a dedicated Fail2Ban config
|
|
|
|
ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Username or password is incorrect\. Try again\. IP: <ADDR>\. Username:.*$"
|
|
|
|
|
2023-09-15 13:59:51 +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
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-12-01 22:04:05 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2019-08-05 01:29:15 +02:00
|
|
|
|
|
|
|
# Start a systemd service
|
2020-01-21 23:03:55 +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="Installation of $app completed"
|