daemonsync-v3.sh 11 KB

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