scrypted-v5-install.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #!/usr/bin/env bash
  2. if [ "$VERBOSE" == "yes" ]; then set -x; fi
  3. YW=$(echo "\033[33m")
  4. RD=$(echo "\033[01;31m")
  5. BL=$(echo "\033[36m")
  6. GN=$(echo "\033[1;92m")
  7. CL=$(echo "\033[m")
  8. RETRY_NUM=10
  9. RETRY_EVERY=3
  10. NUM=$RETRY_NUM
  11. CM="${GN}✓${CL}"
  12. CROSS="${RD}✗${CL}"
  13. BFR="\\r\\033[K"
  14. HOLD="-"
  15. set -o errexit
  16. set -o errtrace
  17. set -o nounset
  18. set -o pipefail
  19. shopt -s expand_aliases
  20. alias die='EXIT=$? LINE=$LINENO error_exit'
  21. trap die ERR
  22. silent() { "$@" > /dev/null 2>&1; }
  23. function error_exit() {
  24. trap - ERR
  25. local reason="Unknown failure occurred."
  26. local msg="${1:-$reason}"
  27. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  28. echo -e "$flag $msg" 1>&2
  29. exit $EXIT
  30. }
  31. function msg_info() {
  32. local msg="$1"
  33. echo -ne " ${HOLD} ${YW}${msg}..."
  34. }
  35. function msg_ok() {
  36. local msg="$1"
  37. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  38. }
  39. function msg_error() {
  40. local msg="$1"
  41. echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
  42. }
  43. msg_info "Setting up Container OS "
  44. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  45. locale-gen >/dev/null
  46. while [ "$(hostname -I)" = "" ]; do
  47. echo 1>&2 -en "${CROSS}${RD} No Network! "
  48. sleep $RETRY_EVERY
  49. ((NUM--))
  50. if [ $NUM -eq 0 ]; then
  51. echo 1>&2 -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  52. exit 1
  53. fi
  54. done
  55. msg_ok "Set up Container OS"
  56. msg_ok "Network Connected: ${BL}$(hostname -I)"
  57. set +e
  58. alias die=''
  59. if nc -zw1 8.8.8.8 443; then msg_ok "Internet Connected"; else
  60. msg_error "Internet NOT Connected"
  61. read -r -p "Would you like to continue anyway? <y/N> " prompt
  62. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  63. echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}"
  64. else
  65. echo -e " 🖧 Check Network Settings"
  66. exit 1
  67. fi
  68. fi
  69. RESOLVEDIP=$(nslookup "github.com" | awk -F':' '/^Address: / { matched = 1 } matched { print $2}' | xargs)
  70. if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to $RESOLVEDIP"; fi
  71. alias die='EXIT=$? LINE=$LINENO error_exit'
  72. set -e
  73. msg_info "Updating Container OS"
  74. $STD apt-get update
  75. $STD apt-get -y upgrade
  76. msg_ok "Updated Container OS"
  77. msg_info "Installing Dependencies"
  78. $STD apt-get -y install software-properties-common apt-utils
  79. $STD apt-get -y update
  80. $STD apt-get -y upgrade
  81. $STD apt-get -y install \
  82. build-essential \
  83. gcc \
  84. gir1.2-gtk-3.0 \
  85. libcairo2-dev \
  86. libgirepository1.0-dev \
  87. libglib2.0-dev \
  88. libjpeg-dev \
  89. libgif-dev \
  90. libopenjp2-7 \
  91. libpango1.0-dev \
  92. librsvg2-dev \
  93. pkg-config \
  94. curl \
  95. sudo
  96. msg_ok "Installed Dependencies"
  97. msg_info "Installing GStreamer"
  98. $STD apt-get -y install \
  99. gstreamer1.0-tools \
  100. libgstreamer1.0-dev \
  101. libgstreamer-plugins-base1.0-dev \
  102. libgstreamer-plugins-bad1.0-dev \
  103. gstreamer1.0-plugins-base \
  104. gstreamer1.0-plugins-good \
  105. gstreamer1.0-plugins-bad \
  106. gstreamer1.0-plugins-ugly \
  107. gstreamer1.0-libav \
  108. gstreamer1.0-alsa
  109. msg_ok "Installed GStreamer"
  110. msg_info "Setting up Node.js Repository"
  111. $STD bash <(curl -fsSL https://deb.nodesource.com/setup_18.x)
  112. msg_ok "Set up Node.js Repository"
  113. msg_info "Installing Node.js"
  114. $STD apt-get install -y nodejs
  115. msg_ok "Installed Node.js"
  116. msg_info "Installing Python3"
  117. $STD apt-get -y install \
  118. python3 \
  119. python3-dev \
  120. python3-gi \
  121. python3-gst-1.0 \
  122. python3-matplotlib \
  123. python3-numpy \
  124. python3-opencv \
  125. python3-pil \
  126. python3-pip \
  127. python3-setuptools \
  128. python3-skimage \
  129. python3-wheel
  130. $STD python3 -m pip install --upgrade pip
  131. $STD python3 -m pip install aiofiles debugpy typing_extensions typing
  132. msg_ok "Installed Python3"
  133. read -r -p "Would you like to add Coral Edge TPU support? <y/N> " prompt
  134. if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
  135. CORAL="Y"
  136. else
  137. CORAL="N"
  138. fi
  139. if [[ $CORAL == "Y" ]]; then
  140. msg_info "Adding Coral Edge TPU Support"
  141. $STD apt-key add <(curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg)
  142. cat <<EOF >/etc/apt/sources.list.d/coral-edgetpu.list
  143. deb https://packages.cloud.google.com/apt coral-edgetpu-stable main
  144. EOF
  145. $STD apt-get -y update
  146. $STD apt-get -y install libedgetpu1-std
  147. msg_ok "Coral Edge TPU Support Added"
  148. fi
  149. msg_info "Installing Scrypted"
  150. $STD sudo -u root npx -y scrypted@latest install-server
  151. msg_info "Installed Scrypted"
  152. msg_info "Creating Service"
  153. service_path="/etc/systemd/system/scrypted.service"
  154. echo "[Unit]
  155. Description=Scrypted service
  156. After=network.target
  157. [Service]
  158. User=root
  159. Group=root
  160. Type=simple
  161. ExecStart=/usr/bin/npx -y scrypted serve
  162. Restart=on-failure
  163. RestartSec=3
  164. [Install]
  165. WantedBy=multi-user.target" >$service_path
  166. $STD systemctl enable --now scrypted.service
  167. msg_ok "Created Service"
  168. PASS=$(grep -w "root" /etc/shadow | cut -b6)
  169. if [[ $PASS != $ ]]; then
  170. msg_info "Customizing Container"
  171. chmod -x /etc/update-motd.d/*
  172. touch ~/.hushlogin
  173. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  174. mkdir -p $(dirname $GETTY_OVERRIDE)
  175. cat <<EOF >$GETTY_OVERRIDE
  176. [Service]
  177. ExecStart=
  178. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  179. EOF
  180. systemctl daemon-reload
  181. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  182. msg_ok "Customized Container"
  183. fi
  184. if [[ "${SSH_ROOT}" == "yes" ]]; then
  185. sed -i "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
  186. systemctl restart sshd
  187. fi
  188. msg_info "Cleaning up"
  189. $STD apt-get autoremove
  190. $STD apt-get autoclean
  191. msg_ok "Cleaned"