nocodb-v5.sh 12 KB

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