debian-v3.sh 12 KB

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