adguard-v3.sh 12 KB

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