Update 'root/usr/libexec/apps/nodered/nodered.sh'

main
ben 1 year ago
parent fdba7ecee9
commit e40a2f90cf

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

Loading…
Cancel
Save