dashy.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/usr/bin/env bash
  2. clear
  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. while true; do
  10. read -p "This will create a New Dashy LXC. Proceed(y/n)?" yn
  11. case $yn in
  12. [Yy]* ) break;;
  13. [Nn]* ) exit;;
  14. * ) echo "Please answer yes or no.";;
  15. esac
  16. done
  17. clear
  18. function header_info {
  19. echo -e "${RD}
  20. _____ _
  21. | __ \ | |
  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 hit enter or ${RD}x${CL} to exit."
  35. read opt
  36. }
  37. option_picked(){
  38. message=${@:-"${CL}Error: No message passed"}
  39. printf " ${YW}${message}${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. set -o errexit
  72. set -o errtrace
  73. set -o nounset
  74. set -o pipefail
  75. shopt -s expand_aliases
  76. alias die='EXIT=$? LINE=$LINENO error_exit'
  77. trap die ERR
  78. trap cleanup EXIT
  79. function error_exit() {
  80. trap - ERR
  81. local DEFAULT='Unknown failure occured.'
  82. local REASON="\e[97m${1:-$DEFAULT}\e[39m"
  83. local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE"
  84. msg "$FLAG $REASON"
  85. [ ! -z ${CTID-} ] && cleanup_ctid
  86. exit $EXIT
  87. }
  88. function warn() {
  89. local REASON="\e[97m$1\e[39m"
  90. local FLAG="\e[93m[WARNING]\e[39m"
  91. msg "$FLAG $REASON"
  92. }
  93. function info() {
  94. local REASON="$1"
  95. local FLAG="\e[36m[INFO]\e[39m"
  96. msg "$FLAG $REASON"
  97. }
  98. function msg() {
  99. local TEXT="$1"
  100. echo -e "$TEXT"
  101. }
  102. function cleanup_ctid() {
  103. if $(pct status $CTID &>/dev/null); then
  104. if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then
  105. pct stop $CTID
  106. fi
  107. pct destroy $CTID
  108. elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then
  109. pvesm free $ROOTFS
  110. fi
  111. }
  112. function cleanup() {
  113. popd >/dev/null
  114. rm -rf $TEMP_DIR
  115. }
  116. if [ "$IM" == "1" ]; then
  117. FEATURES="nesting=1,keyctl=1,mknod=1"
  118. else
  119. FEATURES="nesting=1"
  120. fi
  121. TEMP_DIR=$(mktemp -d)
  122. pushd $TEMP_DIR >/dev/null
  123. export CTID=$(pvesh get /cluster/nextid)
  124. export PCT_OSTYPE=debian
  125. export PCT_OSVERSION=11
  126. export PCT_DISK_SIZE=3
  127. export PCT_OPTIONS="
  128. -features $FEATURES
  129. -hostname dashy
  130. -net0 name=eth0,bridge=vmbr0,ip=dhcp
  131. -onboot 1
  132. -cores 2
  133. -memory 2048
  134. -unprivileged ${IM}
  135. "
  136. bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/ct/create_lxc.sh)" || exit
  137. STORAGE_TYPE=$(pvesm status -storage $(pct config $CTID | grep rootfs | awk -F ":" '{print $2}') | awk 'NR>1 {print $2}')
  138. if [ "$STORAGE_TYPE" == "zfspool" ]; then
  139. warn "Some addons may not work due to ZFS not supporting 'fallocate'."
  140. fi
  141. echo -en "${GN} Starting LXC Container... "
  142. pct start $CTID
  143. echo -e "${CM}${CL} \r"
  144. alias lxc-cmd="lxc-attach -n $CTID --"
  145. lxc-cmd bash -c "$(wget -qLO - https://raw.githubusercontent.com/tteck/Proxmox/main/setup/dashy-install.sh)" || exit
  146. IP=$(pct exec $CTID ip a s dev eth0 | sed -n '/inet / s/\// /p' | awk '{print $2}')
  147. echo -e "${GN}Successfully created Dashy LXC to${CL} ${BL}$CTID${CL}.
  148. ${BL}Dashy${CL} should be reachable by going to the following URL.
  149. ${BL}http://${IP}:4000${CL} \n"