scrypted-v5-install.sh 5.8 KB

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