nocodb-v5.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. #!/usr/bin/env bash
  2. function header_info {
  3. cat <<"EOF"
  4. _ __ ____ ____
  5. / | / /___ ____v5___ / __ \/ __ )
  6. / |/ / __ \/ ___/ __ \/ / / / __ |
  7. / /| / /_/ / /__/ /_/ / /_/ / /_/ /
  8. /_/ |_/\____/\___/\____/_____/_____/
  9. EOF
  10. }
  11. clear
  12. header_info
  13. echo -e "Loading..."
  14. APP="NocoDB"
  15. var_disk="4"
  16. var_cpu="1"
  17. var_ram="1024"
  18. var_os="debian"
  19. var_version="11"
  20. NSAPP=$(echo ${APP,,} | tr -d ' ')
  21. var_install="${NSAPP}-v5-install"
  22. INTEGER='^[0-9]+$'
  23. YW=$(echo "\033[33m")
  24. BL=$(echo "\033[36m")
  25. RD=$(echo "\033[01;31m")
  26. BGN=$(echo "\033[4;92m")
  27. GN=$(echo "\033[1;92m")
  28. DGN=$(echo "\033[32m")
  29. CL=$(echo "\033[m")
  30. BFR="\\r\\033[K"
  31. HOLD="-"
  32. CM="${GN}✓${CL}"
  33. CROSS="${RD}✗${CL}"
  34. set -o errexit
  35. set -o errtrace
  36. set -o nounset
  37. set -o pipefail
  38. shopt -s expand_aliases
  39. alias die='EXIT=$? LINE=$LINENO error_exit'
  40. trap die ERR
  41. function error_exit() {
  42. trap - ERR
  43. local reason="Unknown failure occurred."
  44. local msg="${1:-$reason}"
  45. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  46. echo -e "$flag $msg" 1>&2
  47. exit $EXIT
  48. }
  49. function msg_info() {
  50. local msg="$1"
  51. echo -ne " ${HOLD} ${YW}${msg}..."
  52. }
  53. function msg_ok() {
  54. local msg="$1"
  55. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  56. }
  57. function msg_error() {
  58. local msg="$1"
  59. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  60. }
  61. function PVE_CHECK() {
  62. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  63. if [[ $PVE != 1 ]]; then
  64. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  65. echo -e "Exiting..."
  66. sleep 2
  67. exit
  68. fi
  69. }
  70. if command -v pveversion >/dev/null 2>&1; then
  71. if (whiptail --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
  72. NEXTID=$(pvesh get /cluster/nextid)
  73. else
  74. clear
  75. echo -e "⚠ User exited script \n"
  76. exit
  77. fi
  78. fi
  79. if ! command -v pveversion >/dev/null 2>&1; then
  80. if [[ ! -f /etc/systemd/system/nocodb.service ]]; then
  81. msg_error "No ${APP} Installation Found!";
  82. exit
  83. fi
  84. if (whiptail --title "${APP} LXC UPDATE" --yesno "This will update ${APP} LXC. Proceed?" 10 58); then
  85. echo "User selected Update"
  86. else
  87. clear
  88. echo -e "⚠ User exited script \n"
  89. exit
  90. fi
  91. fi
  92. function default_settings() {
  93. echo -e "${DGN}Using Container Type: ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  94. CT_TYPE="1"
  95. echo -e "${DGN}Using Root Password: ${BGN}Automatic Login${CL}"
  96. PW=""
  97. echo -e "${DGN}Using Container ID: ${BGN}$NEXTID${CL}"
  98. CT_ID=$NEXTID
  99. echo -e "${DGN}Using Hostname: ${BGN}$NSAPP${CL}"
  100. HN=$NSAPP
  101. echo -e "${DGN}Using Disk Size: ${BGN}$var_disk${CL}${DGN}GB${CL}"
  102. DISK_SIZE="$var_disk"
  103. echo -e "${DGN}Allocated Cores ${BGN}$var_cpu${CL}"
  104. CORE_COUNT="$var_cpu"
  105. echo -e "${DGN}Allocated Ram ${BGN}$var_ram${CL}"
  106. RAM_SIZE="$var_ram"
  107. echo -e "${DGN}Using Bridge: ${BGN}vmbr0${CL}"
  108. BRG="vmbr0"
  109. echo -e "${DGN}Using Static IP Address: ${BGN}dhcp${CL}"
  110. NET=dhcp
  111. echo -e "${DGN}Using Gateway Address: ${BGN}Default${CL}"
  112. GATE=""
  113. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  114. SD=""
  115. echo -e "${DGN}Using DNS Server Address: ${BGN}Host${CL}"
  116. NS=""
  117. echo -e "${DGN}Using MAC Address: ${BGN}Default${CL}"
  118. MAC=""
  119. echo -e "${DGN}Using VLAN Tag: ${BGN}Default${CL}"
  120. VLAN=""
  121. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  122. SSH="no"
  123. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  124. VERB="no"
  125. VERB2="silent"
  126. echo -e "${BL}Creating a ${APP} LXC using the above default settings${CL}"
  127. }
  128. function advanced_settings() {
  129. CT_TYPE=$(whiptail --title "CONTAINER TYPE" --radiolist --cancel-button Exit-Script "Choose Type" 8 58 2 \
  130. "1" "Unprivileged" ON \
  131. "0" "Privileged" OFF \
  132. 3>&1 1>&2 2>&3)
  133. exitstatus=$?
  134. if [ $exitstatus = 0 ]; then
  135. echo -e "${DGN}Using Container Type: ${BGN}$CT_TYPE${CL}"
  136. fi
  137. 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)
  138. exitstatus=$?
  139. if [ $exitstatus = 0 ]; then
  140. if [ -z $PW1 ]; then
  141. PW1="Automatic Login" PW=" "
  142. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  143. else
  144. PW="-password $PW1"
  145. echo -e "${DGN}Using Root Password: ${BGN}$PW1${CL}"
  146. fi
  147. fi
  148. CT_ID=$(whiptail --inputbox "Set Container ID" 8 58 $NEXTID --title "CONTAINER ID" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  149. exitstatus=$?
  150. if [ -z $CT_ID ]; then
  151. CT_ID="$NEXTID"
  152. echo -e "${DGN}Container ID: ${BGN}$CT_ID${CL}"
  153. else
  154. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Container ID: ${BGN}$CT_ID${CL}"; fi
  155. fi
  156. CT_NAME=$(whiptail --inputbox "Set Hostname" 8 58 $NSAPP --title "HOSTNAME" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  157. exitstatus=$?
  158. if [ -z $CT_NAME ]; then
  159. HN="$NSAPP"
  160. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  161. else
  162. if [ $exitstatus = 0 ]; then
  163. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  164. echo -e "${DGN}Using Hostname: ${BGN}$HN${CL}"
  165. fi
  166. fi
  167. 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)
  168. exitstatus=$?
  169. if [ -z $DISK_SIZE ]; then
  170. DISK_SIZE="$var_disk"
  171. echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"
  172. else
  173. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Disk Size: ${BGN}$DISK_SIZE${CL}"; fi
  174. if ! [[ $DISK_SIZE =~ $INTEGER ]]; then
  175. echo -e "${RD}⚠ DISK SIZE MUST BE A INTEGER NUMBER!${CL}"
  176. advanced_settings
  177. fi
  178. fi
  179. CORE_COUNT=$(whiptail --inputbox "Allocate CPU Cores" 8 58 $var_cpu --title "CORE COUNT" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  180. exitstatus=$?
  181. if [ -z $CORE_COUNT ]; then
  182. CORE_COUNT="$var_cpu"
  183. echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"
  184. else
  185. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated Cores: ${BGN}$CORE_COUNT${CL}"; fi
  186. fi
  187. RAM_SIZE=$(whiptail --inputbox "Allocate RAM in MiB" 8 58 $var_ram --title "RAM" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  188. exitstatus=$?
  189. if [ -z $RAM_SIZE ]; then
  190. RAM_SIZE="$var_ram"
  191. echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"
  192. else
  193. if [ $exitstatus = 0 ]; then echo -e "${DGN}Allocated RAM: ${BGN}$RAM_SIZE${CL}"; fi
  194. fi
  195. BRG=$(whiptail --inputbox "Set a Bridge" 8 58 vmbr0 --title "BRIDGE" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  196. exitstatus=$?
  197. if [ -z $BRG ]; then
  198. BRG="vmbr0"
  199. echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"
  200. else
  201. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using Bridge: ${BGN}$BRG${CL}"; fi
  202. fi
  203. 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)
  204. exitstatus=$?
  205. if [ -z $NET ]; then
  206. NET="dhcp"
  207. echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"
  208. else
  209. if [ $exitstatus = 0 ]; then echo -e "${DGN}Using IP Address: ${BGN}$NET${CL}"; fi
  210. fi
  211. 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)
  212. exitstatus=$?
  213. if [ $exitstatus = 0 ]; then
  214. if [ -z $GATE1 ]; then
  215. GATE1="Default" GATE=""
  216. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  217. else
  218. GATE=",gw=$GATE1"
  219. echo -e "${DGN}Using Gateway IP Address: ${BGN}$GATE1${CL}"
  220. fi
  221. fi
  222. 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)
  223. exitstatus=$?
  224. if [ $exitstatus = 0 ]; then
  225. if [ -z $SD ]; then
  226. SD=""
  227. echo -e "${DGN}Using DNS Search Domain: ${BGN}Host${CL}"
  228. else
  229. SX=$SD
  230. SD="-searchdomain=$SD"
  231. echo -e "${DGN}Using DNS Search Domain: ${BGN}$SX${CL}"
  232. fi
  233. fi
  234. 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)
  235. exitstatus=$?
  236. if [ $exitstatus = 0 ]; then
  237. if [ -z $NS ]; then
  238. NS=""
  239. echo -e "${DGN}Using DNS Server IP Address: ${BGN}Host${CL}"
  240. else
  241. NX=$NS
  242. NS="-nameserver=$NS"
  243. echo -e "${DGN}Using DNS Server IP Address: ${BGN}$NX${CL}"
  244. fi
  245. fi
  246. 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)
  247. exitstatus=$?
  248. if [ $exitstatus = 0 ]; then
  249. if [ -z $MAC1 ]; then
  250. MAC1="Default" MAC=""
  251. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  252. else
  253. MAC=",hwaddr=$MAC1"
  254. echo -e "${DGN}Using MAC Address: ${BGN}$MAC1${CL}"
  255. fi
  256. fi
  257. VLAN1=$(whiptail --inputbox "Set a Vlan(leave blank for default)" 8 58 --title "VLAN" --cancel-button Exit-Script 3>&1 1>&2 2>&3)
  258. exitstatus=$?
  259. if [ $exitstatus = 0 ]; then
  260. if [ -z $VLAN1 ]; then
  261. VLAN1="Default" VLAN=""
  262. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  263. else
  264. VLAN=",tag=$VLAN1"
  265. echo -e "${DGN}Using Vlan: ${BGN}$VLAN1${CL}"
  266. fi
  267. fi
  268. if (whiptail --defaultno --title "SSH ACCESS" --yesno "Enable Root SSH Access?" 10 58); then
  269. echo -e "${DGN}Enable Root SSH Access: ${BGN}Yes${CL}"
  270. SSH="yes"
  271. else
  272. echo -e "${DGN}Enable Root SSH Access: ${BGN}No${CL}"
  273. SSH="no"
  274. fi
  275. if (whiptail --defaultno --title "VERBOSE MODE" --yesno "Enable Verbose Mode?" 10 58); then
  276. echo -e "${DGN}Enable Verbose Mode: ${BGN}Yes${CL}"
  277. VERB="yes"
  278. VERB2=""
  279. else
  280. echo -e "${DGN}Enable Verbose Mode: ${BGN}No${CL}"
  281. VERB="no"
  282. VERB2="silent"
  283. fi
  284. if (whiptail --title "ADVANCED SETTINGS COMPLETE" --yesno "Ready to create ${APP} LXC?" --no-button Do-Over 10 58); then
  285. echo -e "${RD}Creating a ${APP} LXC using the above advanced settings${CL}"
  286. else
  287. clear
  288. header_info
  289. echo -e "${RD}Using Advanced Settings${CL}"
  290. advanced_settings
  291. fi
  292. }
  293. function install_script() {
  294. if (whiptail --title "SETTINGS" --yesno "Use Default Settings?" --no-button Advanced 10 58); then
  295. header_info
  296. echo -e "${BL}Using Default Settings${CL}"
  297. default_settings
  298. else
  299. header_info
  300. echo -e "${RD}Using Advanced Settings${CL}"
  301. advanced_settings
  302. fi
  303. }
  304. function update_script() {
  305. clear
  306. header_info
  307. msg_info "Updating ${APP}"
  308. cd /opt/nocodb
  309. npm uninstall -s --save nocodb &>/dev/null
  310. npm install -s --save nocodb &>/dev/null
  311. systemctl restart nocodb.service
  312. msg_ok "Updated ${APP}"
  313. msg_ok "Update Successfull"
  314. exit
  315. }
  316. clear
  317. if ! command -v pveversion >/dev/null 2>&1; then update_script; else install_script; fi
  318. if [ "$VERB" == "yes" ]; then set -x; fi
  319. if [ "$CT_TYPE" == "1" ]; then
  320. FEATURES="nesting=1,keyctl=1"
  321. else
  322. FEATURES="nesting=1"
  323. fi
  324. TEMP_DIR=$(mktemp -d)
  325. pushd $TEMP_DIR >/dev/null
  326. export VERBOSE=$VERB
  327. export STD=$VERB2
  328. export SSH_ROOT=${SSH}
  329. export CTID=$CT_ID
  330. export PCT_OSTYPE=$var_os
  331. export PCT_OSVERSION=$var_version
  332. export PCT_DISK_SIZE=$DISK_SIZE
  333. export PCT_OPTIONS="
  334. -features $FEATURES
  335. -hostname $HN
  336. $SD
  337. $NS
  338. -net0 name=eth0,bridge=$BRG$MAC,ip=$NET$GATE$VLAN
  339. -onboot 1
  340. -cores $CORE_COUNT
  341. -memory $RAM_SIZE
  342. -unprivileged $CT_TYPE
  343. $PW
  344. "
  345. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  346. msg_info "Starting LXC Container"
  347. pct start $CTID
  348. msg_ok "Started LXC Container"
  349. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/install/$var_install.sh)" || exit
  350. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  351. pct set $CTID -description "# ${APP} LXC
  352. ### https://tteck.github.io/Proxmox/
  353. <a href='https://ko-fi.com/D1D7EP4GF'><img src='https://img.shields.io/badge/☕-Buy me a coffee-red' /></a>"
  354. msg_ok "Completed Successfully!\n"
  355. echo -e "${APP} should be reachable by going to the following URL.
  356. ${BL}http://${IP}:8080/dashboard${CL} \n"