plex-install.sh 2.9 KB

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