nocodb-install.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env bash -ex
  2. set -euo pipefail
  3. shopt -s inherit_errexit nullglob
  4. YW=`echo "\033[33m"`
  5. RD=`echo "\033[01;31m"`
  6. BL=`echo "\033[36m"`
  7. GN=`echo "\033[1;92m"`
  8. CL=`echo "\033[m"`
  9. RETRY_NUM=10
  10. RETRY_EVERY=3
  11. NUM=$RETRY_NUM
  12. CM="${GN}✓${CL}"
  13. CROSS="${RD}✗${CL}"
  14. BFR="\\r\\033[K"
  15. HOLD="-"
  16. function msg_info() {
  17. local msg="$1"
  18. echo -ne " ${HOLD} ${YW}${msg}..."
  19. }
  20. function msg_ok() {
  21. local msg="$1"
  22. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  23. }
  24. msg_info "Setting up Container OS "
  25. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  26. locale-gen >/dev/null
  27. while [ "$(hostname -I)" = "" ]; do
  28. 1>&2 echo -en "${CROSS}${RD} No Network! "
  29. sleep $RETRY_EVERY
  30. ((NUM--))
  31. if [ $NUM -eq 0 ]
  32. then
  33. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  34. exit 1
  35. fi
  36. done
  37. msg_ok "Set up Container OS"
  38. msg_ok "Network Connected: ${BL}$(hostname -I)"
  39. msg_info "Updating Container OS"
  40. apt update &>/dev/null
  41. apt-get -qqy upgrade &>/dev/null
  42. msg_ok "Updated Container OS"
  43. msg_info "Installing Dependencies"
  44. apt-get install -y curl &>/dev/null
  45. apt-get install -y sudo &>/dev/null
  46. apt-get install -y git &>/dev/null
  47. msg_ok "Installed Dependencies"
  48. msg_info "Setting up Node.js Repository"
  49. sudo curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash - &>/dev/null
  50. msg_ok "Set up Node.js Repository"
  51. msg_info "Installing Node.js"
  52. sudo apt-get install -y nodejs git make g++ gcc &>/dev/null
  53. msg_ok "Installed Node.js"
  54. msg_info "Installing NocoDB"
  55. git clone https://github.com/nocodb/nocodb-seed &>/dev/null
  56. mv nocodb-seed /opt/nocodb
  57. cd /opt/nocodb
  58. npm install &>/dev/null
  59. msg_ok "Installed NocoDB"
  60. msg_info "Creating Service"
  61. service_path="/etc/systemd/system/nocodb.service"
  62. echo "[Unit]
  63. Description=nocodb
  64. [Service]
  65. Type=simple
  66. Restart=always
  67. User=root
  68. WorkingDirectory=/opt/nocodb
  69. ExecStart=/usr/bin/npm start
  70. [Install]
  71. WantedBy=multi-user.target" > $service_path
  72. systemctl enable --now nocodb.service &>/dev/null
  73. msg_ok "Created Service"
  74. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  75. if [[ $PASS != $ ]]; then
  76. msg_info "Customizing Container"
  77. rm /etc/motd
  78. rm /etc/update-motd.d/10-uname
  79. touch ~/.hushlogin
  80. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  81. mkdir -p $(dirname $GETTY_OVERRIDE)
  82. cat << EOF > $GETTY_OVERRIDE
  83. [Service]
  84. ExecStart=
  85. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  86. EOF
  87. systemctl daemon-reload
  88. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  89. msg_ok "Customized Container"
  90. fi
  91. msg_info "Cleaning up"
  92. apt-get autoremove >/dev/null
  93. apt-get autoclean >/dev/null
  94. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  95. msg_ok "Cleaned"