heimdalldashboard-install.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o errtrace
  4. set -o nounset
  5. set -o pipefail
  6. shopt -s expand_aliases
  7. alias die='EXIT=$? LINE=$LINENO error_exit'
  8. trap die ERR
  9. trap 'die "Script interrupted."' INT
  10. function error_exit() {
  11. trap - ERR
  12. local DEFAULT='Unknown failure occured.'
  13. local REASON="\e[97m${1:-$DEFAULT}\e[39m"
  14. local FLAG="\e[91m[ERROR:LXC] \e[93m$EXIT@$LINE"
  15. msg "$FLAG $REASON"
  16. exit $EXIT
  17. }
  18. function msg() {
  19. local TEXT="$1"
  20. echo -e "$TEXT"
  21. }
  22. CROSS='\033[1;31m\xE2\x9D\x8C\033[0m'
  23. RD=`echo "\033[01;31m"`
  24. BL=`echo "\033[36m"`
  25. CM='\xE2\x9C\x94\033'
  26. GN=`echo "\033[1;92m"`
  27. CL=`echo "\033[m"`
  28. RETRY_NUM=10
  29. RETRY_EVERY=3
  30. NUM=$RETRY_NUM
  31. echo -en "${GN} Setting up Container OS... "
  32. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  33. locale-gen >/dev/null
  34. while [ "$(hostname -I)" = "" ]; do
  35. 1>&2 echo -en "${CROSS}${RD} No Network! "
  36. sleep $RETRY_EVERY
  37. ((NUM--))
  38. if [ $NUM -eq 0 ]
  39. then
  40. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  41. exit 1
  42. fi
  43. done
  44. echo -e "${CM}${CL} \r"
  45. echo -en "${GN} Network Connected: ${BL}$(hostname -I)${CL} "
  46. echo -e "${CM}${CL} \r"
  47. echo -en "${GN} Updating Container OS... "
  48. apt update &>/dev/null
  49. apt-get -qqy upgrade &>/dev/null
  50. echo -e "${CM}${CL} \r"
  51. echo -en "${GN} Installing Dependencies... "
  52. apt-get install -y curl &>/dev/null
  53. apt-get install -y sudo &>/dev/null
  54. echo -e "${CM}${CL} \r"
  55. echo -en "${GN} Installing PHP... "
  56. apt-get install -y php &>/dev/null
  57. apt-get install -y php-sqlite3 &>/dev/null
  58. apt-get install -y php-zip &>/dev/null
  59. echo -e "${CM}${CL} \r"
  60. RELEASE=$(curl -sX GET "https://api.github.com/repos/linuxserver/Heimdall/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]')
  61. echo -en "${GN} Installing Heimdall Dashboard ${RELEASE}... "
  62. curl --silent -o ${RELEASE}.tar.gz -L "https://github.com/linuxserver/Heimdall/archive/${RELEASE}.tar.gz" &>/dev/null
  63. tar xvzf ${RELEASE}.tar.gz &>/dev/null
  64. VER=$(curl -s https://api.github.com/repos/linuxserver/Heimdall/releases/latest \
  65. | grep "tag_name" \
  66. | awk '{print substr($2, 3, length($2)-4) }')
  67. rm -rf ${RELEASE}.tar.gz
  68. mv Heimdall-${VER} /opt/Heimdall
  69. echo -e "${CM}${CL} \r"
  70. echo -en "${GN} Creating Service... "
  71. service_path="/etc/systemd/system/heimdall.service"
  72. echo "[Unit]
  73. Description=Heimdall
  74. After=network.target
  75. [Service]
  76. Restart=always
  77. RestartSec=5
  78. Type=simple
  79. User=root
  80. WorkingDirectory=/opt/Heimdall
  81. ExecStart="/usr/bin/php" artisan serve --port 7990 --host 0.0.0.0
  82. TimeoutStopSec=30
  83. [Install]
  84. WantedBy=multi-user.target" > $service_path
  85. sudo systemctl enable --now heimdall.service &>/dev/null
  86. echo -e "${CM}${CL} \r"
  87. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  88. if [[ $PASS != $ ]]; then
  89. echo -en "${GN} Customizing Container... "
  90. rm /etc/motd
  91. rm /etc/update-motd.d/10-uname
  92. touch ~/.hushlogin
  93. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  94. mkdir -p $(dirname $GETTY_OVERRIDE)
  95. cat << EOF > $GETTY_OVERRIDE
  96. [Service]
  97. ExecStart=
  98. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  99. EOF
  100. systemctl daemon-reload
  101. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  102. echo -e "${CM}${CL} \r"
  103. fi
  104. echo -en "${GN} Cleanup... "
  105. apt-get autoremove >/dev/null
  106. apt-get autoclean >/dev/null
  107. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  108. echo -e "${CM}${CL} \n"