tdarr-v5-install.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. $STD apt-get install -y unzip
  83. msg_ok "Installed Dependencies"
  84. msg_info "Installing Tdarr"
  85. mkdir -p /opt/tdarr
  86. cd /opt/tdarr
  87. wget -q https://f000.backblazeb2.com/file/tdarrs/versions/2.00.15/linux_x64/Tdarr_Updater.zip
  88. $STD unzip Tdarr_Updater.zip
  89. chmod +x Tdarr_Updater
  90. $STD ./Tdarr_Updater
  91. msg_ok "Installed Tdarr"
  92. msg_info "Creating Service"
  93. service_path="/etc/systemd/system/tdarr-server.service"
  94. echo "[Unit]
  95. Description=Tdarr Server Daemon
  96. After=network.target
  97. # Enable if using ZFS, edit and enable if other FS mounting is required to access directory
  98. #Requires=zfs-mount.service
  99. [Service]
  100. User=root
  101. Group=root
  102. Type=simple
  103. WorkingDirectory=/opt/tdarr/Tdarr_Server
  104. ExecStartPre=/opt/tdarr/Tdarr_Updater
  105. ExecStart=/opt/tdarr/Tdarr_Server/Tdarr_Server
  106. TimeoutStopSec=20
  107. KillMode=process
  108. Restart=on-failure
  109. [Install]
  110. WantedBy=multi-user.target" >$service_path
  111. service_path="/etc/systemd/system/tdarr-node.service"
  112. echo "[Unit]
  113. Description=Tdarr Node Daemon
  114. After=network.target
  115. Requires=tdarr-server.service
  116. [Service]
  117. User=root
  118. Group=root
  119. Type=simple
  120. WorkingDirectory=/opt/tdarr/Tdarr_Node
  121. ExecStart=/opt/tdarr/Tdarr_Node/Tdarr_Node
  122. TimeoutStopSec=20
  123. KillMode=process
  124. Restart=on-failure
  125. [Install]
  126. WantedBy=multi-user.target" >$service_path
  127. systemctl enable --now -q tdarr-server.service
  128. systemctl enable --now -q tdarr-node.service
  129. msg_ok "Created Service"
  130. PASS=$(grep -w "root" /etc/shadow | cut -b6)
  131. echo "export TERM='xterm-256color'" >>/root/.bashrc
  132. if [[ $PASS != $ ]]; then
  133. msg_info "Customizing Container"
  134. chmod -x /etc/update-motd.d/*
  135. touch ~/.hushlogin
  136. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  137. mkdir -p $(dirname $GETTY_OVERRIDE)
  138. cat <<EOF >$GETTY_OVERRIDE
  139. [Service]
  140. ExecStart=
  141. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  142. EOF
  143. systemctl daemon-reload
  144. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  145. msg_ok "Customized Container"
  146. fi
  147. if [[ "${SSH_ROOT}" == "yes" ]]; then
  148. sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
  149. systemctl restart sshd
  150. fi
  151. msg_info "Cleaning up"
  152. rm -rf Tdarr_Updater.zip
  153. $STD apt-get autoremove
  154. $STD apt-get autoclean
  155. msg_ok "Cleaned"