From ada2aa88f03ff03a8509901f45e35d50860240f0 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 28 Feb 2021 12:24:08 +0100 Subject: [PATCH] apply last example --- scripts/install | 32 +++++++------------------------- scripts/restore | 15 +++++++-------- scripts/upgrade | 32 +++++++------------------------- 3 files changed, 21 insertions(+), 58 deletions(-) diff --git a/scripts/install b/scripts/install index f8bd3ec..a65c2cc 100644 --- a/scripts/install +++ b/scripts/install @@ -129,7 +129,7 @@ pushd "$final_path"/build popd # Install bitwarden_rs -cp -a "$final_path"/build/target/release/bitwarden_rs "$final_path"/live/bitwarden_rs +cp -a "$final_path/build/target/release/bitwarden_rs" "$final_path/live/bitwarden_rs" # Remove build files and rustup ynh_secure_remove --file="$final_path/build" @@ -152,24 +152,7 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Modifying a config file..." -config="$final_path/live/bitwarden_rs.env" - -cp -f ../conf/bitwarden_rs.env "$config" - -ynh_replace_string --match_string="__ADMIN_TOKEN__" --replace_string="$admin_token" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__WEBSOCKET_PORT__" --replace_string="$websocket_port" --target_file="$config" -ynh_replace_string --match_string="__ROCKET_PORT__" --replace_string="$rocket_port" --target_file="$config" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="$config" +ynh_add_config --template="../conf/bitwarden_rs.env" --destination="$final_path/live/bitwarden_rs.env" #================================================= # GENERIC FINALIZATION @@ -218,11 +201,13 @@ ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Usern #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." +ynh_script_progression --message="Configuring permissions..." # Make app public if necessary if [ $is_public -eq 1 ] then + # Everyone can access the app. + # The "main" permission is automatically created before the install script. ynh_permission_update --permission="main" --add="visitors" fi @@ -241,12 +226,9 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Sending a readme for the admin..." -ynh_replace_string --match_string="__ADMIN_MAIL__" --replace_string="$admin_mail" --target_file="../conf/message" -ynh_replace_string --match_string="__ADMIN_TOKEN__" --replace_string="$admin_token" --target_file="../conf/message" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="../conf/message" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="../conf/message" +ynh_add_config --template="../conf/message" --destination="../conf/msg_install" -ynh_send_readme_to_admin --app_message="../conf/message" --recipients="$admin_mail" --type='install' +ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients="$admin_mail" --type='install' #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 0aa9900..ea4ea2d 100644 --- a/scripts/restore +++ b/scripts/restore @@ -99,14 +99,6 @@ ynh_script_progression --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." - -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # RESTORE SYSTEMD #================================================= @@ -129,6 +121,13 @@ ynh_script_progression --message="Starting a systemd service..." ynh_systemd_action --service_name=$app --action="start" --log_path="systemd" --line_match="Rocket has launched from" --length=100 +#================================================= +# RESTORE THE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." + +ynh_restore_file --origin_path="/etc/logrotate.d/$app" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index d52d04d..cd8e7d1 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -44,15 +44,16 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +if ! ynh_permission_exists --permission="admin"; then + # Create the required permissions + ynh_permission_create --permission="admin" --url="/admin" --allowed="$admin" --show_tile="false" +fi + # Create a permission if needed if ! ynh_permission_exists --permission="api"; then ynh_permission_create --permission="api" --url="/api" --additional_urls="/identity/connect/token" --allowed="visitors" --auth_header="false" --show_tile="false" --protected="true" fi -if ! ynh_permission_exists --permission="admin"; then - ynh_permission_create --permission="admin" --url="/admin" --allowed="$admin" --show_tile="false" -fi - #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -149,7 +150,7 @@ then ynh_secure_remove --file="$final_path/live/bitwarden_rs.d" # Install bitwarden_rs - cp -af "$final_path"/build/target/release/bitwarden_rs "$final_path"/live/bitwarden_rs + cp -af "$final_path/build/target/release/bitwarden_rs" "$final_path/live/bitwarden_rs" # Remove build files and rustup ynh_secure_remove --file="$final_path/build" @@ -170,26 +171,7 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Modifying a config file..." -config="$final_path/live/bitwarden_rs.env" - -ynh_backup_if_checksum_is_different --file="$config" - -cp -f ../conf/bitwarden_rs.env "$config" - -ynh_replace_string --match_string="__ADMIN_TOKEN__" --replace_string="$admin_token" --target_file="$config" -ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$config" -ynh_replace_string --match_string="__PATH_URL__" --replace_string="$path_url" --target_file="$config" -ynh_replace_string --match_string="__WEBSOCKET_PORT__" --replace_string="$websocket_port" --target_file="$config" -ynh_replace_string --match_string="__ROCKET_PORT__" --replace_string="$rocket_port" --target_file="$config" -ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$config" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= -ynh_script_progression --message="Storing the config file checksum..." - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$config" +ynh_add_config --template="../conf/bitwarden_rs.env" --destination="$final_path/live/bitwarden_rs.env" #================================================= # GENERIC FINALIZATION