technitiumdns.sh 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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="Debian"
  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 "${RD}
  29. _______ _ _ _ _
  30. |__ __| | | (_) | (_)
  31. | | ___v3___| |__ _ __ _| |_ _ _ _ _ __ ___
  32. | |/ _ \/ __| _ \| _ \| | __| | | | | _ _ \
  33. | | __/ (__| | | | | | | | |_| | |_| | | | | | |
  34. |_|\___|\___|_| |_|_| |_|_|\__|_|\__,_|_| |_| |_|
  35. ${CL}"
  36. }
  37. header_info
  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. function PVE_CHECK() {
  47. PVE=$(pveversion | grep "pve-manager/7" | wc -l)
  48. if [[ $PVE != 1 ]]; then
  49. echo -e "${RD}This script requires Proxmox Virtual Environment 7.0 or greater${CL}"
  50. echo -e "Exiting..."
  51. sleep 2
  52. exit
  53. fi
  54. }
  55. function default_settings() {
  56. clear
  57. header_info
  58. echo -e "${BL}Using Default Settings${CL}"
  59. echo -e "${DGN}Using CT Type ${BGN}Unprivileged${CL} ${RD}NO DEVICE PASSTHROUGH${CL}"
  60. CT_TYPE="1"
  61. echo -e "${DGN}Using CT Password ${BGN}Automatic Login${CL}"
  62. PW=" "
  63. echo -e "${DGN}Using ID ${BGN}$NEXTID${CL}"
  64. CT_ID=$NEXTID
  65. echo -e "${DGN}Using CT Name ${BGN}$NSAPP${CL}"
  66. HN=$NSAPP
  67. echo -e "${DGN}Using Disk Size ${BGN}2GB${CL}"
  68. DISK_SIZE="2"
  69. echo -e "${DGN}Using ${BGN}1vCPU${CL}"
  70. CORE_COUNT="1"
  71. echo -e "${DGN}Using ${BGN}512MiB${CL}${GN} RAM${CL}"
  72. RAM_SIZE="512"
  73. echo -e "${DGN}Using IP Address ${BGN}DHCP${CL}"
  74. NET=dhcp
  75. echo -e "${DGN}Using VLAN Tag ${BGN}NONE${CL}"
  76. VLAN=" "
  77. }
  78. function advanced_settings() {
  79. clear
  80. header_info
  81. echo -e "${RD}Using Advanced Settings${CL}"
  82. echo -e "${YW}Type Privileged, or Press [ENTER] for Default: Unprivileged (${RD}NO DEVICE PASSTHROUGH${CL}${YW})"
  83. read CT_TYPE1
  84. if [ -z $CT_TYPE1 ]; then CT_TYPE1="Unprivileged" CT_TYPE="1";
  85. echo -en "${DGN}Set CT Type ${BL}$CT_TYPE1${CL}"
  86. else
  87. CT_TYPE1="Privileged"
  88. CT_TYPE="0"
  89. echo -en "${DGN}Set CT Type ${BL}Privileged${CL}"
  90. fi;
  91. echo -e " ${CM}${CL} \r"
  92. sleep 1
  93. clear
  94. header_info
  95. echo -e "${RD}Using Advanced Settings${CL}"
  96. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  97. echo -e "${YW}Set Password, or Press [ENTER] for Default: Automatic Login "
  98. read PW1
  99. if [ -z $PW1 ]; then PW1="Automatic Login" PW=" ";
  100. echo -en "${DGN}Set CT ${BL}$PW1${CL}"
  101. else
  102. PW="-password $PW1"
  103. echo -en "${DGN}Set CT Password ${BL}$PW1${CL}"
  104. fi;
  105. echo -e " ${CM}${CL} \r"
  106. sleep 1
  107. clear
  108. header_info
  109. echo -e "${RD}Using Advanced Settings${CL}"
  110. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  111. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  112. echo -e "${YW}Enter the CT ID, or Press [ENTER] to automatically generate (${NEXTID}) "
  113. read CT_ID
  114. if [ -z $CT_ID ]; then CT_ID=$NEXTID; fi;
  115. echo -en "${DGN}Set CT ID To ${BL}$CT_ID${CL}"
  116. echo -e " ${CM}${CL} \r"
  117. sleep 1
  118. clear
  119. header_info
  120. echo -e "${RD}Using Advanced Settings${CL}"
  121. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  122. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  123. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  124. echo -e "${YW}Enter CT Name (no-spaces), or Press [ENTER] for Default: $NSAPP "
  125. read CT_NAME
  126. if [ -z $CT_NAME ]; then
  127. HN=$NSAPP
  128. else
  129. HN=$(echo ${CT_NAME,,} | tr -d ' ')
  130. fi
  131. echo -en "${DGN}Set CT Name To ${BL}$HN${CL}"
  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 "${DGN}Using ID ${BGN}$CT_ID${CL}"
  140. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  141. echo -e "${YW}Enter a Disk Size, or Press [ENTER] for Default: 2Gb "
  142. read DISK_SIZE
  143. if [ -z $DISK_SIZE ]; then DISK_SIZE="2"; fi;
  144. if ! [[ $DISK_SIZE =~ $INTEGER ]] ; then echo "ERROR! DISK SIZE MUST HAVE INTEGER NUMBER!"; exit; fi;
  145. echo -en "${DGN}Set Disk Size To ${BL}$DISK_SIZE${CL}"
  146. echo -e " ${CM}${CL} \r"
  147. sleep 1
  148. clear
  149. header_info
  150. echo -e "${RD}Using Advanced Settings${CL}"
  151. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  152. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  153. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  154. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  155. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  156. echo -e "${YW}Allocate CPU cores, or Press [ENTER] for Default: 1 "
  157. read CORE_COUNT
  158. if [ -z $CORE_COUNT ]; then CORE_COUNT="1"; fi;
  159. echo -en "${DGN}Set Cores To ${BL}$CORE_COUNT${CL}"
  160. echo -e " ${CM}${CL} \r"
  161. sleep 1
  162. clear
  163. header_info
  164. echo -e "${RD}Using Advanced Settings${CL}"
  165. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  166. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  167. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  168. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  169. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  170. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  171. echo -e "${YW}Allocate RAM in MiB, or Press [ENTER] for Default: 512 "
  172. read RAM_SIZE
  173. if [ -z $RAM_SIZE ]; then RAM_SIZE="512"; fi;
  174. echo -en "${DGN}Set RAM To ${BL}$RAM_SIZE${CL}"
  175. echo -e " ${CM}${CL} \n"
  176. sleep 1
  177. clear
  178. header_info
  179. echo -e "${RD}Using Advanced Settings${CL}"
  180. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  181. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  182. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  183. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  184. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  185. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  186. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${GN} RAM${CL}"
  187. echo -e "${YW}Enter a IP Address, or Press [ENTER] for Default: DHCP "
  188. read NET
  189. if [ -z $NET ]; then NET="dhcp"; fi;
  190. echo -en "${DGN}Set IP Address To ${BL}$NET${CL}"
  191. echo -e " ${CM}${CL} \n"
  192. sleep 1
  193. clear
  194. header_info
  195. echo -e "${RD}Using Advanced Settings${CL}"
  196. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  197. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  198. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  199. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  200. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  201. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  202. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${GN} RAM${CL}"
  203. echo -e "${DGN}Using IP Address ${BGN}$NET${CL}"
  204. echo -e "${YW}Enter a VLAN Tag, or Press [ENTER] for Default: NONE "
  205. read VLAN1
  206. if [ -z $VLAN1 ]; then VLAN1="NONE" VLAN=" ";
  207. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  208. else
  209. VLAN="-tag $VLAN1"
  210. echo -en "${DGN}Set VLAN Tag To ${BL}$VLAN1${CL}"
  211. fi;
  212. echo -e " ${CM}${CL} \n"
  213. sleep 1
  214. clear
  215. header_info
  216. echo -e "${RD}Using Advanced Settings${CL}"
  217. echo -e "${DGN}Using CT Type ${BGN}$CT_TYPE1${CL}"
  218. echo -e "${DGN}Using CT Password ${BGN}$PW1${CL}"
  219. echo -e "${DGN}Using ID ${BGN}$CT_ID${CL}"
  220. echo -e "${DGN}Using CT Name ${BGN}$HN${CL}"
  221. echo -e "${DGN}Using Disk Size ${BGN}$DISK_SIZE${CL}"
  222. echo -e "${DGN}Using ${BGN}${CORE_COUNT}vCPU${CL}"
  223. echo -e "${DGN}Using ${BGN}${RAM_SIZE}MiB${CL}${GN} RAM${CL}"
  224. echo -e "${DGN}Using IP Address ${BGN}$NET${CL}"
  225. echo -e "${DGN}Using VLAN Tag ${BGN}$VLAN1${CL}"
  226. read -p "Are these settings correct(y/n)? " -n 1 -r
  227. echo
  228. if [[ ! $REPLY =~ ^[Yy]$ ]]
  229. then
  230. advanced_settings
  231. fi
  232. }
  233. function start_script() {
  234. echo -e "${YW}Type Advanced, or Press [ENTER] for Default Settings "
  235. read SETTINGS
  236. if [ -z $SETTINGS ]; then default_settings;
  237. else
  238. advanced_settings
  239. fi;
  240. }
  241. start_script
  242. if [ "$CT_TYPE" == "1" ]; then
  243. FEATURES="nesting=1,keyctl=1"
  244. else
  245. FEATURES="nesting=1"
  246. fi
  247. TEMP_DIR=$(mktemp -d)
  248. pushd $TEMP_DIR >/dev/null
  249. export CTID=$CT_ID
  250. export PCT_OSTYPE=debian
  251. export PCT_OSVERSION=11
  252. export PCT_DISK_SIZE=$DISK_SIZE
  253. export PCT_OPTIONS="
  254. -features $FEATURES
  255. -hostname $HN
  256. -net0 name=eth0,bridge=vmbr0,ip=$NET
  257. $VLAN
  258. -onboot 1
  259. -cores $CORE_COUNT
  260. -memory $RAM_SIZE
  261. -unprivileged $CT_TYPE
  262. $PW
  263. "
  264. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  265. STORAGE_TYPE=$(pvesm status -storage $(pct config $CTID | grep rootfs | awk -F ":" '{print $2}') | awk 'NR>1 {print $2}')
  266. if [ "$STORAGE_TYPE" == "zfspool" ]; then
  267. warn "Some addons may not work due to ZFS not supporting 'fallocate'."
  268. fi
  269. msg_info "Starting LXC Container"
  270. pct start $CTID
  271. msg_ok "Started LXC Container"
  272. lxc-attach -n $CTID -- bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/technitiumdns-install.sh)" || exit
  273. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  274. msg_ok "Completed Successfully!\n"
  275. echo -e "${APP} should be reachable by going to the following URL.
  276. ${BL}http://${IP}:5380${CL} \n"