zwave-js-ui-v5.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. function header_info {
  7. clear
  8. cat <<"EOF"
  9. _____ _______ __ ______
  10. /__ /_ ______ __v5 _____ / / ___/ / / / / _/
  11. / /| | /| / / __ `/ | / / _ \ __ / /\__ \ / / / // /
  12. / /_| |/ |/ / /_/ /| |/ / __/ / /_/ /___/ / / /_/ // /
  13. /____/__/|__/\__,_/ |___/\___/ \____//____/ \____/___/
  14. EOF
  15. }
  16. header_info
  17. echo -e "Loading..."
  18. APP="Zwave-JS-UI"
  19. var_disk="4"
  20. var_cpu="2"
  21. var_ram="1024"
  22. var_os="debian"
  23. var_version="11"
  24. NSAPP=$(echo ${APP,,} | tr -d ' ')
  25. var_install="${NSAPP}-v5-install"
  26. INTEGER='^[0-9]+$'
  27. YW=$(echo "\033[33m")
  28. BL=$(echo "\033[36m")
  29. RD=$(echo "\033[01;31m")
  30. BGN=$(echo "\033[4;92m")
  31. GN=$(echo "\033[1;92m")
  32. DGN=$(echo "\033[32m")
  33. CL=$(echo "\033[m")
  34. BFR="\\r\\033[K"
  35. HOLD="-"
  36. CM="${GN}✓${CL}"
  37. CROSS="${RD}✗${CL}"
  38. set -Eeuo pipefail
  39. trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
  40. function error_handler() {
  41. local exit_code="$?"
  42. local line_number="$1"
  43. local command="$2"
  44. local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
  45. echo -e "\n$error_message\n"
  46. }
  47. function msg_info() {
  48. local msg="$1"
  49. echo -ne " ${HOLD} ${YW}${msg}..."
  50. }
  51. function msg_ok() {
  52. local msg="$1"
  53. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  54. }
  55. function msg_error() {
  56. local msg="$1"
  57. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  58. }
  59. function PVE_CHECK() {
  60. if [ $(pveversion | grep -c "pve-manager/7\.[0-9]") -eq 0 ]; then
  61. echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
  62. echo -e "Requires PVE Version 7.0 or higher"
  63. echo -e "Exiting..."
  64. sleep 2
  65. exit
  66. fi
  67. }
  68. function ARCH_CHECK() {
  69. if [ "$(dpkg --print-architecture)" != "amd64" ]; then
  70. echo -e "\n ${CROSS} This script will not work with PiMox! \n"
  71. echo -e "Exiting..."
  72. sleep 2
  73. exit
  74. fi
  75. }
  76. function default_settings() {
  77. echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}"
  78. CT_TYPE="0"
  79. echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  80. PW=""
  81. echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  82. CT_ID=$NEXTID
  83. echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  84. HN=$NSAPP
  85. echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  86. DISK_SIZE="$var_disk"
  87. echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  88. CORE_COUNT="$var_cpu"
  89. echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  90. RAM_SIZE="$var_ram"
  91. echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  92. BRG="vmbr0"
  93. echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  94. NET=dhcp
  95. echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  96. GATE=""
  97. echo -e "${DGN}Disable IPv6: ${BGN}No${CL}"
  98. DISABLEIP6="no"
  99. echo -e "${DGN}Using Interface MTU Size: ${BGN}Default${CL}"
  100. MTU=""
  101. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  102. SD=""
  103. echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}"
  104. NS=""
  105. echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  106. MAC=""
  107. echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  108. VLAN=""
  109. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  110. SSH="no"
  111. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  112. VERB="no"
  113. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  114. }
  115. function advanced_settings() {
  116. CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 10 58 2 \
  117. "1" "Unprivileged" OFF \
  118. "0" "Privileged" ON \
  119. 3>&1 1>&2 2>&3)
  120. exitstatus=$?
  121. if [ $exitstatus = 0 ]; then
  122. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  123. fi
  124. PW1=$(whiptail --inputbox "Set Root Password (needed for root ssh access)" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  125. exitstatus=$?
  126. if [ $exitstatus = 0 ]; then
  127. if [ -z $PW1 ]; then
  128. PW1="Automatic Login" PW=" "
  129. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  130. else
  131. PW="-password $PW1"
  132. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  133. fi
  134. fi
  135. CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  136. exitstatus=$?
  137. if [ -z $CT_ID ]; then
  138. CT_ID="$NEXTID"
  139. echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  140. else
  141. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi
  142. fi
  143. CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  144. exitstatus=$?
  145. if [ -z $CT_NAME ]; then
  146. HN="$NSAPP"
  147. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  148. else
  149. if [ $exitstatus = 0 ]; then
  150. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  151. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  152. fi
  153. fi
  154. DISK_SIZE=$(whiptail --inputbox "Set Disk Size in GB" 8 58 $var_disk --title "DISK SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  155. exitstatus=$?
  156. if [ -z $DISK_SIZE ]; then
  157. DISK_SIZE="$var_disk"
  158. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  159. else
  160. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi
  161. if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  162. echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"
  163. advanced_settings
  164. fi
  165. fi
  166. CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  167. exitstatus=$?
  168. if [ -z $CORE_COUNT ]; then
  169. CORE_COUNT="$var_cpu"
  170. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  171. else
  172. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi
  173. fi
  174. RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  175. exitstatus=$?
  176. if [ -z $RAM_SIZE ]; then
  177. RAM_SIZE="$var_ram"
  178. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  179. else
  180. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi
  181. fi
  182. BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  183. exitstatus=$?
  184. if [ -z $BRG ]; then
  185. BRG="vmbr0"
  186. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  187. else
  188. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi
  189. fi
  190. NET=$(whiptail --inputbox "Set a Static IPv4 CIDR Address(/24)" 8 58 dhcp --title "IP ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  191. exitstatus=$?
  192. if [ -z $NET ]; then
  193. NET="dhcp"
  194. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  195. else
  196. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi
  197. fi
  198. GATE1=$(whiptail --inputbox "Set a Gateway IP (mandatory if Static IP was used)" 8 58 --title "GATEWAY IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  199. exitstatus=$?
  200. if [ $exitstatus = 0 ]; then
  201. if [ -z $GATE1 ]; then
  202. GATE1="Default" GATE=""
  203. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  204. else
  205. GATE=",gw=$GATE1"
  206. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  207. fi
  208. fi
  209. if (whiptail --defaultno --title "IPv6" --yesno "Disable IPv6?" 10 58); then
  210. echo -e "${DGN}Disable IPv6: ${BGN}Yes${CL}"
  211. DISABLEIP6="yes"
  212. else
  213. echo -e "${DGN}Disable IPv6: ${BGN}No${CL}"
  214. DISABLEIP6="no"
  215. fi
  216. MTU1=$(whiptail --inputbox "Set Interface MTU Size (leave blank for default)" 8 58 --title "MTU SIZE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  217. exitstatus=$?
  218. if [ $exitstatus = 0 ]; then
  219. if [ -z $MTU1 ]; then
  220. MTU1="Default" MTU=""
  221. echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
  222. else
  223. MTU=",mtu=$MTU1"
  224. echo -e "${DGN}Using Interface MTU Size: ${BGN}$MTU1${CL}"
  225. fi
  226. fi
  227. SD=$(whiptail --inputbox "Set a DNS Search Domain (leave blank for HOST)" 8 58 --title "DNS Search Domain" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  228. exitstatus=$?
  229. if [ $exitstatus = 0 ]; then
  230. if [ -z $SD ]; then
  231. SD=""
  232. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  233. else
  234. SX=$SD
  235. SD="-searchdomain=$SD"
  236. echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}"
  237. fi
  238. fi
  239. NS=$(whiptail --inputbox "Set a DNS Server IP (leave blank for HOST)" 8 58 --title "DNS SERVER IP" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  240. exitstatus=$?
  241. if [ $exitstatus = 0 ]; then
  242. if [ -z $NS ]; then
  243. NS=""
  244. echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}"
  245. else
  246. NX=$NS
  247. NS="-nameserver=$NS"
  248. echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}"
  249. fi
  250. fi
  251. MAC1=$(whiptail --inputbox "Set a MAC Address(leave blank for default)" 8 58 --title "MAC ADDRESS" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  252. exitstatus=$?
  253. if [ $exitstatus = 0 ]; then
  254. if [ -z $MAC1 ]; then
  255. MAC1="Default" MAC=""
  256. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  257. else
  258. MAC=",hwaddr=$MAC1"
  259. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  260. fi
  261. fi
  262. VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  263. exitstatus=$?
  264. if [ $exitstatus = 0 ]; then
  265. if [ -z $VLAN1 ]; then
  266. VLAN1="Default" VLAN=""
  267. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  268. else
  269. VLAN=",tag=$VLAN1"
  270. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  271. fi
  272. fi
  273. if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then
  274. echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}"
  275. SSH="yes"
  276. else
  277. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  278. SSH="no"
  279. fi
  280. if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
  281. echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}"
  282. VERB="yes"
  283. else
  284. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  285. VERB="no"
  286. fi
  287. if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then
  288. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  289. else
  290. clear
  291. header_info
  292. echo -e "${RD}Using Advanced Settings${CL}"
  293. advanced_settings
  294. fi
  295. }
  296. function install_script() {
  297. ARCH_CHECK
  298. PVE_CHECK
  299. NEXTID=$(pvesh get /cluster/nextid)
  300. header_info
  301. if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  302. header_info
  303. echo -e "${BL}Using Default Settings${CL}"
  304. default_settings
  305. else
  306. header_info
  307. echo -e "${RD}Using Advanced Settings${CL}"
  308. advanced_settings
  309. fi
  310. }
  311. function update_script() {
  312. header_info
  313. RELEASE=$(curl -s https://api.github.com/repos/zwave-js/zwave-js-ui/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
  314. msg_info "Stopping Z-wave JS UI"
  315. systemctl stop zwave-js-ui.service
  316. msg_ok "Stopped Z-wave JS UI"
  317. msg_info "Updating Z-wave JS UI"
  318. wget https://github.com/zwave-js/zwave-js-ui/releases/download/${RELEASE}/zwave-js-ui-${RELEASE}-linux.zip &>/dev/null
  319. unzip zwave-js-ui-${RELEASE}-linux.zip &>/dev/null
  320. \cp -R zwave-js-ui-linux /opt/zwave-js-ui
  321. msg_ok "Updated Z-wave JS UI"
  322. msg_info "Starting Z-wave JS UI"
  323. systemctl enable --now zwave-js-ui.service
  324. msg_ok "Started Z-wave JS UI"
  325. msg_info "Cleanup"
  326. rm -rf zwave-js-ui-${RELEASE}-linux.zip zwave-js-ui-linux store
  327. msg_ok "Cleaned"
  328. msg_ok "Updated Successfully!\n"
  329. exit
  330. }
  331. if command -v pveversion >/dev/null 2>&1; then
  332. if ! (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  333. clear
  334. echo -e "⚠ User exited script \n"
  335. exit
  336. fi
  337. install_script
  338. fi
  339. if ! command -v pveversion >/dev/null 2>&1 && [[ ! -d /opt/zwave-js-ui ]]; then
  340. msg_error "No ${APP} Installation Found!"
  341. exit
  342. fi
  343. if ! command -v pveversion >/dev/null 2>&1; then
  344. if ! (whiptail --title "${APP} LXC UPDATE" --yesno "This will update ${APP} LXC. Proceed?" 10 58); then
  345. clear
  346. echo -e "⚠ User exited script \n"
  347. exit
  348. fi
  349. update_script
  350. fi
  351. if [ "$VERB" == "yes" ]; then set -x; fi
  352. if [ "$CT_TYPE" == "1" ]; then
  353. FEATURES="nesting=1,keyctl=1"
  354. else
  355. FEATURES="nesting=1"
  356. fi
  357. TEMP_DIR=$(mktemp -d)
  358. pushd $TEMP_DIR >/dev/null
  359. export DISABLEIPV6=$DISABLEIP6
  360. export APPLICATION=$APP
  361. export VERBOSE=$VERB
  362. export SSH_ROOT=${SSH}
  363. export CTID=$CT_ID
  364. export PCT_OSTYPE=$var_os
  365. export PCT_OSVERSION=$var_version
  366. export PCT_DISK_SIZE=$DISK_SIZE
  367. export PCT_OPTIONS="
  368. -features $FEATURES
  369. -hostname $HN
  370. $SD
  371. $NS
  372. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN$MTU
  373. -onboot 1
  374. -cores $CORE_COUNT
  375. -memory $RAM_SIZE
  376. -unprivileged $CT_TYPE
  377. $PW
  378. "
  379. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  380. if [ "$CT_TYPE" == "0" ]; then
  381. LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
  382. cat <<EOF >>$LXC_CONFIG
  383. lxc.cgroup2.devices.allow: a
  384. lxc.cap.drop:
  385. lxc.cgroup2.devices.allow: c 188:* rwm
  386. lxc.cgroup2.devices.allow: c 189:* rwm
  387. lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir
  388. lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file
  389. lxc.mount.entry: /dev/ttyUSB1 dev/ttyUSB1 none bind,optional,create=file
  390. lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file
  391. lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file
  392. EOF
  393. fi
  394. msg_info "Starting LXC Container"
  395. pct start $CTID
  396. msg_ok "Started LXC Container"
  397. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit
  398. IP=$(pct exec $CTID ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
  399. pct set $CTID -description "# ${APP} LXC
  400. ### https://tteck.github.io/Proxmox/
  401. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  402. msg_ok "Completed Successfully!\n"
  403. echo -e "${APP} should be reachable by going to the following URL.
  404. ${BL}http://${IP}:8091${CL} \n"