jellyfin-install.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 apt-transport-https &>/dev/null
  47. apt-get install -y software-properties-common &>/dev/null
  48. msg_ok "Installed Dependencies"
  49. msg_info "Setting Up Hardware Acceleration"
  50. apt-get -y install \
  51. va-driver-all \
  52. ocl-icd-libopencl1 \
  53. beignet-opencl-icd &>/dev/null
  54. /bin/chgrp video /dev/dri
  55. /bin/chmod 755 /dev/dri
  56. /bin/chmod 660 /dev/dri/*
  57. msg_ok "Set Up Hardware Acceleration"
  58. msg_info "Setting Up Jellyfin Repository"
  59. sudo add-apt-repository universe -y &>/dev/null
  60. wget -q -O - https://repo.jellyfin.org/ubuntu/jellyfin_team.gpg.key | sudo apt-key add - &>/dev/null
  61. echo "deb [arch=$( dpkg --print-architecture )] https://repo.jellyfin.org/ubuntu $( lsb_release -c -s ) main" | sudo tee /etc/apt/sources.list.d/jellyfin.list &>/dev/null
  62. msg_ok "Set Up Jellyfin Repository"
  63. msg_info "Installing Jellyfin"
  64. apt-get update &>/dev/null
  65. sudo apt install jellyfin-server -y &>/dev/null
  66. msg_ok "Installed Jellyfin"
  67. msg_info "Creating Service"
  68. cat << 'EOF' > /lib/systemd/system/jellyfin.service
  69. [Unit]
  70. Description = Jellyfin Media Server
  71. After = network.target
  72. [Service]
  73. Type = simple
  74. EnvironmentFile = /etc/default/jellyfin
  75. User = root
  76. ExecStart = /usr/bin/jellyfin ${JELLYFIN_WEB_OPT} ${JELLYFIN_RESTART_OPT} ${JELLYFIN_FFMPEG_OPT} ${JELL>
  77. Restart = on-failure
  78. TimeoutSec = 15
  79. [Install]
  80. WantedBy = multi-user.target
  81. EOF
  82. ln -s /usr/share/jellyfin/web/ /usr/lib/jellyfin/bin/jellyfin-web
  83. msg_ok "Created Service"
  84. PASS=$(grep -w "root" /etc/shadow | cut -b6);
  85. if [[ $PASS != $ ]]; then
  86. msg_info "Customizing Container"
  87. chmod -x /etc/update-motd.d/*
  88. touch ~/.hushlogin
  89. GETTY_OVERRIDE="/etc/systemd/system/container-getty@1.service.d/override.conf"
  90. mkdir -p $(dirname $GETTY_OVERRIDE)
  91. cat << EOF > $GETTY_OVERRIDE
  92. [Service]
  93. ExecStart=
  94. ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM
  95. EOF
  96. systemctl daemon-reload
  97. systemctl restart $(basename $(dirname $GETTY_OVERRIDE) | sed 's/\.d//')
  98. msg_ok "Customized Container"
  99. fi
  100. msg_info "Cleaning up"
  101. apt-get autoremove >/dev/null
  102. apt-get autoclean >/dev/null
  103. rm -rf /var/{cache,log}/* /var/lib/apt/lists/*
  104. msg_ok "Cleaned"