influxdb-v3.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #!/usr/bin/env bash -ex
  2. set -euo pipefail
  3. shopt -s inherit_errexit nullglob
  4. NEXTID=$(pvesh get /cluster/nextid)
  5. INTEGER='^[0-9]+$'
  6. YW=`echo "\033[33m"`
  7. BL=`echo "\033[36m"`
  8. RD=`echo "\033[01;31m"`
  9. BGN=`echo "\033[4;92m"`
  10. GN=`echo "\033[1;92m"`
  11. DGN=`echo "\033[32m"`
  12. CL=`echo "\033[m"`
  13. BFR="\\r\\033[K"
  14. HOLD="-"
  15. CM="${GN}✓${CL}"
  16. APP="InfluxDB"
  17. NSAPP=$(echo ${APP,,} | tr -d ' ')
  18. while true; do
  19. read -p "This will create a New ${APP} LXC. Proceed(y/n)?" yn
  20. case $yn in
  21. [Yy]* ) break;;
  22. [Nn]* ) exit;;
  23. * ) echo "Please answer yes or no.";;
  24. esac
  25. done
  26. clear
  27. function header_info {
  28. echo -e "${YW}
  29. _____ __ _ _____ ____
  30. |_ _| / _| | | __ \| _ \
  31. | | _ __ | |_| |_ v3___ _| | | | |_) |
  32. | | | _ \| _| | | | \ \/ / | | | _ <
  33. _| |_| | | | | | | |_| |> <| |__| | |_) |
  34. |_____|_| |_|_| |_|\__,_/_/\_\_____/|____/
  35. with Telegraf
  36. ${CL}"
  37. }
  38. header_info
  39. function msg_info() {
  40. local msg="$1"
  41. echo -ne " ${HOLD} ${YW}${msg}..."
  42. }
  43. function msg_ok() {
  44. local msg="$1"
  45. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  46. }
  47. function PVE_CHECK() {
  48. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  49. if [[ $PVE != 1 ]]; then
  50. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  51. echo -e "Exiting..."
  52. sleep 2
  53. exit
  54. fi
  55. }
  56. function default_settings() {
  57. clear
  58. header_info
  59. echo -e "${BL}Using Default Settings${CL}"
  60. echo -e "${DGN}Using CT Type ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  61. CT_TYPE="1"
  62. echo -e "${DGN}Using CT Password ${BGN}Automatic Login${CL}"
  63. PW=" "
  64. echo -e "${DGN}Using CT ID ${BGN}$NEXTID${CL}"
  65. CT_ID=$NEXTID
  66. echo -e "${DGN}Using CT Name ${BGN}$NSAPP${CL}"
  67. HN=$NSAPP
  68. echo -e "${DGN}Using Disk Size ${BGN}8GB${CL}"
  69. DISK_SIZE="8"
  70. echo -e "${DGN}Using ${BGN}2vCPU${CL}"
  71. CORE_COUNT="2"
  72. echo -e "${DGN}Using ${BGN}512MiB${CL}${DGN} RAM${CL}"
  73. RAM_SIZE="2048"
  74. echo -e "${DGN}Using Static IP Address ${BGN}DHCP${CL}"
  75. NET=dhcp
  76. echo -e "${DGN}Using Gateway Address ${BGN}NONE${CL}"
  77. GATE=" "
  78. echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}"
  79. VLAN=" "
  80. }
  81. function advanced_settings() {
  82. clear
  83. header_info
  84. echo -e "${RD}Using Advanced Settings${CL}"
  85. echo -e "${YW}Type Privileged, or Press [ENTER] for Default: Unprivileged (${RD}NO DEVICE PASSTHROUGH${CL}${YW})"
  86. read CT_TYPE1
  87. if [ -z $CT_TYPE1 ]; then CT_TYPE1="Unprivileged" CT_TYPE="1";
  88. echo -en "${DGN}Set CT Type ${BL}$CT_TYPE1${CL}"
  89. else
  90. CT_TYPE1="Privileged"
  91. CT_TYPE="0"
  92. echo -en "${DGN}Set CT Type ${BL}Privileged${CL}"
  93. fi;
  94. echo -e " ${CM}${CL} \r"
  95. sleep 1
  96. clear
  97. header_info
  98. echo -e "${RD}Using Advanced Settings${CL}"
  99. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  100. echo -e "${YW}Set Password, or Press [ENTER] for Default: Automatic Login "
  101. read PW1
  102. if [ -z $PW1 ]; then PW1="Automatic Login" PW=" ";
  103. echo -en "${DGN}Set CT ${BL}$PW1${CL}"
  104. else
  105. PW="-password $PW1"
  106. echo -en "${DGN}Set CT Password ${BL}$PW1${CL}"
  107. fi;
  108. echo -e " ${CM}${CL} \r"
  109. sleep 1
  110. clear
  111. header_info
  112. echo -e "${RD}Using Advanced Settings${CL}"
  113. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  114. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  115. echo -e "${YW}Enter the CT ID, or Press [ENTER] to automatically generate (${NEXTID}) "
  116. read CT_ID
  117. if [ -z $CT_ID ]; then CT_ID=$NEXTID; fi;
  118. echo -en "${DGN}Set CT ID To ${BL}$CT_ID${CL}"
  119. echo -e " ${CM}${CL} \r"
  120. sleep 1
  121. clear
  122. header_info
  123. echo -e "${RD}Using Advanced Settings${CL}"
  124. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  125. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  126. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  127. echo -e "${YW}Enter CT Name (no-spaces), or Press [ENTER] for Default: $NSAPP "
  128. read CT_NAME
  129. if [ -z $CT_NAME ]; then
  130. HN=$NSAPP
  131. else
  132. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  133. fi
  134. echo -en "${DGN}Set CT Name To ${BL}$HN${CL}"
  135. echo -e " ${CM}${CL} \r"
  136. sleep 1
  137. clear
  138. header_info
  139. echo -e "${RD}Using Advanced Settings${CL}"
  140. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  141. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  142. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  143. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  144. echo -e "${YW}Enter a Disk Size, or Press [ENTER] for Default: 8Gb "
  145. read DISK_SIZE
  146. if [ -z $DISK_SIZE ]; then DISK_SIZE="8"; fi;
  147. if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo "ERROR! DISK SIZE MUST HAVE INTEGER NUMBER!"; exit; fi;
  148. echo -en "${DGN}Set Disk Size To ${BL}$DISK_SIZE${CL}"
  149. echo -e " ${CM}${CL} \r"
  150. sleep 1
  151. clear
  152. header_info
  153. echo -e "${RD}Using Advanced Settings${CL}"
  154. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  155. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  156. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  157. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  158. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  159. echo -e "${YW}Allocate CPU cores, or Press [ENTER] for Default: 2 "
  160. read CORE_COUNT
  161. if [ -z $CORE_COUNT ]; then CORE_COUNT="2"; fi;
  162. echo -en "${DGN}Set Cores To ${BL}$CORE_COUNT${CL}"
  163. echo -e " ${CM}${CL} \r"
  164. sleep 1
  165. clear
  166. header_info
  167. echo -e "${RD}Using Advanced Settings${CL}"
  168. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  169. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  170. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  171. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  172. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  173. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  174. echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 2048 "
  175. read RAM_SIZE
  176. if [ -z $RAM_SIZE ]; then RAM_SIZE="2048"; fi;
  177. echo -en "${DGN}Set RAM To ${BL}$RAM_SIZE${CL}"
  178. echo -e " ${CM}${CL} \n"
  179. sleep 1
  180. clear
  181. header_info
  182. echo -e "${RD}Using Advanced Settings${CL}"
  183. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  184. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  185. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  186. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  187. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  188. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  189. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  190. echo -e "${YW}Enter a Static IP Address, or Press [ENTER] for Default: DHCP "
  191. read NET
  192. if [ -z $NET ]; then NET="dhcp"; fi;
  193. echo -en "${DGN}Set Static IP Address To ${BL}$NET${CL}"
  194. echo -e " ${CM}${CL} \n"
  195. sleep 1
  196. clear
  197. header_info
  198. echo -e "${RD}Using Advanced Settings${CL}"
  199. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  200. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  201. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  202. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  203. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  204. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  205. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  206. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  207. echo -e "${YW}Enter a Gateway IP, or Press [ENTER] for Default: NONE "
  208. read GATE1
  209. if [ -z $GATE1 ]; then GATE1="NONE" GATE=" ";
  210. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  211. else
  212. GATE=",gw=$GATE1"
  213. echo -en "${DGN}Set Gateway IP To ${BL}$GATE1${CL}"
  214. fi;
  215. echo -e " ${CM}${CL} \n"
  216. sleep 1
  217. clear
  218. header_info
  219. echo -e "${RD}Using Advanced Settings${CL}"
  220. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  221. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  222. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  223. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  224. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  225. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  226. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  227. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  228. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  229. echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE "
  230. read VLAN1
  231. if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=" ";
  232. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  233. else
  234. VLAN=",tag=$VLAN1"
  235. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  236. fi;
  237. echo -e " ${CM}${CL} \n"
  238. sleep 1
  239. clear
  240. header_info
  241. echo -e "${RD}Using Advanced Settings${CL}"
  242. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  243. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  244. echo -e "${DGN}Using CT ID ${BGN}$CT_ID${CL}"
  245. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  246. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  247. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  248. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${DGN} RAM${CL}"
  249. echo -e "${DGN}Using Static IP Address ${BGN}$NET${CL}"
  250. echo -e "${DGN}Using Gateway IP Address ${BGN}$GATE1${CL}"
  251. echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}"
  252. read -p "Are these settings correct(y/n)? " -n 1 -r
  253. echo
  254. if [[ ! $REPLY =~ ^[Yy]$ ]]
  255. then
  256. advanced_settings
  257. fi
  258. }
  259. function start_script() {
  260. echo -e "${YW}Type Advanced, or Press [ENTER] for Default Settings "
  261. read SETTINGS
  262. if [ -z $SETTINGS ]; then default_settings;
  263. else
  264. advanced_settings
  265. fi;
  266. }
  267. start_script
  268. if [ "$CT_TYPE" == "1" ]; then
  269. FEATURES="nesting=1,keyctl=1"
  270. else
  271. FEATURES="nesting=1"
  272. fi
  273. TEMP_DIR=$(mktemp -d)
  274. pushd $TEMP_DIR >/dev/null
  275. export CTID=$CT_ID
  276. export PCT_OSTYPE=debian
  277. export PCT_OSVERSION=11
  278. export PCT_DISK_SIZE=$DISK_SIZE
  279. export PCT_OPTIONS="
  280. -features $FEATURES
  281. -hostname $HN
  282. -net0 name=eth0,bridge=vmbr0,ip=$NET$GATE$VLAN
  283. -onboot 1
  284. -cores $CORE_COUNT
  285. -memory $RAM_SIZE
  286. -unprivileged $CT_TYPE
  287. $PW
  288. "
  289. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  290. msg_info "Starting LXC Container"
  291. pct start $CTID
  292. msg_ok "Started LXC Container"
  293. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/influxdb-install.sh)" || exit
  294. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  295. msg_ok "Completed Successfully!\n"