install_chromium_widevine.sh 4.42 KB
Newer Older
1
2
#!/bin/sh

3
4
5
6
7
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

8
DEBIAN_VER=buster
9
10
11
12
CONTAINER_DIR=/var/lib/machines/
CONTAINER_ID=chromium_widevine
TEMP_DIR="$(mktemp -p /var/cache/ -td ChromeOS-IMG.XXXXXX)"

13
14
15
# check online connectivity
wget -q --spider https://google.com
CONNECTION_STATUS=$?
16
if [[ $CONNECTION_STATUS -ne 0 ]]; then
17
18
  echo "You have to establish an online connection first!" 1>&2
  exit 1
19
20
fi

21
22
set -e # error if a command as non 0 exit
set -u # error if undefined variable
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# message functions
msg() {
  ALL_OFF="\e[1;0m"
  BOLD="\e[1;1m"
  GREEN="${BOLD}\e[1;32m"
  local mesg=$1; shift
  printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

info() {
  ALL_OFF="\e[1;0m"
  BOLD="\e[1;1m"
  BLUE="${BOLD}\e[1;34m"
  local mesg=$1; shift
  printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

41
42
43
44
45
46
# check for command availability
available () {
  command -v "$1" >/dev/null 2>&1
}

if ! available debootstrap; then
47
  pacman -S --noconfirm debian-archive-keyring debootstrap
48
49
50
fi

if ! available xhost; then
51
  pacman -S --noconfirm xorg-xhost
52
53
54
fi

if ! available curl; then
55
  pacman -S --noconfirm curl
56
57
58
fi

if ! available git; then
59
  pacman -S --noconfirm git
60
61
fi

62
if [[ ! -d $CONTAINER_DIR ]]; then
63
  info "Creating base directory for systemd containers $CONTAINER_DIR..."
64
65
66
  mkdir -p $CONTAINER_DIR
fi

67
if [[ ! -d $CONTAINER_DIR/$CONTAINER_ID ]]; then
68
  info "Bootstrap new Debian 10 Buster armhf container $CONTAINER_ID..."
69
  cd $CONTAINER_DIR
70
  debootstrap --include=systemd-container,debconf --components=main,universe --arch=armhf $DEBIAN_VER $CONTAINER_ID
71
72
fi

73
info "Cloning docker-chromium-armhf from Git repo..."
74
git clone --progress --depth=1 https://github.com/appelgriebsch/docker-chromium-armhf/ $TEMP_DIR
75

76
info "Downloading ChromeOS image..."
77
78
79
80
81
CHROMEOS_URL="$(curl -s https://dl.google.com/dl/edgedl/chromeos/recovery/recovery.conf | grep -A11 CB5-312T | sed -n 's/^url=//p')"
CHROMEOS_IMG="$(basename "$CHROMEOS_URL" .zip)"
curl -L "$CHROMEOS_URL" | zcat > "$TEMP_DIR/$CHROMEOS_IMG"

# Note the next free loop device in a variable
82
info "Mounting local ChromeOS image..."
83
84
85
86
87
LOOPD="$(losetup -f)"
mkdir -p $TEMP_DIR/img
losetup -Pf "$TEMP_DIR/$CHROMEOS_IMG"
mount -o ro "${LOOPD}p3" "$TEMP_DIR/img"

88
info "Setting up environment in systemd container $CONTAINER_ID..."
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
systemd-nspawn --directory="$CONTAINER_DIR/$CONTAINER_ID" --bind-ro=$TEMP_DIR:/tmp/chromium --pipe /bin/bash <<'EOF'
apt install --yes --no-install-recommends \
  fontconfig fontconfig-config fonts-dejavu-core gconf-service gconf2-common \
  libasn1-8-heimdal libasound2 libasound2-data libatk1.0-0 libatk1.0-data libavahi-client3 libavahi-common-data \
  libavahi-common3 libcairo2 libcups2 libdatrie1 libdbus-1-3 libdbus-glib-1-2 libexpat1 libfontconfig1 \
  libfreetype6 libgconf-2-4 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libgmp10 \
  libgnutls30 libgraphite2-3 libgssapi-krb5-2 libgssapi3-heimdal libgtk2.0-0 \
  libgtk2.0-common libharfbuzz0b libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhogweed4 \
  libhx509-5-heimdal libjbig0 libk5crypto3 libkeyutils1 \
  libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libnettle6 libnspr4 libnss3 \
  libp11-kit0 libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 libpixman-1-0 libpng16-16 libroken18-heimdal \
  libsasl2-2 libsasl2-modules-db libsqlite3-0 libtasn1-6 libthai-data libthai0 libtiff5 libwind0-heimdal libx11-6 \
  libx11-data libxau6 libxcb-render0 libxcb-shm0 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 \
  libxext6 libxfixes3 libxi6 libxinerama1 libxml2 libxrandr2 libxrender1 libxss1 libxtst6 shared-mime-info ucf \
  x11-common xdg-utils libpulse0 pulseaudio-utils wget libatk-bridge2.0-0 libatspi2.0-0 libgtk-3-0 \
104
105
  mesa-va-drivers mesa-vdpau-drivers mesa-utils libosmesa6 libegl1-mesa libwayland-egl1-mesa libgl1-mesa-dri \
  libgles2-mesa libegl1 libgles2
106
107
108
109
110
111

apt install /tmp/chromium/dependencies/chromium*.deb

cp -R /tmp/chromium/img/opt/google/chrome/libwidevinecdm.so /usr/lib/chromium-browser
cp -R /tmp/chromium/img/opt/google/chrome/pepper /usr/lib/chromium-browser
cp -R /tmp/chromium/widevine/netflix-1080p-1.20.1 /usr/lib/chromium-browser/netflix-1080p
112
cp -R /tmp/chromium/chromium-settings /etc/chromium-browser/default
113
114
115
116
117

useradd -m -s /bin/bash chromium
gpasswd -a chromium audio
EOF

118
info "Cleaning up..."
119
120
umount "$TEMP_DIR/img"
losetup -d "$LOOPD"
121
rm -rf "$TEMP_DIR"
122
msg "All done! You can use the launcher to start the Chromium Widevine application"