|
|
|
@ -1,18 +1,21 @@
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
APP_NAME="nodered"
|
|
|
|
|
|
|
|
|
|
ACTION=${1}
|
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
|
|
get_image() {
|
|
|
|
|
IMAGE_NAME=$(uci get nodered.@nodered[0].image_name 2>/dev/null)
|
|
|
|
|
do_install_detail
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_install_detail() {
|
|
|
|
|
local config=$(uci get nodered.@nodered[0].config_path 2>/dev/null)
|
|
|
|
|
local port=$(uci get nodered.@nodered[0].port 2>/dev/null)
|
|
|
|
|
local IMAGE_NAME=$(uci get nodered.@nodered[0].image_name 2>/dev/null)
|
|
|
|
|
local username=$(uci get nodered.@nodered[0].username 2>/dev/null)
|
|
|
|
|
local password=$(uci get nodered.@nodered[0].password 2>/dev/null)
|
|
|
|
|
local config port IMAGE_NAME username password LAN_IP
|
|
|
|
|
config=$(uci get nodered.@nodered[0].config_path 2>/dev/null)
|
|
|
|
|
port=$(uci get nodered.@nodered[0].port 2>/dev/null)
|
|
|
|
|
IMAGE_NAME=$(uci get nodered.@nodered[0].image_name 2>/dev/null)
|
|
|
|
|
username=$(uci get nodered.@nodered[0].username 2>/dev/null)
|
|
|
|
|
password=$(uci get nodered.@nodered[0].password 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
GEN_PASS=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c14; echo)
|
|
|
|
|
GEN_PASS2=$(< /dev/urandom tr -dc A-Za-z0-9 2>/dev/null | head -c14; echo)
|
|
|
|
@ -49,7 +52,7 @@ EOF
|
|
|
|
|
docker-compose -f /opt/docker2/compose/nodered-app/docker-compose.yml up -d
|
|
|
|
|
|
|
|
|
|
uci add shortcutmenu lists
|
|
|
|
|
uci set shortcutmenu.@lists[-1].webname="$IMAGE_NAME"
|
|
|
|
|
uci set shortcutmenu.@lists[-1].webname="$APP_NAME"
|
|
|
|
|
uci set shortcutmenu.@lists[-1].weburl="$LAN_IP:$port"
|
|
|
|
|
uci set shortcutmenu.@lists[-1].webpath="/"
|
|
|
|
|
uci commit shortcutmenu
|
|
|
|
@ -66,13 +69,14 @@ usage() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case ${ACTION} in
|
|
|
|
|
"install"|"upgrade")
|
|
|
|
|
get_image
|
|
|
|
|
"install")
|
|
|
|
|
do_install_detail
|
|
|
|
|
;;
|
|
|
|
|
"upgrade")
|
|
|
|
|
docker-compose -f /opt/docker2/compose/nodered-app/docker-compose.yml up -d
|
|
|
|
|
;;
|
|
|
|
|
"rm")
|
|
|
|
|
get_image
|
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}')
|
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}')
|
|
|
|
|
echo "Stopping and removing containers..."
|
|
|
|
|
for ID in $CONTAINER_IDS; do
|
|
|
|
|
docker stop $ID
|
|
|
|
@ -81,20 +85,17 @@ case ${ACTION} in
|
|
|
|
|
docker rmi -f $IMAGE_NAME
|
|
|
|
|
;;
|
|
|
|
|
"start"|"stop"|"restart")
|
|
|
|
|
get_image
|
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.ID}}')
|
|
|
|
|
CONTAINER_IDS=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.ID}}')
|
|
|
|
|
for ID in $CONTAINER_IDS; do
|
|
|
|
|
docker ${ACTION} ${ID}
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
"status")
|
|
|
|
|
get_image
|
|
|
|
|
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.Names}}')
|
|
|
|
|
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.Names}}')
|
|
|
|
|
docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Status}}'
|
|
|
|
|
;;
|
|
|
|
|
"port")
|
|
|
|
|
get_image
|
|
|
|
|
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${IMAGE_NAME}" --format '{{.Names}}')
|
|
|
|
|
CONTAINER_NAMES=$(docker ps -a --filter "ancestor=${APP_NAME}" --format '{{.Names}}')
|
|
|
|
|
docker ps --all -f "name=${CONTAINER_NAMES}" --format '{{.Ports}}' | grep -om1 '0.0.0.0:[0-9]*' | sed 's/0.0.0.0://'
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|