mirror of
https://github.com/YunoHost-Apps/shellinabox_ynh.git
synced 2024-09-03 20:26:12 +02:00
Refactoring
This commit is contained in:
parent
ba771d23f4
commit
a94b50de8b
10 changed files with 262 additions and 135 deletions
|
@ -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:
|
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
|
### Install
|
||||||
|
|
||||||
|
|
|
@ -13,21 +13,21 @@
|
||||||
upgrade=1
|
upgrade=1
|
||||||
backup_restore=1
|
backup_restore=1
|
||||||
multi_instance=0
|
multi_instance=0
|
||||||
wrong_user=1
|
|
||||||
wrong_path=1
|
|
||||||
incorrect_path=1
|
incorrect_path=1
|
||||||
corrupt_source=0
|
|
||||||
fail_download_source=0
|
|
||||||
port_already_use=0
|
port_already_use=0
|
||||||
final_path_already_use=0
|
change_url=0
|
||||||
;;; Levels
|
;;; Levels
|
||||||
Level 1=auto
|
Level 1=auto
|
||||||
Level 2=auto
|
Level 2=auto
|
||||||
Level 3=auto
|
Level 3=auto
|
||||||
Level 4=na
|
Level 4=na
|
||||||
Level 5=auto
|
# Level 5: https://github.com/YunoHost-Apps/shellinabox_ynh/issues/3
|
||||||
|
Level 5=1
|
||||||
Level 6=auto
|
Level 6=auto
|
||||||
Level 7=auto
|
Level 7=auto
|
||||||
Level 8=0
|
Level 8=0
|
||||||
Level 9=0
|
Level 9=0
|
||||||
Level 10=0
|
Level 10=0
|
||||||
|
;;; Options
|
||||||
|
Email=
|
||||||
|
Notification=none
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
location PATHTOCHANGE {
|
location __PATH__ {
|
||||||
|
|
||||||
if ($scheme = http) {
|
if ($scheme = http) {
|
||||||
rewrite ^ https://$server_name$request_uri? permanent;
|
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_set_header Host $host;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
tcp_nodelay on;
|
tcp_nodelay on;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
SHELLINABOX_DAEMON_START=1
|
SHELLINABOX_DAEMON_START=1
|
||||||
|
|
||||||
# TCP port that shellinboxd's webserver listens on
|
# 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
|
# Parameters that are managed by the system and usually should not need
|
||||||
# changing:
|
# changing:
|
||||||
|
@ -16,4 +16,3 @@ SHELLINABOX_PORT=4200
|
||||||
# Beeps are disabled because of reports of the VLC plugin crashing
|
# Beeps are disabled because of reports of the VLC plugin crashing
|
||||||
# Firefox on Linux/x86_64.
|
# Firefox on Linux/x86_64.
|
||||||
SHELLINABOX_ARGS="--no-beep --localhost-only"
|
SHELLINABOX_ARGS="--no-beep --localhost-only"
|
||||||
|
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
"name": "Shell In A Box",
|
"name": "Shell In A Box",
|
||||||
"id": "shellinabox",
|
"id": "shellinabox",
|
||||||
"packaging_format": 1,
|
"packaging_format": 1,
|
||||||
"version": "1.1.0",
|
|
||||||
"license": "free",
|
|
||||||
"requirements": {
|
|
||||||
"yunohost": ">> 2.3.15"
|
|
||||||
},
|
|
||||||
"description": {
|
"description": {
|
||||||
"en": "Web based AJAX terminal emulator",
|
"en": "Web based AJAX terminal emulator",
|
||||||
"fr": "Émulateur de terminal web"
|
"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",
|
||||||
"maintainer": {
|
"maintainer": {
|
||||||
"name": "kload",
|
"name": "kload",
|
||||||
"email": "kload@kload.fr"
|
"email": "kload@kload.fr"
|
||||||
},
|
},
|
||||||
|
"requirements": {
|
||||||
|
"yunohost": ">= 2.7.2"
|
||||||
|
},
|
||||||
"multi_instance": false,
|
"multi_instance": false,
|
||||||
"services": [
|
"services": [
|
||||||
"nginx",
|
"nginx",
|
||||||
|
|
|
@ -1,21 +1,39 @@
|
||||||
#!/bin/bash
|
#!/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
|
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
|
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
|
# STANDARD BACKUP STEPS
|
||||||
backup_dir=$YNH_APP_BACKUP_DIR
|
#=================================================
|
||||||
|
# BACKUP THE APP MAIN DIR
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Copy the conf files
|
ynh_backup "/etc/shellinabox"
|
||||||
sudo mkdir -p ./conf
|
ynh_backup "/etc/default/shellinabox"
|
||||||
ynh_backup "/etc/default/${app}" "./conf/default_${app}"
|
|
||||||
ynh_backup "/etc/nginx/conf.d/${domain}.d/${app}.conf" ./conf/nginx.conf
|
#=================================================
|
||||||
|
# BACKUP THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
|
|
111
scripts/install
111
scripts/install
|
@ -1,40 +1,99 @@
|
||||||
#!/bin/bash
|
#!/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
|
domain=$YNH_APP_ARG_DOMAIN
|
||||||
path=$YNH_APP_ARG_PATH
|
path_url=$YNH_APP_ARG_PATH
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Check domain/path availability
|
#=================================================
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
#=================================================
|
||||||
|
|
||||||
# Check port availability
|
# Normalize the url path syntax
|
||||||
sudo yunohost app checkport 4200 \
|
path_url=$(ynh_normalize_url_path $path_url)
|
||||||
|| ynh_die "Port not available: 4200"
|
|
||||||
|
|
||||||
# Remove trailing "/" for next commands
|
# Check web path availability
|
||||||
if [[ ! "$path" == "/" ]]; then
|
ynh_webpath_available $domain $path_url
|
||||||
path=${path%/}
|
# Register (book) web path
|
||||||
fi
|
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
|
ynh_app_setting_set $app domain $domain
|
||||||
sudo yunohost service add shellinabox
|
ynh_app_setting_set $app path $path_url
|
||||||
|
|
||||||
# Copy shellinabox default configuration and restart
|
#=================================================
|
||||||
sudo cp ../conf/shellinabox /etc/default/shellinabox
|
# STANDARD MODIFICATIONS
|
||||||
sudo service shellinabox restart
|
#=================================================
|
||||||
|
# FIND AND OPEN A PORT
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Configure Nginx and reload
|
# Find a free port
|
||||||
sed -i "s@PATHTOCHANGE@$path@g" ../conf/nginx.conf
|
port=$(ynh_find_port 4200)
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shellinabox.conf
|
ynh_app_setting_set $app port $port
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
#=================================================
|
||||||
|
# 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
|
||||||
|
|
|
@ -1,29 +1,43 @@
|
||||||
#!/bin/bash
|
#!/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
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Get multi-instances specific variables
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
port=$(ynh_app_setting_get $app port)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
|
||||||
|
|
||||||
# Stop and remove shellinabox
|
#=================================================
|
||||||
sudo systemctl stop shellinabox || echo "ShellInABox already stopped"
|
# STANDARD REMOVE
|
||||||
sudo apt-get remove --purge -y -qq shellinabox || echo "ShellInABox already uninstalled"
|
#=================================================
|
||||||
|
# REMOVE SERVICE FROM ADMIN PANEL
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Remove service
|
if yunohost service status | grep -q $app
|
||||||
sudo yunohost service remove shellinabox
|
then
|
||||||
|
echo "Remove $app service"
|
||||||
|
yunohost service remove $app
|
||||||
|
fi
|
||||||
|
|
||||||
# Remove Shell In A Box configuration
|
#=================================================
|
||||||
sudo rm -f "/etc/default/${app}"
|
# REMOVE SHELLINABOX
|
||||||
# Remove Nginx proxy configuration
|
#=================================================
|
||||||
[[ -n $domain ]] && sudo rm -f "/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
||||||
|
|
||||||
# Restart nginx
|
ynh_package_autopurge shellinabox
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
#=================================================
|
||||||
|
# REMOVE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
# Remove the dedicated nginx config
|
||||||
|
ynh_remove_nginx_config
|
||||||
|
|
|
@ -1,59 +1,64 @@
|
||||||
#!/bin/bash
|
#!/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
|
set -eu
|
||||||
|
|
||||||
# Source app helpers
|
#=================================================
|
||||||
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Get multi-instances specific variables
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
path=$(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
|
ynh_webpath_available $domain $path_url \
|
||||||
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|| ynh_die "Path not available: ${domain}${path_url}"
|
||||||
|| ynh_die "Path not available: ${domain}${path}"
|
|
||||||
|
|
||||||
# Check port availability
|
#=================================================
|
||||||
sudo yunohost app checkport 4200 \
|
# STANDARD RESTORATION STEPS
|
||||||
|| ynh_die "Port not available: 4200"
|
#=================================================
|
||||||
|
# RESTORE THE NGINX CONFIGURATION
|
||||||
|
#=================================================
|
||||||
|
|
||||||
# Check configuration files
|
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||||
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
|
|
||||||
|
|
||||||
# if shellainbox is installed
|
#=================================================
|
||||||
shellinabox_bin="/usr/bin/shellinaboxd"
|
# INSTALL SHELLINABOX
|
||||||
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
|
|
||||||
|
|
||||||
sudo cp -a "./conf/default_${app}" "${shellinabox_conf}"
|
ynh_package_update
|
||||||
|
ynh_package_install shellinabox
|
||||||
|
|
||||||
# Add service into YunoHost
|
#=================================================
|
||||||
sudo yunohost service add shellinabox
|
# RESTORE THE APP MAIN DIR
|
||||||
sudo service shellinabox restart
|
#=================================================
|
||||||
fi
|
|
||||||
|
|
||||||
# Restore configuration files
|
ynh_restore_file "/etc/shellinabox"
|
||||||
sudo cp -a ./conf/nginx.conf "${nginx_conf}"
|
ynh_restore_file "/etc/default/shellinabox"
|
||||||
|
systemctl restart shellinabox
|
||||||
|
|
||||||
# Reload service
|
#=================================================
|
||||||
sudo systemctl reload nginx
|
# GENERIC FINALIZATION
|
||||||
sudo yunohost app ssowatconf
|
#=================================================
|
||||||
|
# RELOAD NGINX
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
systemctl reload nginx
|
||||||
|
|
|
@ -1,31 +1,61 @@
|
||||||
#!/bin/bash
|
#!/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
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
# Get multi-instances specific variables
|
#=================================================
|
||||||
|
# LOAD SETTINGS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
app=$YNH_APP_INSTANCE_NAME
|
app=$YNH_APP_INSTANCE_NAME
|
||||||
|
|
||||||
# Retrieve arguments
|
domain=$(ynh_app_setting_get $app domain)
|
||||||
domain=$(ynh_app_setting_get "$app" domain)
|
path_url=$(ynh_app_setting_get $app path)
|
||||||
path=$(ynh_app_setting_get "$app" path)
|
port=$(ynh_app_setting_get $app port)
|
||||||
|
|
||||||
# Remove trailing "/" for next commands
|
#=================================================
|
||||||
if [[ ! "$path" == "/" ]]; then
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
path=${path%/}
|
#=================================================
|
||||||
|
|
||||||
|
# If port doesn't exist, create it
|
||||||
|
if [ -z $port ]; then
|
||||||
|
port=4200
|
||||||
|
ynh_app_setting_set $app port $port
|
||||||
fi
|
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
|
ynh_backup_before_upgrade # Backup the current version of the app
|
||||||
sudo cp ../conf/shellinabox /etc/default/shellinabox
|
ynh_clean_setup () {
|
||||||
sudo service shellinabox restart
|
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
|
# CHECK THE PATH
|
||||||
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/shellinabox.conf
|
#=================================================
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
# 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
|
||||||
|
|
Loading…
Reference in a new issue