diff --git a/README.md b/README.md index 4d5b6ed..bdc2c5b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,6 @@ LDAP and HTTP auth are not supported * x86-64b - [![Build Status](https://ci-apps.yunohost.org/ci/logs/bitwarden%20%28Apps%29.svg)](https://ci-apps.yunohost.org/ci/apps/bitwarden/) * ARMv8-A - [![Build Status](https://ci-apps-arm.yunohost.org/ci/logs/bitwarden%20%28Apps%29.svg)](https://ci-apps-arm.yunohost.org/ci/apps/bitwarden/) -* Jessie x86-64b - [![Build Status](https://ci-stretch.nohost.me/ci/logs/bitwarden%20%28Apps%29.svg)](https://ci-stretch.nohost.me/ci/apps/bitwarden/) ## Links @@ -56,7 +55,6 @@ LDAP and HTTP auth are not supported Developers info ---------------- -**Only if you want to use a testing branch for coding, instead of merging directly into master.** Please do your pull request to the [testing branch](https://github.com/YunoHost-Apps/bitwarden_ynh/tree/testing). To try the testing branch, please proceed like that. diff --git a/scripts/backup b/scripts/backup index a3d5165..a804c08 100644 --- a/scripts/backup +++ b/scripts/backup @@ -13,6 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -23,40 +24,40 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -domain=$(ynh_app_setting_get --app="$app" --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=2 +ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped Bitwarden Server" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped Bitwarden Server" #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --weight=1 +ynh_print_info --message="Backing up the main app directory..." ynh_backup --src_path="$final_path" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Backing up nginx web server configuration..." --weight=1 +ynh_print_info --message="Backing up nginx web server configuration..." ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Backing up fail2ban configuration..." --weight=1 +ynh_print_info --message="Backing up fail2ban configuration..." ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" @@ -66,25 +67,24 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 +ynh_print_info --message="Backing up logrotate configuration..." ynh_backup --src_path="/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --weight=1 +ynh_print_info --message="Backing up systemd configuration..." ynh_backup --src_path="/etc/systemd/system/$app.service" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Rocket has launched from" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Rocket has launched from" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then - ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" --line_match="Rocket has launched from" sleep 60 fi @@ -92,4 +92,4 @@ fi # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last +ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index d534462..2b2dc97 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,10 +24,32 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_print_info --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) + +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= +ynh_print_info --message="Backing up the app before changing its url (may take a while)..." + +# Backup the current version of the app +ynh_backup_before_upgrade +ynh_clean_setup () { + # Remove the new domain config file, the remove script won't do it as it doesn't know yet its location. + ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + + # restore it if the upgrade fails + ynh_restore_upgradebackup +} +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED @@ -50,14 +72,14 @@ fi #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped Bitwarden Server" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped Bitwarden Server" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --weight=1 +ynh_print_info --message="Updating nginx web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -78,7 +100,7 @@ if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location ynh_delete_file_checksum --file="$nginx_conf_path" - mv "$nginx_conf_path" /etc/nginx/conf.d/"$new_domain".d/"$app".conf + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi @@ -94,18 +116,17 @@ fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Rocket has launched from" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Rocket has launched from" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then - ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" --line_match="Rocket has launched from" sleep 60 fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_print_info --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -113,4 +134,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_print_info --message="Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index f65b1e3..3490862 100644 --- a/scripts/install +++ b/scripts/install @@ -13,6 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -23,6 +24,7 @@ ynh_abort_if_errors #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= +ynh_print_info --message="Retrieving arguments from the manifest..." domain=$YNH_APP_ARG_DOMAIN path_url="/" @@ -37,53 +39,54 @@ admin_token=$(ynh_string_random --length=48 | base64) #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 +ynh_print_info --message="Validating installation parameters..." final_path=/var/www/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" # Register (book) web path -ynh_webpath_register --app="$app" --domain="$domain" --path_url=$path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= -ynh_script_progression --message="Storing installation settings..." --weight=2 +ynh_print_info --message="Storing installation settings..." -ynh_app_setting_set --app="$app" --key=domain --value="$domain" -ynh_app_setting_set --app="$app" --key=path --value=$path_url -ynh_app_setting_set --app="$app" --key=admin --value="$admin" -ynh_app_setting_set --app="$app" --key=is_public --value="$is_public" -ynh_app_setting_set --app="$app" --key=admin_token --value="$admin_token" +ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=admin --value=$admin +ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=admin_token --value=$admin_token #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= -ynh_script_progression --message="Configuring firewall..." --weight=1 +ynh_print_info --message="Configuring firewall..." -# Find a free port + +# Find an available port websocket_port=$(ynh_find_port --port=3012) -ynh_app_setting_set --app="$app" --key=websocket_port --value="$websocket_port" +ynh_app_setting_set --app=$app --key=websocket_port --value="$websocket_port" -# Find a free port +# Find an available port rocket_port=$(ynh_find_port --port=8095) -ynh_app_setting_set --app="$app" --key=rocket_port --value="$rocket_port" +ynh_app_setting_set --app=$app --key=rocket_port --value="$rocket_port" #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=10 +ynh_print_info --message="Installing dependencies..." -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=3 +ynh_print_info --message="Setting up source files..." -ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" +ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress the source of bitwarden_rs from app.src to his build directory ynh_setup_source --dest_dir="$final_path/build/" --source_id=app @@ -94,7 +97,7 @@ ynh_setup_source --dest_dir="$final_path/live/web-vault/" --source_id=web #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." --weight=2 +ynh_print_info --message="Configuring nginx web server..." # Create a dedicated nginx config ynh_add_nginx_config "websocket_port rocket_port" @@ -102,7 +105,7 @@ ynh_add_nginx_config "websocket_port rocket_port" #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --weight=2 +ynh_print_info --message="Configuring system user..." # Create a system user ynh_system_user_create --username="$app" --home_dir="$final_path" @@ -112,7 +115,7 @@ ynh_system_user_create --username="$app" --home_dir="$final_path" #================================================= # MAKE INSTALL #================================================= -ynh_script_progression --message="Making install..." --weight=780 +ynh_print_info --message="Making install..." # Set right permissions chown -R "$app":"$app" "$final_path" @@ -140,7 +143,7 @@ ynh_secure_remove --file="$final_path/.rustup" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=2 +ynh_print_info --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config @@ -148,6 +151,7 @@ ynh_add_systemd_config #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." config="$final_path/live/bitwarden_rs.env" @@ -162,6 +166,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_print_info --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$config" @@ -171,6 +176,7 @@ ynh_store_file_checksum --file="$config" #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions to app files chown -R "$app":"$app" "$final_path" @@ -180,33 +186,33 @@ chown -R "$app":"$app" "/var/log/$app" #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=2 +ynh_print_info --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_use_logrotate #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "$app" --description "$app daemon for Bitwarden" --log "/var/log/$app/$app.log" +yunohost service add $app --description "$app daemon for Bitwarden" --log "/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=2 +ynh_print_info --message="Starting a systemd service..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Rocket has launched from" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Rocket has launched from" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then - ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" --line_match="Rocket has launched from" sleep 60 fi #================================================= # SETUP FAIL2BAN #================================================= -ynh_script_progression --message="Configuring fail2ban..." --weight=5 +ynh_print_info --message="Configuring fail2ban..." # Create a dedicated fail2ban config touch /var/log/"$app"/"$app".log @@ -215,26 +221,26 @@ ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Usern #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Configuring SSOwat..." --weight=1 +ynh_print_info --message="Configuring SSOwat..." # Make app public if necessary -if [ "$is_public" -eq 1 ] +if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway. - ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_print_info --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload #================================================= # SEND A README FOR THE ADMIN #================================================= -ynh_script_progression --message="Sending a readme for the admin..." --weight=17 +ynh_print_info --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" @@ -246,4 +252,4 @@ ynh_send_readme_to_admin --app_message="../conf/message" --recipients="$admin_ma # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_print_info --message="Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 3674db5..bce5632 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,30 +12,31 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=2 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # STANDARD REMOVE #================================================= -# REMOVE SERVICE FROM ADMIN PANEL +# REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= +ynh_print_info --message="Removing service integration in YunoHost..." -# Remove a service from the admin panel, added by `yunohost service add` -if ynh_exec_warn_less yunohost service status "$app" >/dev/null +# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --weight=1 - yunohost service remove "$app" + ynh_print_info --message="Removing $app service..." + yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 +ynh_print_info --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config @@ -43,7 +44,7 @@ ynh_remove_systemd_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --weight=4 +ynh_print_info --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -51,7 +52,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 +ynh_print_info --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -59,7 +60,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." --weight=2 +ynh_print_info --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -67,7 +68,7 @@ ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 +ynh_print_info --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate @@ -75,7 +76,7 @@ ynh_remove_logrotate #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Removing fail2ban configuration..." --weight=7 +ynh_print_info --message="Removing fail2ban configuration..." # Remove the dedicated fail2ban config ynh_remove_fail2ban_config @@ -94,13 +95,13 @@ ynh_secure_remove --file="/var/log/$app/" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +ynh_print_info --message="Removing the dedicated system user..." # Delete a system user -ynh_system_user_delete --username="$app" +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_print_info --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 424fe9a..4c314bb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -13,6 +13,7 @@ source /usr/share/yunohost/helpers #================================================= # MANAGE SCRIPT FAILURE #================================================= +ynh_print_info --message="Managing script failure..." ynh_clean_setup () { ynh_clean_check_starting @@ -23,22 +24,22 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=1 +ynh_print_info --message="Loading settings..." 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) +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) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 +ynh_print_info --message="Validating restoration parameters..." -ynh_webpath_available --domain="$domain" --path_url="$path_url" \ +ynh_webpath_available --domain=$domain --path_url=$path_url \ || ynh_die --message="Path not available: ${domain}${path_url}" -test ! -d "$final_path" \ +test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " #================================================= @@ -52,21 +53,22 @@ ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_print_info --message="Restoring the app main directory..." ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=3 +ynh_print_info --message="Recreating the dedicated system user..." # Create the dedicated user (if not existing) -ynh_system_user_create --username="$app" --home_dir="$final_path" +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE USER RIGHTS #================================================= +ynh_print_info --message="Restoring user rights..." # Restore permissions on app files chown -R "$app":"$app" "$final_path" @@ -76,7 +78,7 @@ chown -R "$app":"$app" /var/log/"$app" #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the fail2ban configuration..." --weight=8 +ynh_print_info --message="Restoring the fail2ban configuration..." # Create a dedicated fail2ban config mkdir -p "/var/log/$app" @@ -92,33 +94,34 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=8 +ynh_print_info --message="Reinstalling dependencies..." # Define and install dependencies -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies + #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_print_info --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable "$app".service #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_print_info --message="Integrating service in YunoHost..." -yunohost service add "$app" --description "$app daemon for Bitwarden" --log "/var/log/$app/$app.log" +yunohost service add $app --description "$app daemon for Bitwarden" --log "/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=2 +ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Rocket has launched from" + +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Rocket has launched from" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then - ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" --line_match="Rocket has launched from" sleep 60 fi @@ -133,7 +136,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_print_info --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -141,4 +144,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_print_info --message="Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index f082c9a..d3bdeb6 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,19 +12,19 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 +ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -path_url=$(ynh_app_setting_get --app="$app" --key=path) -admin=$(ynh_app_setting_get --app="$app" --key=admin) -is_public=$(ynh_app_setting_get --app="$app" --key=is_public) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +domain=$(ynh_app_setting_get --app=$app --key=domain) +path_url=$(ynh_app_setting_get --app=$app --key=path) +admin=$(ynh_app_setting_get --app=$app --key=admin) +is_public=$(ynh_app_setting_get --app=$app --key=is_public) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) -admin_token=$(ynh_app_setting_get --app="$app" --key=admin_token) -rocket_port=$(ynh_app_setting_get --app="$app" --key=rocket_port) -websocket_port=$(ynh_app_setting_get --app="$app" --key=websocket_port) +admin_token=$(ynh_app_setting_get --app=$app --key=admin_token) +rocket_port=$(ynh_app_setting_get --app=$app --key=rocket_port) +websocket_port=$(ynh_app_setting_get --app=$app --key=websocket_port) #================================================= # CHECK VERSION @@ -35,27 +35,27 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_print_info --message="Ensuring downward compatibility..." # Fix is_public as a boolean value if [ "$is_public" = "Yes" ]; then - ynh_app_setting_set --app="$app" --key=is_public --value=1 + ynh_app_setting_set --app=$app --key=is_public --value=1 is_public=1 elif [ "$is_public" = "No" ]; then - ynh_app_setting_set --app="$app" --key=is_public --value=0 + ynh_app_setting_set --app=$app --key=is_public --value=0 is_public=0 fi # If final_path doesn't exist, create it if [ -z "$final_path" ]; then final_path=/var/www/$app - ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" + ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 +ynh_print_info --message="Backing up the app before upgrading (may take a while)..." # Backup the current version of the app ynh_backup_before_upgrade @@ -72,17 +72,18 @@ ynh_abort_if_errors #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_print_info --message="Stopping a systemd service..." -ynh_systemd_action --service_name="$app" --action="stop" --log_path="systemd" --line_match="Stopped Bitwarden Server" +ynh_systemd_action --service_name=$app --action="stop" --log_path=systemd --line_match="Stopped Bitwarden Server" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_print_info --message="Upgrading source files..." if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=6 + ynh_print_info --message="Upgrading source files..." # Download, check integrity, uncompress the source of bitwarden_rs from app.src to his build directory ynh_setup_source --dest_dir="$final_path/build/" --source_id=app @@ -94,7 +95,7 @@ fi #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1 +ynh_print_info --message="Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config "websocket_port rocket_port" @@ -102,24 +103,24 @@ ynh_add_nginx_config "websocket_port rocket_port" #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=5 +ynh_print_info --message="Upgrading dependencies..." -ynh_install_app_dependencies "$pkg_dependencies" +ynh_install_app_dependencies $pkg_dependencies #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_print_info --message="Making sure dedicated system user exists..." # Create a dedicated user (if not existing) -ynh_system_user_create --username="$app" --home_dir="$final_path" +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # SPECIFIC UPGRADE #================================================= # MAKE UPGRADE #================================================= -ynh_script_progression --message="Making upgrade..." --weight=760 +ynh_print_info --message="Making upgrade..." # Set right permissions chown -R "$app":"$app" "$final_path" @@ -150,6 +151,7 @@ fi #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." config="$final_path/live/bitwarden_rs.env" @@ -166,6 +168,7 @@ ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_fil #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_print_info --message="Storing the config file checksum..." # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$config" @@ -173,7 +176,7 @@ ynh_store_file_checksum --file="$config" #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_print_info --message="Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) ynh_use_logrotate --non-append @@ -181,7 +184,7 @@ ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 +ynh_print_info --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config @@ -191,7 +194,7 @@ ynh_add_systemd_config #================================================= # UPGRADE FAIL2BAN #================================================= -ynh_script_progression --message="Reconfiguring fail2ban..." --weight=8 +ynh_print_info --message="Reconfiguring fail2ban..." # Create a dedicated fail2ban config ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Username or password is incorrect\. Try again\. IP: \. Username:.*$" @@ -199,6 +202,7 @@ ynh_add_fail2ban_config --logpath="/var/log/$app/$app.log" --failregex="^.*Usern #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions on app files chown -R "$app":"$app" "$final_path" @@ -208,30 +212,29 @@ chown -R "$app":"$app" /var/log/"$app" #================================================= # SETUP SSOWAT #================================================= -ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1 +ynh_print_info --message="Upgrading SSOwat configuration..." # Make app public if necessary if [ $is_public -eq 1 ] then # unprotected_uris allows SSO credentials to be passed anyway - ynh_app_setting_set --app="$app" --key=unprotected_uris --value="/" + ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +ynh_print_info --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" --line_match="Rocket has launched from" +ynh_systemd_action --service_name=$app --action="start" --log_path=systemd --line_match="Rocket has launched from" if [ "${PACKAGE_CHECK_EXEC:-0}" -eq 1 ]; then - ynh_systemd_action --service_name="$app" --action="restart" --log_path="systemd" --line_match="Rocket has launched from" sleep 60 fi #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --weight=1 +ynh_print_info --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -239,4 +242,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_print_info --message="Upgrade of $app completed"