podman-homeassistant-v3.sh 11 KB

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