heimdalldashboard.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #!/usr/bin/env bash
  2. PP=`echo "\e[1;35m"`
  3. YW=`echo "\033[33m"`
  4. BL=`echo "\033[36m"`
  5. RD=`echo "\033[01;31m"`
  6. CM='\xE2\x9C\x94\033'
  7. GN=`echo "\033[1;92m"`
  8. CL=`echo "\033[m"`
  9. APP="Heimdall Dashboard"
  10. HN=$(echo ${APP,,} | tr -d ' ')
  11. while true; do
  12. read -p "This will create a New ${APP} LXC. Proceed(y/n)?" yn
  13. case $yn in
  14. [Yy]* ) break;;
  15. [Nn]* ) exit;;
  16. * ) echo "Please answer yes or no.";;
  17. esac
  18. done
  19. clear
  20. function header_info {
  21. echo -e "${PP}
  22. _ _ _ _ _ _ _____ _ _ _
  23. | | | | (_) | | | | | | __ \ | | | | | |
  24. | |__| | ___ _ _ __ ___ __| | __ _| | | | | | | __ _ ___| |__ | |__ ___ __ _ _ __ __| |
  25. | __ |/ _ \ | _ _ \ / _ |/ _ | | | | | | |/ _ / __| _ \| _ \ / _ \ / _ | __/ _ |
  26. | | | | __/ | | | | | | (_| | (_| | | | | |__| | (_| \__ \ | | | |_) | (_) | (_| | | | (_| |
  27. |_| |_|\___|_|_| |_| |_|\__,_|\__,_|_|_| |_____/ \__,_|___/_| |_|_.__/ \___/ \__,_|_| \__,_|
  28. ${CL}"
  29. }
  30. header_info
  31. show_menu(){
  32. printf " ${YW} 1)${YW} Privileged ${CL}\n"
  33. printf " ${YW} 2)${GN} Unprivileged ${CL}\n"
  34. printf "Please choose a Install Method and press [ENTER] or ${RD}x${CL} to exit."
  35. read opt
  36. }
  37. option_picked(){
  38. message1=${@:-"${CL}Error: No message passed"}
  39. printf " ${YW}${message1}${CL}\n"
  40. }
  41. show_menu
  42. while [ $opt != '' ]
  43. do
  44. if [ $opt = '' ]; then
  45. exit;
  46. else
  47. case $opt in
  48. 1) clear;
  49. header_info;
  50. option_picked "Using Privileged Install";
  51. IM=0
  52. break;
  53. ;;
  54. 2) clear;
  55. header_info;
  56. option_picked "Using Unprivileged Install";
  57. IM=1
  58. break;
  59. ;;
  60. x)exit;
  61. ;;
  62. \n)exit;
  63. ;;
  64. *)clear;
  65. option_picked "Please choose a Install Method from the menu";
  66. show_menu;
  67. ;;
  68. esac
  69. fi
  70. done
  71. show_menu2(){
  72. printf " ${YW} 1)${GN} Use Automatic Login ${CL}\n"
  73. printf " ${YW} 2)${GN} Use Password (changeme) ${CL}\n"
  74. printf "Please choose a Password Type and press [ENTER] or ${RD}x${CL} to exit."
  75. read opt
  76. }
  77. option_picked(){
  78. message2=${@:-"${CL}Error: No message passed"}
  79. printf " ${YW}${message1}${CL}\n"
  80. printf " ${YW}${message2}${CL}\n"
  81. }
  82. show_menu2
  83. while [ $opt != '' ]
  84. do
  85. if [ $opt = '' ]; then
  86. exit;
  87. else
  88. case $opt in
  89. 1) clear;
  90. header_info;
  91. option_picked "Using Automatic Login";
  92. PW=" "
  93. break;
  94. ;;
  95. 2) clear;
  96. header_info;
  97. option_picked "Using Password (changeme)";
  98. PW="-password changeme"
  99. break;
  100. ;;
  101. x)exit;
  102. ;;
  103. \n)exit;
  104. ;;
  105. *)clear;
  106. option_picked "Please choose a Password Type from the menu";
  107. show_menu2;
  108. ;;
  109. esac
  110. fi
  111. done
  112. show_menu3(){
  113. printf " ${YW} 1)${GN} Automatic DHCP ${CL}\n"
  114. printf " ${YW} 2)${GN} Manual DHCP ${CL}\n"
  115. printf "Please choose a DHCP Type and press [ENTER] or ${RD}x${CL} to exit."
  116. read opt
  117. }
  118. option_picked(){
  119. message3=${@:-"${CL}Error: No message passed"}
  120. printf " ${YW}${message1}${CL}\n"
  121. printf " ${YW}${message2}${CL}\n"
  122. printf " ${YW}${message3}${CL}\n"
  123. }
  124. show_menu3
  125. while [ $opt != '' ]
  126. do
  127. if [ $opt = '' ]; then
  128. exit;
  129. else
  130. case $opt in
  131. 1) clear;
  132. header_info;
  133. option_picked "Using Automatic DHCP";
  134. DHCP=" "
  135. break;
  136. ;;
  137. 2) clear;
  138. header_info;
  139. option_picked "Using Manual DHCP";
  140. DHCP="1"
  141. break;
  142. ;;
  143. x)exit;
  144. ;;
  145. \n)exit;
  146. ;;
  147. *)clear;
  148. option_picked "Please choose a DHCP Type from the menu";
  149. show_menu3;
  150. ;;
  151. esac
  152. fi
  153. done
  154. set -o errexit
  155. set -o errtrace
  156. set -o nounset
  157. set -o pipefail
  158. shopt -s expand_aliases
  159. alias die='EXIT=$? LINE=$LINENO error_exit'
  160. trap die ERR
  161. trap cleanup EXIT
  162. function error_exit() {
  163. trap - ERR
  164. local DEFAULT='Unknown failure occured.'
  165. local REASON="\e[97m${1:-$DEFAULT}\e[39m"
  166. local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
  167. msg "$FLAG $REASON"
  168. [ ! -z ${CTID-} ] && cleanup_ctid
  169. exit $EXIT
  170. }
  171. function warn() {
  172. local REASON="\e[97m$1\e[39m"
  173. local FLAG="\e[93m[WARNING]\e[39m"
  174. msg "$FLAG $REASON"
  175. }
  176. function info() {
  177. local REASON="$1"
  178. local FLAG="\e[36m[INFO]\e[39m"
  179. msg "$FLAG $REASON"
  180. }
  181. function msg() {
  182. local TEXT="$1"
  183. echo -e "$TEXT"
  184. }
  185. function cleanup_ctid() {
  186. if $(pct status $CTID &>/dev/null); then
  187. if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then
  188. pct stop $CTID
  189. fi
  190. pct destroy $CTID
  191. elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then
  192. pvesm free $ROOTFS
  193. fi
  194. }
  195. function cleanup() {
  196. popd >/dev/null
  197. rm -rf $TEMP_DIR
  198. }
  199. if [ "$IM" == "1" ]; then
  200. FEATURES="nesting=1,keyctl=1"
  201. else
  202. FEATURES="nesting=1"
  203. fi
  204. TEMP_DIR=$(mktemp -d)
  205. pushd $TEMP_DIR >/dev/null
  206. export CTID=$(pvesh get /cluster/nextid)
  207. export PCT_OSTYPE=debian
  208. export PCT_OSVERSION=11
  209. export PCT_DISK_SIZE=2
  210. export PCT_OPTIONS="
  211. -features $FEATURES
  212. -hostname $HN
  213. -net0 name=eth0,bridge=vmbr0,ip=dhcp
  214. -onboot 1
  215. -cores 1
  216. -memory 512
  217. -unprivileged ${IM}
  218. ${PW}
  219. "
  220. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  221. STORAGE_TYPE=$(pvesm status -storage $(pct config $CTID | grep rootfs | awk -F ":" '{print $2}') | awk 'NR>1 {print $2}')
  222. if [ "$STORAGE_TYPE" == "zfspool" ]; then
  223. warn "Some addons may not work due to ZFS not supporting 'fallocate'."
  224. fi
  225. LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
  226. cat <<EOF >> $LXC_CONFIG
  227. lxc.cgroup2.devices.allow: a
  228. lxc.cap.drop:
  229. EOF
  230. if [ "$DHCP" == "1" ]; then
  231. MAC=$(pct config $CTID \
  232. | grep -i hwaddr \
  233. | awk '{print substr($2, 31, length($3) 17 ) }') \
  234. echo -e "MAC Address ${BL}$MAC${CL}"
  235. dhcp_reservation(){
  236. printf "Please set DHCP reservation and press [ENTER]."
  237. read
  238. }
  239. dhcp_reservation
  240. fi
  241. echo -en "${GN} Starting LXC Container... "
  242. pct start $CTID
  243. echo -e "${CM}${CL} \r"
  244. alias lxc-cmd="lxc-attach -n $CTID --"
  245. lxc-cmd bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/$HN-install.sh)" || exit
  246. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  247. echo -e "${GN}Successfully created ${APP} LXC to${CL} ${BL}$CTID${CL}.
  248. ${BL}${APP}${CL} should be reachable by going to the following URL.
  249. ${BL}http://${IP}:7990${CL} \n"