diff --git a/README.md b/README.md index 340c624..216c957 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,12 @@ # WebMin package installation for YunoHost -[![Integration level](https://dash.yunohost.org/integration/webmin.svg)](https://dash.yunohost.org/appci/app/webmin) ![](https://ci-apps.yunohost.org/ci/badges/webmin.status.svg) ![](https://ci-apps.yunohost.org/ci/badges/webmin.maintain.svg) -[![Install webmin with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=webmin)

+[![Integration level](https://dash.yunohost.org/integration/webin.svg)](https://dash.yunohost.org/appci/app/webmin) +[![Install Webin with YunoHost](https://install-app.yunohost.org/install-with-yunohost.png)](https://install-app.yunohost.org/?app=webmin) +

+ +> *This package allow you to install Webmin quickly and simply on a YunoHost server. +If you don't have YunoHost, please see [here](https://yunohost.org/#/install) to know how to install and enjoy it.* **Note:** This app has **root** access which can change core things in the system, thus **breaking the YunoHost**. Use it carefully and read the [documents](https://doxfer.webmin.com/Webmin/Main_Page) two times before changing values. diff --git a/scripts/_common.sh b/scripts/_common.sh index bb04a03..6ca04e1 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,13 +1,22 @@ #!/bin/bash -# ============= FUTURE YUNOHOST HELPER ============= -# Delete a file checksum from the app settings -# -# $app should be defined when calling this helper -# -# usage: ynh_remove_file_checksum file -# | arg: file - The file for which the checksum will be deleted -ynh_delete_file_checksum () { - local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' - ynh_app_setting_delete $app $checksum_setting_name -} \ No newline at end of file +#================================================= +# COMMON VARIABLES +#================================================= + +# dependencies used by the app +pkg_dependencies="perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python" + +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= + + diff --git a/scripts/backup b/scripts/backup index 6a626d7..ca57c9e 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -23,21 +24,42 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) +domain=$(ynh_app_setting_get --app=$app --key=domain) #================================================= # STANDARD BACKUP STEPS #================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd Webmin service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" + #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Backing up nginx web server configuration..." --time --weight=1 -ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # SPECIFIC BACKUP #================================================= -ynh_backup "/etc/webmin/miniserv.conf" +ynh_backup --src_path="/etc/webmin/miniserv.conf" + +================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd Webmin service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="start" + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last diff --git a/scripts/change_url b/scripts/change_url index efae51a..652bf18 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -49,6 +49,13 @@ fi #================================================= # STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # MODIFY URL IN NGINX CONF #================================================= diff --git a/scripts/install b/scripts/install index 82ad41b..5ca5704 100644 --- a/scripts/install +++ b/scripts/install @@ -40,55 +40,69 @@ admin=$YNH_APP_ARG_ADMIN ### db names, ... app=$YNH_APP_INSTANCE_NAME -# Normalize the url path syntax -path_url=$(ynh_normalize_url_path $path_url) +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= +### About --weight and --time +### ynh_script_progression will show to your final users the progression of each scripts. +### In order to do that, --weight will represent the relative time of execution compared to the other steps in the script. +### --time is a packager option, it will show you the execution time since the previous call. +### This option should be removed before releasing your app. +### Use the execution time, given by --time, to estimate the weight of a step. +### A common way to do it is to set a weight equal to the execution time in second +1. +### The execution time is given for the duration since the previous call. So the weight should be applied to this previous call. +ynh_script_progression --message="Validating installation parameters..." --time --weight=1 + -# Check web path availability -ynh_webpath_available $domain $path_url # Register (book) web path -ynh_webpath_register $app $domain $path_url +ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url #================================================= # STORE SETTINGS FROM MANIFEST #================================================= +ynh_script_progression --message="Storing installation settings..." --time --weight=1 -ynh_app_setting_set $app domain $domain -ynh_app_setting_set $app path $path_url -ynh_app_setting_set $app admin $admin +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 #================================================= # STANDARD MODIFICATIONS #================================================= # FIND AND OPEN A PORT #================================================= +ynh_script_progression --message="Configuring firewall..." --time --weight=1 ### Use these lines if you have to open a port for the application ### `ynh_find_port` will find the first available port starting from the given port. ### If you're not using these lines: ### - Remove the section "CLOSE A PORT" in the remove script -# Find a free port -port=$(ynh_find_port 10000) +# Find an available port +port=$(ynh_find_port --port=10000) # Open this port -ynh_app_setting_set $app port $port +ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Installing dependencies..." --time --weight=1 ### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package. ### Those deb packages will be installed as dependencies of this package. ### If you're not using this helper: ### - Remove the section "REMOVE DEPENDENCIES" in the remove script +### - Remove the variable "pkg_dependencies" in _common.sh ### - As well as the section "REINSTALL DEPENDENCIES" in the restore script ### - And the section "UPGRADE DEPENDENCIES" in the upgrade script -ynh_install_app_dependencies perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python - +ynh_install_app_dependencies $pkg_dependencies + #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Configuring nginx web server..." --time --weight=1 ### `ynh_add_nginx_config` will use the file conf/nginx.conf @@ -99,12 +113,12 @@ sudo sh -c "echo 'deb http://download.webmin.com/download/repository sarge contr sudo sh -c "echo 'deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib' >> /etc/apt/sources.list.d/webmin.list" -sudo wget http://www.webmin.com/jcameron-key.asc -sudo apt-key add jcameron-key.asc -sudo rm jcameron-key.asc +wget http://www.webmin.com/jcameron-key.asc +apt-key add jcameron-key.asc +rm jcameron-key.asc -sudo apt-get update -sudo apt-get install -y webmin +apt-get update +apt-get install -y webmin #================================================= # MODIFY A CONFIG FILE @@ -113,8 +127,8 @@ sudo apt-get install -y webmin ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -ynh_replace_string "port=10000" "port=$port" "/etc/webmin/miniserv.conf" -ynh_replace_string "listen=10000" "listen=$port" "/etc/webmin/miniserv.conf" +ynh_replace_string --match_string="port=10000" --replace_string"port=$port" --target_file="/etc/webmin/miniserv.conf" +ynh_replace_string --match_string="listen=10000" --replace_string"listen=$port" --target_file="/etc/webmin/miniserv.conf" #================================================= # STORE THE CONFIG FILE CHECKSUM @@ -125,20 +139,26 @@ ynh_replace_string "listen=10000" "listen=$port" "/etc/webmin/miniserv.conf" ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "/etc/webmin/miniserv.conf" +ynh_store_file_checksum --file="/etc/webmin/miniserv.conf" #================================================= # SETUP SSOWAT #================================================= +ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 # Restrict access to admin only yunohost app addaccess --users=$admin $app - #================================================= -# RELOAD NGINX AND START WEBMIN +# RELOAD NGINX #================================================= -systemctl enable webmin -systemctl restart webmin -sudo service nginx reload +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +ynh_script_progression --message="Starting webmin web server..." --time --weight=1 +ynh_systemd_action --service_name=$app --action=enable + +ynh_systemd_action --service_name=$app --action=start + diff --git a/scripts/remove b/scripts/remove index bd861ad..c6666ea 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,15 +12,24 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -port=$(ynh_app_setting_get $app port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +#================================================= +# STOP WEBMIN +#================================================= +ynh_script_progression --message="Stopping webmin service..." --time --weight=1 + +# Remove the dedicated Webmin +ynh_systemd_action --service_name=webmin --action=stop #================================================= # REMOVE DEPENDENCIES #================================================= +ynh_script_progression --message="Removing dependencies..." --time --weight=1 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -28,6 +37,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Removing nginx web server configuration..." --time --weight=1 # Remove the dedicated nginx config ynh_remove_nginx_config @@ -38,12 +48,15 @@ ynh_remove_nginx_config if yunohost firewall list | grep -q "\- $port$" then - echo "Close port $port" >&2 - yunohost firewall disallow TCP $port 2>&1 + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port fi -sudo apt-get remove -y --purge webmin -sudo rm -r /etc/apt/sources.list.d/webmin.list +#================================================= +# SPECIFIC REMOVE +#================================================= +apt-get remove -y --purge webmin +rm -r /etc/apt/sources.list.d/webmin.list diff --git a/scripts/restore b/scripts/restore index 9063938..232f4dc 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -23,20 +24,22 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -port=$(ynh_app_setting_get $app port) +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) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= +ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 -ynh_webpath_available $domain $path_url \ - || ynh_die "Path not available: ${domain}${path_url}" +ynh_webpath_available --domain=$domain --path_url=$path_url \ + || ynh_die --message="Path not available: ${domain}${path_url}" #================================================= # STANDARD RESTORATION STEPS @@ -44,7 +47,8 @@ ynh_webpath_available $domain $path_url \ # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" + #================================================= # SPECIFIC RESTORATION @@ -53,7 +57,7 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # Define and install dependencies -ynh_install_app_dependencies perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python +ynh_install_app_dependencies $pkg_dependencies @@ -61,12 +65,12 @@ sudo sh -c "echo 'deb http://download.webmin.com/download/repository sarge contr sudo sh -c "echo 'deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib' >> /etc/apt/sources.list.d/webmin.list" -sudo wget http://www.webmin.com/jcameron-key.asc -sudo apt-key add jcameron-key.asc -sudo rm jcameron-key.asc +wget http://www.webmin.com/jcameron-key.asc +apt-key add jcameron-key.asc +rm jcameron-key.asc -sudo apt-get update -sudo apt-get install -y webmin +apt-get update +apt-get install -y webmin #================================================= # MODIFY A CONFIG FILE @@ -75,9 +79,8 @@ sudo apt-get install -y webmin ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -ynh_replace_string "port=10000" "port=$port" "/etc/webmin/miniserv.conf" -ynh_replace_string "listen=10000" "listen=$port" "/etc/webmin/miniserv.conf" - +ynh_replace_string --match_string="port=10000" --replace_string"port=$port" --target_file="/etc/webmin/miniserv.conf" +ynh_replace_string --match_string="listen=10000" --replace_string"listen=$port" --target_file="/etc/webmin/miniserv.conf" #================================================= # SETUP SSOWAT #================================================= @@ -89,6 +92,16 @@ yunohost app addaccess --users=$admin $app #================================================= # RELOAD NGINX AND START WEBMIN #================================================= -systemctl enable webmin -systemctl restart webmin -sudo service nginx reload +ynh_script_progression --message="Starting webmin web server..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action=enable + +ynh_systemd_action --service_name=$app --action=start + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Restoration completed for $app" --time --last diff --git a/scripts/upgrade b/scripts/upgrade index 2567329..78960e4 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,13 +12,14 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get $app domain) -path_url=$(ynh_app_setting_get $app path) -admin=$(ynh_app_setting_get $app admin) -port=$(ynh_app_setting_get $app port) +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) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK THE PATH @@ -30,15 +31,24 @@ path_url=$(ynh_normalize_url_path $path_url) #================================================= # NGINX CONFIGURATION #================================================= +ynh_script_progression --message="Upgrading nginx web server configuration..." --time --weight=1 # Create a dedicated nginx config ynh_add_nginx_config +#================================================= + STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # UPGRADE DEPENDENCIES #================================================= +ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 -ynh_install_app_dependencies perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python +ynh_install_app_dependencies $pkg_dependencies #================================================= # SPECIFIC UPGRADE @@ -47,9 +57,9 @@ ynh_install_app_dependencies perl libnet-ssleay-perl openssl libauthen-pam-perl sudo sh -c "echo 'deb http://download.webmin.com/download/repository sarge contrib' > /etc/apt/sources.list.d/webmin.list" sudo sh -c "echo 'deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib' >> /etc/apt/sources.list.d/webmin.list" -sudo wget http://www.webmin.com/jcameron-key.asc -sudo apt-key add jcameron-key.asc -sudo rm jcameron-key.asc +wget http://www.webmin.com/jcameron-key.asc +apt-key add jcameron-key.asc +rm jcameron-key.asc sudo apt-get update sudo apt-get upgrade @@ -67,8 +77,8 @@ ynh_store_file_checksum "/etc/webmin/miniserv.conf" if yunohost firewall list | grep -q "\- $port$" then - echo "Close port $port" >&2 - yunohost firewall disallow TCP $port 2>&1 + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port fi #================================================= @@ -81,8 +91,14 @@ yunohost app addaccess --users=$admin $app #================================================= # RELOAD NGINX AND START WEBMIN #================================================= -systemctl enable webmin -systemctl restart webmin -sudo service nginx reload +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +ynh_script_progression --message="Starting webmin web server..." --time --weight=1 +ynh_systemd_action --service_name=$app --action=enable + +ynh_systemd_action --service_name=$app --action=start +