plex-install.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env bash -ex
  2. set -euo pipefail
  3. shopt -s inherit_errexit nullglob
  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. function msg_info() {
  17. local msg="$1"
  18. echo -ne " ${HOLD} ${YW}${msg}..."
  19. }
  20. function msg_ok() {
  21. local msg="$1"
  22. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  23. }
  24. msg_info "Setting up Container OS "
  25. sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
  26. locale-gen >/dev/null
  27. while [ "$(hostname -I)" = "" ]; do
  28. 1>&2 echo -en "${CROSS}${RD} No Network! "
  29. sleep $RETRY_EVERY
  30. ((NUM--))
  31. if [ $NUM -eq 0 ]
  32. then
  33. 1>&2 echo -e "${CROSS}${RD} No Network After $RETRY_NUM Tries${CL}"
  34. exit 1
  35. fi
  36. done
  37. msg_ok "Set up Container OS"
  38. msg_ok "Network Connected: ${BL}$(hostname -I)"
  39. msg_info "Updating Container OS"
  40. apt update &>/dev/null
  41. apt-get -qqy upgrade &>/dev/null
  42. msg_ok "Updated Container OS"
  43. msg_info "Installing Dependencies"
  44. apt-get install -y curl &>/dev/null
  45. apt-get install -y sudo &>/dev/null
  46. apt-get install -y gnupg &>/dev/null
  47. msg_ok "Installed Dependencies"
  48. msg_info "Setting Up Hardware Acceleration"
  49. apt-get -y install \
  50. va-driver-all \
  51. ocl-icd-libopencl1 \
  52. beignet-opencl-icd &>/dev/null
  53. /bin/chgrp video /dev/dri
  54. /bin/chmod 755 /dev/dri
  55. /bin/chmod 660 /dev/dri/*
  56. msg_ok "Set Up Hardware Acceleration"
  57. msg_info "Setting Up Plex Media Server Repository"
  58. wget -q https://downloads.plex.tv/plex-keys/PlexSign.key -O - | sudo apt-key add - &>/dev/null
  59. echo "deb [arch=$( dpkg --print-architecture )] https://downloads.plex.tv/repo/deb/ public main" | tee /etc/apt/sources.list.d/plexmediaserver.list &>/dev/null
  60. msg_ok "Set Up Plex Media Server Repository"
  61. msg_info "Installing Plex Media Server"
  62. apt-get update &>/dev/null
  63. apt-get -o Dpkg::Options::="--force-confold" install -y plexmediaserver &>/dev/null
  64. msg_ok "Installed Plex Media Server"
  65. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  66. if [[ $PASS != $ ]]; then
  67. msg_info "Customizing Container"
  68. chmod -x /etc/update-motd.d/*
  69. touch ~/.hushlogin
  70. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  71. mkdir -p $(dirname $GETTY_OVERRIDE)
  72. cat << EOF > $GETTY_OVERRIDE
  73. [Service]
  74. ExecStart=
  75. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  76. EOF
  77. systemctl daemon-reload
  78. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  79. msg_ok "Customized Container"
  80. fi
  81. msg_info "Cleaning up"
  82. apt-get autoremove >/dev/null
  83. apt-get autoclean >/dev/null
  84. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  85. msg_ok "Cleaned"