heimdalldashboard-v5-install.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env bash
  2. if [ "$VERBOSE" == "yes" ]; then set -x; fi
  3. if [ "$DISABLEIPV6" == "yes" ]; then echo "net.ipv6.conf.all.disable_ipv6 = 1" >>/etc/sysctl.conf; fi
  4. YW=$(echo "\033[33m")
  5. RD=$(echo "\033[01;31m")
  6. BL=$(echo "\033[36m")
  7. GN=$(echo "\033[1;92m")
  8. CL=$(echo "\033[m")
  9. RETRY_NUM=10
  10. RETRY_EVERY=3
  11. NUM=$RETRY_NUM
  12. CM="${GN}✓${CL}"
  13. CROSS="${RD}✗${CL}"
  14. BFR="\\r\\033[K"
  15. HOLD="-"
  16. set -o errexit
  17. set -o errtrace
  18. set -o nounset
  19. set -o pipefail
  20. shopt -s expand_aliases
  21. alias die='EXIT=$? LINE=$LINENO error_exit'
  22. trap die ERR
  23. silent() { "$@" > /dev/null 2>&1; }
  24. function error_exit() {
  25. trap - ERR
  26. local reason="Unknown failure occurred."
  27. local msg="${1:-$reason}"
  28. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  29. echo -e "$flag $msg" 1>&2
  30. exit $EXIT
  31. }
  32. function msg_info() {
  33. local msg="$1"
  34. echo -ne " ${HOLD} ${YW}${msg}..."
  35. }
  36. function msg_ok() {
  37. local msg="$1"
  38. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  39. }
  40. function msg_error() {
  41. local msg="$1"
  42. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  43. }
  44. msg_info "Setting up Container OS "
  45. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  46. locale-gen >/dev/null
  47. while [ "$(hostname -I)" = "" ]; do
  48. echo 1>&2 -en "${CROSS}${RD} No Network! "
  49. sleep $RETRY_EVERY
  50. ((NUM--))
  51. if [ $NUM -eq 0 ]; then
  52. echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  53. exit 1
  54. fi
  55. done
  56. msg_ok "Set up Container OS"
  57. msg_ok "Network Connected: ${BL}$(hostname -I)"
  58. set +e
  59. alias die=''
  60. if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else
  61. msg_error "Internet NOT Connected"
  62. read -r -p "Would you like to continue anyway? <y/N> " prompt
  63. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  64. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  65. else
  66. echo -e " 🖧 Check Network Settings"
  67. exit 1
  68. fi
  69. fi
  70. RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
  71. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi
  72. alias die='EXIT=$? LINE=$LINENO error_exit'
  73. set -e
  74. msg_info "Updating Container OS"
  75. $STD apt-get update
  76. $STD apt-get -y upgrade
  77. msg_ok "Updated Container OS"
  78. msg_info "Installing Dependencies"
  79. $STD apt-get install -y curl
  80. $STD apt-get install -y sudo
  81. $STD apt-get install -y mc
  82. msg_ok "Installed Dependencies"
  83. msg_info "Installing PHP"
  84. $STD apt-get install -y php
  85. $STD apt-get install -y php-sqlite3
  86. $STD apt-get install -y php-zip
  87. msg_ok "Installed PHP"
  88. RELEASE=$(curl -sX GET "https://api.github.com/repos/linuxserver/Heimdall/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]')
  89. msg_info "Installing Heimdall Dashboard ${RELEASE}"
  90. $STD curl --silent -o ${RELEASE}.tar.gz -L "https://github.com/linuxserver/Heimdall/archive/${RELEASE}.tar.gz"
  91. $STD tar xvzf ${RELEASE}.tar.gz
  92. VER=$(curl -s https://api.github.com/repos/linuxserver/Heimdall/releases/latest |
  93. grep "tag_name" |
  94. awk '{print substr($2, 3, length($2)-4) }')
  95. rm -rf ${RELEASE}.tar.gz
  96. mv Heimdall-${VER} /opt/Heimdall
  97. msg_ok "Installed Heimdall Dashboard ${RELEASE}"
  98. msg_info "Creating Service"
  99. service_path="/etc/systemd/system/heimdall.service"
  100. echo "[Unit]
  101. Description=Heimdall
  102. After=network.target
  103. [Service]
  104. Restart=always
  105. RestartSec=5
  106. Type=simple
  107. User=root
  108. WorkingDirectory=/opt/Heimdall
  109. ExecStart="/usr/bin/php" artisan serve --port 7990 --host 0.0.0.0
  110. TimeoutStopSec=30
  111. [Install]
  112. WantedBy=multi-user.target" >$service_path
  113. $STD sudo systemctl enable --now heimdall.service
  114. msg_ok "Created Service"
  115. PASS=$(grep -w "root" /etc/shadow | cut -b6)
  116. echo "export TERM='xterm-256color'" >>/root/.bashrc
  117. if [[ $PASS != $ ]]; then
  118. msg_info "Customizing Container"
  119. rm /etc/motd
  120. rm /etc/update-motd.d/10-uname
  121. touch ~/.hushlogin
  122. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  123. mkdir -p $(dirname $GETTY_OVERRIDE)
  124. cat <<EOF >$GETTY_OVERRIDE
  125. [Service]
  126. ExecStart=
  127. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  128. EOF
  129. systemctl daemon-reload
  130. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  131. msg_ok "Customized Container"
  132. fi
  133. if [[ "${SSH_ROOT}" == "yes" ]]; then
  134. sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
  135. systemctl restart sshd
  136. fi
  137. msg_info "Cleaning up"
  138. $STD apt-get autoremove
  139. $STD apt-get autoclean
  140. msg_ok "Cleaned"