zwave-js-ui-v4.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #!/usr/bin/env bash
  2. echo -e "Loading..."
  3. APP="Zwave-JS-UI"
  4. var_disk="4"
  5. var_cpu="2"
  6. var_ram="1024"
  7. var_os="debian"
  8. var_version="11"
  9. NSAPP=$(echo ${APP,,} | tr -d ' ')
  10. var_install="${NSAPP}-install"
  11. NEXTID=$(pvesh get /cluster/nextid)
  12. INTEGER='^[0-9]+$'
  13. YW=`echo "\033[33m"`
  14. BL=`echo "\033[36m"`
  15. RD=`echo "\033[01;31m"`
  16. BGN=`echo "\033[4;92m"`
  17. GN=`echo "\033[1;92m"`
  18. DGN=`echo "\033[32m"`
  19. CL=`echo "\033[m"`
  20. BFR="\\r\\033[K"
  21. HOLD="-"
  22. CM="${GN}✓${CL}"
  23. set -o errexit
  24. set -o errtrace
  25. set -o nounset
  26. set -o pipefail
  27. shopt -s expand_aliases
  28. alias die='EXIT=$? LINE=$LINENO error_exit'
  29. trap die ERR
  30. function error_exit() {
  31. trap - ERR
  32. local reason="Unknown failure occurred."
  33. local msg="${1:-$reason}"
  34. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  35. echo -e "$flag $msg" 1>&2
  36. exit $EXIT
  37. }
  38. if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  39. echo "User selected Yes"
  40. else
  41. clear
  42. echo -e "⚠ User exited script \n"
  43. exit
  44. fi
  45. function header_info {
  46. cat << "EOF"
  47. _____ _______ __ ______
  48. /__ /_ ______ __v4 _____ / / ___/ / / / / _/
  49. / /| | /| / / __ `/ | / / _ \ __ / /\__ \ / / / // /
  50. / /_| |/ |/ / /_/ /| |/ / __/ / /_/ /___/ / / /_/ // /
  51. /____/__/|__/\__,_/ |___/\___/ \____//____/ \____/___/
  52. EOF
  53. }
  54. function msg_info() {
  55. local msg="$1"
  56. echo -ne " ${HOLD} ${YW}${msg}..."
  57. }
  58. function msg_ok() {
  59. local msg="$1"
  60. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  61. }
  62. function PVE_CHECK() {
  63. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  64. if [[ $PVE != 1 ]]; then
  65. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  66. echo -e "Exiting..."
  67. sleep 2
  68. exit
  69. fi
  70. }
  71. function default_settings() {
  72. echo -e "${DGN}Using Container Type: ${BGN}Privileged${CL}"
  73. CT_TYPE="0"
  74. echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  75. PW=""
  76. echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  77. CT_ID=$NEXTID
  78. echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  79. HN=$NSAPP
  80. echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  81. DISK_SIZE="$var_disk"
  82. echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  83. CORE_COUNT="$var_cpu"
  84. echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  85. RAM_SIZE="$var_ram"
  86. echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  87. BRG="vmbr0"
  88. echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  89. NET=dhcp
  90. echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  91. GATE=""
  92. echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  93. MAC=""
  94. echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  95. VLAN=""
  96. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  97. }
  98. function advanced_settings() {
  99. CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 8 58 2 \
  100. "1" "Unprivileged" OFF \
  101. "0" "Privileged" ON \
  102. 3>&1 1>&2 2>&3)
  103. exitstatus=$?
  104. if [ $exitstatus = 0 ]; then
  105. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  106. fi
  107. PW1=$(whiptail --inputbox "Set Root Password" 8 58 --title "PASSWORD(leave blank for automatic login)" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  108. exitstatus=$?
  109. if [ $exitstatus = 0 ]; then
  110. if [ -z $PW1 ]; then PW1="Automatic Login" PW=" ";
  111. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  112. else
  113. PW="-password $PW1"
  114. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  115. fi
  116. fi
  117. CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  118. exitstatus=$?
  119. if [ -z $CT_ID ]; then CT_ID="$NEXTID"; echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}";
  120. else
  121. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi;
  122. fi
  123. CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  124. exitstatus=$?
  125. if [ -z $CT_NAME ]; then HN="$NSAPP"; echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}";
  126. else
  127. if [ $exitstatus = 0 ]; then HN=$(echo ${CT_NAME,,} | tr -d ' '); echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"; fi;
  128. fi
  129. 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)
  130. exitstatus=$?
  131. if [ -z $DISK_SIZE ]; then DISK_SIZE="$var_disk"; echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}";
  132. else
  133. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi;
  134. if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"; advanced_settings; fi;
  135. fi
  136. CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  137. exitstatus=$?
  138. if [ -z $CORE_COUNT ]; then CORE_COUNT="$var_cpu"; echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}";
  139. else
  140. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi;
  141. fi
  142. RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  143. exitstatus=$?
  144. if [ -z $RAM_SIZE ]; then RAM_SIZE="$var_ram"; echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}";
  145. else
  146. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi;
  147. fi
  148. BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE"--cancel-button Exit-Script 3>&1 1>&2 2>&3)
  149. exitstatus=$?
  150. if [ -z $BRG ]; then BRG="vmbr0"; echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}";
  151. else
  152. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi;
  153. fi
  154. 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)
  155. exitstatus=$?
  156. if [ -z $NET ]; then NET="dhcp"; echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}";
  157. else
  158. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi;
  159. fi
  160. 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)
  161. exitstatus=$?
  162. if [ $exitstatus = 0 ]; then
  163. if [ -z $GATE1 ]; then GATE1="Default" GATE="";
  164. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  165. else
  166. GATE=",gw=$GATE1"
  167. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  168. fi
  169. fi
  170. 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)
  171. exitstatus=$?
  172. if [ $exitstatus = 0 ]; then
  173. if [ -z $MAC1 ]; then MAC1="Default" MAC="";
  174. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  175. else
  176. MAC=",hwaddr=$MAC1"
  177. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  178. fi
  179. fi
  180. VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  181. exitstatus=$?
  182. if [ $exitstatus = 0 ]; then
  183. if [ -z $VLAN1 ]; then VLAN1="Default" VLAN="";
  184. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  185. else
  186. VLAN=",tag=$VLAN1"
  187. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  188. fi
  189. fi
  190. if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then
  191. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  192. else
  193. clear
  194. header_info
  195. echo -e "${RD}Using Advanced Settings${CL}"
  196. advanced_settings
  197. fi
  198. }
  199. function start_script() {
  200. if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  201. header_info
  202. echo -e "${BL}Using Default Settings${CL}"
  203. default_settings
  204. else
  205. header_info
  206. echo -e "${RD}Using Advanced Settings${CL}"
  207. advanced_settings
  208. fi
  209. }
  210. clear
  211. start_script
  212. if [ "$CT_TYPE" == "1" ]; then
  213. FEATURES="nesting=1,keyctl=1"
  214. else
  215. FEATURES="nesting=1"
  216. fi
  217. TEMP_DIR=$(mktemp -d)
  218. pushd $TEMP_DIR >/dev/null
  219. export CTID=$CT_ID
  220. export PCT_OSTYPE=$var_os
  221. export PCT_OSVERSION=$var_version
  222. export PCT_DISK_SIZE=$DISK_SIZE
  223. export PCT_OPTIONS="
  224. -features $FEATURES
  225. -hostname $HN
  226. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN
  227. -onboot 1
  228. -cores $CORE_COUNT
  229. -memory $RAM_SIZE
  230. -unprivileged $CT_TYPE
  231. $PW
  232. "
  233. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  234. LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
  235. cat <<EOF >> $LXC_CONFIG
  236. lxc.cgroup2.devices.allow: a
  237. lxc.cap.drop:
  238. lxc.cgroup2.devices.allow: c 188:* rwm
  239. lxc.cgroup2.devices.allow: c 189:* rwm
  240. lxc.mount.entry: /dev/serial/by-id dev/serial/by-id none bind,optional,create=dir
  241. lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,optional,create=file
  242. lxc.mount.entry: /dev/ttyACM0 dev/ttyACM0 none bind,optional,create=file
  243. lxc.mount.entry: /dev/ttyACM1 dev/ttyACM1 none bind,optional,create=file
  244. EOF
  245. msg_info "Starting LXC Container"
  246. pct start $CTID
  247. msg_ok "Started LXC Container"
  248. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/$var_install.sh)" || exit
  249. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  250. pct set $CTID -description "# ${APP} LXC
  251. ### https://tteck.github.io/Proxmox/
  252. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  253. msg_ok "Completed Successfully!\n"
  254. echo -e "${APP} should be reachable by going to the following URL.
  255. ${BL}http://${IP}:8091${CL} \n"