heimdalldashboard-v2.sh 6.4 KB

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