diff --git a/README.md b/README.md index fcb88c9..e4b09e5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Shell In A Box implements a web server that can export arbitrary command line tools to a web based terminal emulator. This emulator is accessible to any JavaScript and CSS enabled web browser and does not require any additional browser plugins. Most typically, login shells would be exported this way: -Source: [code.google.com/shellinabox/](https://code.google.com/p/shellinabox/) +https://github.com/shellinabox/shellinabox ### Install @@ -10,4 +10,4 @@ Source: [code.google.com/shellinabox/](https://code.google.com/p/shellinabox/) ### Update -`$ sudo yunohost app upgrade --verbose spip -u https://github.com/YunoHost-Apps/shellinabox_ynh.git` \ No newline at end of file +`$ sudo yunohost app upgrade --verbose shellinabox -u https://github.com/YunoHost-Apps/shellinabox_ynh.git` diff --git a/check_process b/check_process index b86cb88..f6eb3c3 100644 --- a/check_process +++ b/check_process @@ -13,21 +13,21 @@ upgrade=1 backup_restore=1 multi_instance=0 - wrong_user=1 - wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 port_already_use=0 - final_path_already_use=0 + change_url=0 ;;; Levels Level 1=auto Level 2=auto Level 3=auto Level 4=na - Level 5=auto +# Level 5: https://github.com/YunoHost-Apps/shellinabox_ynh/issues/3 + Level 5=1 Level 6=auto Level 7=auto Level 8=0 Level 9=0 Level 10=0 +;;; Options +Email= +Notification=none diff --git a/conf/nginx.conf b/conf/nginx.conf index f7e570e..374702d 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,8 +1,10 @@ -location PATHTOCHANGE { +location __PATH__ { + if ($scheme = http) { rewrite ^ https://$server_name$request_uri? permanent; } - proxy_pass http://127.0.0.1:4200/; + + proxy_pass http://127.0.0.1:__PORT__/; proxy_set_header Host $host; proxy_buffering off; tcp_nodelay on; diff --git a/conf/shellinabox b/conf/shellinabox index 7e8a865..5d0bbea 100644 --- a/conf/shellinabox +++ b/conf/shellinabox @@ -2,7 +2,7 @@ SHELLINABOX_DAEMON_START=1 # TCP port that shellinboxd's webserver listens on -SHELLINABOX_PORT=4200 +SHELLINABOX_PORT=__PORT__ # Parameters that are managed by the system and usually should not need # changing: @@ -16,4 +16,3 @@ SHELLINABOX_PORT=4200 # Beeps are disabled because of reports of the VLC plugin crashing # Firefox on Linux/x86_64. SHELLINABOX_ARGS="--no-beep --localhost-only" - diff --git a/manifest.json b/manifest.json index c2e6528..c1962c4 100644 --- a/manifest.json +++ b/manifest.json @@ -2,20 +2,20 @@ "name": "Shell In A Box", "id": "shellinabox", "packaging_format": 1, - "version": "1.1.0", - "license": "free", - "requirements": { - "yunohost": ">> 2.3.15" - }, "description": { "en": "Web based AJAX terminal emulator", "fr": "Émulateur de terminal web" }, - "url": "https://code.google.com/p/shellinabox/", + "version": "1.1.0", + "url": "https://github.com/shellinabox/shellinabox", + "license": "GPL-2.0", "maintainer": { "name": "kload", "email": "kload@kload.fr" }, + "requirements": { + "yunohost": ">= 2.7.2" + }, "multi_instance": false, "services": [ "nginx", diff --git a/scripts/backup b/scripts/backup index 9c4a1f5..a1429dc 100644 --- a/scripts/backup +++ b/scripts/backup @@ -1,21 +1,39 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error set -eu -# Source YNH helpers -. /usr/share/yunohost/helpers +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= -# Get multi-instances specific variables app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get "$app" domain) +domain=$(ynh_app_setting_get $app domain) -# Backup directory location for the app from where the script is executed and -# which will be compressed afterward -backup_dir=$YNH_APP_BACKUP_DIR +#================================================= +# STANDARD BACKUP STEPS +#================================================= +# BACKUP THE APP MAIN DIR +#================================================= -# Copy the conf files -sudo mkdir -p ./conf -ynh_backup "/etc/default/${app}" "./conf/default_${app}" -ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf \ No newline at end of file +ynh_backup "/etc/shellinabox" +ynh_backup "/etc/default/shellinabox" + +#================================================= +# BACKUP THE NGINX CONFIGURATION +#================================================= + +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" diff --git a/scripts/install b/scripts/install index 5db480b..ef928f0 100644 --- a/scripts/install +++ b/scripts/install @@ -1,40 +1,99 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -source /usr/share/yunohost/helpers # Source app helpers +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= -# Retrieve arguments domain=$YNH_APP_ARG_DOMAIN -path=$YNH_APP_ARG_PATH +path_url=$YNH_APP_ARG_PATH app=$YNH_APP_INSTANCE_NAME -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= -# Check port availability -sudo yunohost app checkport 4200 \ - || ynh_die "Port not available: 4200" +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path $path_url) -# Remove trailing "/" for next commands -if [[ ! "$path" == "/" ]]; then - path=${path%/} -fi +# Check web path availability +ynh_webpath_available $domain $path_url +# Register (book) web path +ynh_webpath_register $app $domain $path_url -sudo apt-get update -qq -sudo apt-get install shellinabox -y -qq +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= -# Add service into YunoHost -sudo yunohost service add shellinabox +ynh_app_setting_set $app domain $domain +ynh_app_setting_set $app path $path_url -# Copy shellinabox default configuration and restart -sudo cp ../conf/shellinabox /etc/default/shellinabox -sudo service shellinabox restart +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= -# Configure Nginx and reload -sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shellinabox.conf -sudo systemctl reload nginx +# Find a free port +port=$(ynh_find_port 4200) +ynh_app_setting_set $app port $port + +#================================================= +# INSTALL SHELLINABOX +#================================================= + +ynh_package_update +ynh_package_install shellinabox + +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# SPECIFIC SETUP +#================================================= +# CONFIGURE SHELLINABOX +#================================================= + +cp ../conf/shellinabox /etc/default/shellinabox +ynh_replace_string "__PORT__" "$port" "/etc/default/shellinabox" +systemctl restart shellinabox + +#================================================= +# STORE THE CHECKSUM OF THE CONFIG FILE +#================================================= + +# Calculate and store the config file checksum into the app settings +ynh_store_file_checksum "/etc/default/shellinabox" + +#================================================= +# GENERIC FINALIZATION +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/remove b/scripts/remove index d48d9f2..0a055a2 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,29 +1,43 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -u +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers source /usr/share/yunohost/helpers -# Get multi-instances specific variables +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +domain=$(ynh_app_setting_get $app domain) +port=$(ynh_app_setting_get $app port) -# Stop and remove shellinabox -sudo systemctl stop shellinabox || echo "ShellInABox already stopped" -sudo apt-get remove --purge -y -qq shellinabox || echo "ShellInABox already uninstalled" +#================================================= +# STANDARD REMOVE +#================================================= +# REMOVE SERVICE FROM ADMIN PANEL +#================================================= -# Remove service -sudo yunohost service remove shellinabox +if yunohost service status | grep -q $app +then + echo "Remove $app service" + yunohost service remove $app +fi -# Remove Shell In A Box configuration -sudo rm -f "/etc/default/${app}" -# Remove Nginx proxy configuration -[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf" +#================================================= +# REMOVE SHELLINABOX +#================================================= -# Restart nginx -sudo systemctl reload nginx +ynh_package_autopurge shellinabox + +#================================================= +# REMOVE NGINX CONFIGURATION +#================================================= + +# Remove the dedicated nginx config +ynh_remove_nginx_config diff --git a/scripts/restore b/scripts/restore index e78bdf4..2709165 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,59 +1,70 @@ #!/bin/bash -# causes the shell to exit if any subcommand or pipeline returns a non-zero status +#================================================= +# GENERIC START +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit on command errors and treat access to unset variables as an error set -eu -# Source app helpers +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + source /usr/share/yunohost/helpers -# Get multi-instances specific variables +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +port=$(ynh_app_setting_get $app port) -# Remove trailing slash to path -path=${path%/} +#================================================= +# CHECK IF THE APP CAN BE RESTORED +#================================================= -# Check domain/path availability -sudo yunohost app checkurl "${domain}${path}" -a "$app" \ - || ynh_die "Path not available: ${domain}${path}" +ynh_webpath_available $domain $path_url \ + || ynh_die "Path not available: ${domain}${path_url}" -# Check port availability -sudo yunohost app checkport 4200 \ - || ynh_die "Port not available: 4200" +#================================================= +# STANDARD RESTORATION STEPS +#================================================= +# RESTORE THE NGINX CONFIGURATION +#================================================= -# Check configuration files -nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf" -if [ -f $nginx_conf ]; then - ynh_die "The NGINX configuration already exists at '${nginx_conf}'. - You should safely delete it before restoring this app." -fi -shellinabox_conf="/etc/default/${app}" -if [ -f $shellinabox_conf ]; then - ynh_die "The shellinabox configuration already exists at '${shellinabox_conf}'. - You should safely delete it before restoring this app." -fi +ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" -# if shellainbox is installed -shellinabox_bin="/usr/bin/shellinaboxd" -if [ -f $shellinabox_bin ]; then - ynh_die "Good! The shellinabox is installed" -else - sudo apt-get update -qq - sudo apt-get install shellinabox -y -qq +#================================================= +# INSTALL SHELLINABOX +#================================================= - sudo cp -a "./conf/default_${app}" "${shellinabox_conf}" +ynh_package_update +ynh_package_install shellinabox - # Add service into YunoHost - sudo yunohost service add shellinabox - sudo service shellinabox restart -fi +#================================================= +# RESTORE THE APP MAIN DIR +#================================================= -# Restore configuration files -sudo cp -a ./conf/nginx.conf "${nginx_conf}" +ynh_restore_file "/etc/shellinabox" +ynh_restore_file "/etc/default/shellinabox" +systemctl restart shellinabox -# Reload service -sudo systemctl reload nginx -sudo yunohost app ssowatconf +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= + +yunohost service add $app + +#================================================= +# GENERIC FINALIZATION +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx diff --git a/scripts/upgrade b/scripts/upgrade index c8b336f..8815730 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,31 +1,61 @@ #!/bin/bash -# Exit on command errors and treat unset variables as an error -set -eu +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Source app helpers source /usr/share/yunohost/helpers -# Get multi-instances specific variables +#================================================= +# LOAD SETTINGS +#================================================= + app=$YNH_APP_INSTANCE_NAME -# Retrieve arguments -domain=$(ynh_app_setting_get "$app" domain) -path=$(ynh_app_setting_get "$app" path) +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +port=$(ynh_app_setting_get $app port) -# Remove trailing "/" for next commands -if [[ ! "$path" == "/" ]]; then - path=${path%/} +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= + +# If port doesn't exist, create it +if [ -z $port ]; then + port=4200 + ynh_app_setting_set $app port $port fi -sudo apt-get update -qq -sudo apt-get install shellinabox -y -qq +#================================================= +# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP +#================================================= -# Copy shellinabox default configuration and restart -sudo cp ../conf/shellinabox /etc/default/shellinabox -sudo service shellinabox restart +ynh_backup_before_upgrade # Backup the current version of the app +ynh_clean_setup () { + ynh_restore_upgradebackup # restore it if the upgrade fails +} +ynh_abort_if_errors # Exit if an error occurs during the execution of the script -# Configure Nginx and reload -sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf -sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shellinabox.conf -sudo systemctl reload nginx +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# NGINX CONFIGURATION +#================================================= + +# Create a dedicated nginx config +ynh_add_nginx_config + +#================================================= +# RELOAD NGINX +#================================================= + +systemctl reload nginx