influxdb-v5-install.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/env bash
  2. if [ "$VERBOSE" == "yes" ]; then set -x; fi
  3. if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; fi
  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. set -o errexit
  17. set -o errtrace
  18. set -o nounset
  19. set -o pipefail
  20. shopt -s expand_aliases
  21. alias die='EXIT=$? LINE=$LINENO error_exit'
  22. trap die ERR
  23. silent() { "$@" > /dev/null 2>&1; }
  24. function error_exit() {
  25. trap - ERR
  26. local reason="Unknown failure occurred."
  27. local msg="${1:-$reason}"
  28. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  29. echo -e "$flag $msg" 1>&2
  30. exit $EXIT
  31. }
  32. function msg_info() {
  33. local msg="$1"
  34. echo -ne " ${HOLD} ${YW}${msg}..."
  35. }
  36. function msg_ok() {
  37. local msg="$1"
  38. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  39. }
  40. function msg_error() {
  41. local msg="$1"
  42. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  43. }
  44. msg_info "Setting up Container OS "
  45. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  46. locale-gen >/dev/null
  47. while [ "$(hostname -I)" = "" ]; do
  48. echo 1>&2 -en "${CROSS}${RD} No Network! "
  49. sleep $RETRY_EVERY
  50. ((NUM--))
  51. if [ $NUM -eq 0 ]; then
  52. echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  53. exit 1
  54. fi
  55. done
  56. msg_ok "Set up Container OS"
  57. msg_ok "Network Connected: ${BL}$(hostname -I)"
  58. set +e
  59. alias die=''
  60. if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else
  61. msg_error "Internet NOT Connected"
  62. read -r -p "Would you like to continue anyway? <y/N> " prompt
  63. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  64. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  65. else
  66. echo -e " 🖧 Check Network Settings"
  67. exit 1
  68. fi
  69. fi
  70. RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
  71. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi
  72. alias die='EXIT=$? LINE=$LINENO error_exit'
  73. set -e
  74. msg_info "Updating Container OS"
  75. $STD apt-get update
  76. $STD apt-get -y upgrade
  77. msg_ok "Updated Container OS"
  78. msg_info "Installing Dependencies"
  79. $STD apt-get install -y curl
  80. $STD apt-get install -y sudo
  81. $STD apt-get install -y mc
  82. $STD apt-get install -y lsb-base
  83. $STD apt-get install -y lsb-release
  84. $STD apt-get install -y gnupg2
  85. msg_ok "Installed Dependencies"
  86. msg_info "Setting up InfluxDB Repository"
  87. $STD apt-key add <(curl -fsSL https://repos.influxdata.com/influxdb.key)
  88. cat <<EOF >/etc/apt/sources.list.d/influxdb.list
  89. deb https://repos.influxdata.com/debian bullseye stable
  90. EOF
  91. msg_ok "Set up InfluxDB Repository"
  92. read -r -p "Which version of InfluxDB to install? (1 or 2) " prompt
  93. if [[ $prompt == "2" ]]; then
  94. INFLUX="2"
  95. else
  96. INFLUX="1"
  97. fi
  98. msg_info "Installing InfluxDB"
  99. $STD apt-get update
  100. if [[ $INFLUX == "2" ]]; then
  101. $STD apt-get install -y influxdb2
  102. else
  103. $STD apt-get install -y influxdb
  104. fi
  105. $STD systemctl enable --now influxdb
  106. msg_ok "Installed InfluxDB"
  107. read -r -p "Would you like to add Telegraf? <y/N> " prompt
  108. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  109. TELEGRAF="Y"
  110. else
  111. TELEGRAF="N"
  112. fi
  113. if [[ $TELEGRAF == "Y" ]]; then
  114. msg_info "Installing Telegraf"
  115. $STD apt-get install -y telegraf
  116. msg_ok "Installed Telegraf"
  117. fi
  118. PASS=$(grep -w "root" /etc/shadow | cut -b6)
  119. echo "export TERM='xterm-256color'" >>/root/.bashrc
  120. if [[ $PASS != $ ]]; then
  121. msg_info "Customizing Container"
  122. rm /etc/motd
  123. rm /etc/update-motd.d/10-uname
  124. touch ~/.hushlogin
  125. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  126. mkdir -p $(dirname $GETTY_OVERRIDE)
  127. cat <<EOF >$GETTY_OVERRIDE
  128. [Service]
  129. ExecStart=
  130. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  131. EOF
  132. systemctl daemon-reload
  133. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  134. msg_ok "Customized Container"
  135. fi
  136. if [[ "${SSH_ROOT}" == "yes" ]]; then
  137. sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
  138. systemctl restart sshd
  139. fi
  140. msg_info "Cleaning up"
  141. $STD apt-get autoremove
  142. $STD apt-get autoclean
  143. msg_ok "Cleaned"