postgresql-v3.sh 13 KB

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