1
1
#!/usr/bin/with-contenv bash
2
+ # shellcheck shell=bash
2
3
3
4
# If docker manages versioning exit
4
- if [ "${VERSION}" ] && [ "${VERSION}" == ' docker' ]; then
5
+ if [[ -n "${VERSION}" ]] && [[ "${VERSION}" == " docker" ] ]; then
5
6
echo "Docker is used for versioning skip update check"
6
7
exit 0
7
8
fi
@@ -12,30 +13,32 @@ if (dpkg --get-selections plexmediaserver | grep -wq "install"); then
12
13
else
13
14
echo "for some reason plex doesn't appear to be installed, pulling a new copy and exiting out of update script"
14
15
curl -o /tmp/plexmediaserver.deb -L \
15
- "${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb" && \
16
+ "${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
16
17
dpkg -i --force-confold /tmp/plexmediaserver.deb
17
18
rm -f /tmp/plexmediaserver.deb
18
19
exit 0
19
20
fi
20
21
21
22
# set no update message
22
- [[ -e /tmp/no-version.nfo ]] && \
23
+ if [[ -e /tmp/no-version.nfo ]]; then
23
24
rm /tmp/no-version.nfo
25
+ fi
24
26
NOVERSION_SET='/tmp/no-version.nfo'
25
- cat > "${NOVERSION_SET}" <<-EOFVERSION
27
+ cat >"${NOVERSION_SET}" <<-EOFVERSION
26
28
#######################################################
27
- # Update routine will not run because you havent set #
29
+ # Update routine will not run because you haven't set #
28
30
# the VERSION variable or you opted out of updates. #
29
31
# For more information checkout :- #
30
32
# https://github.com/linuxserver/docker-plex #
31
33
#######################################################
32
34
EOFVERSION
33
35
34
36
# set update failed message
35
- [[ -e /tmp/update_fail.nfo ]] && \
37
+ if [[ -e /tmp/update_fail.nfo ]]; then
36
38
rm /tmp/update_fail.nfo
39
+ fi
37
40
UPGRADE_FAIL='/tmp/update_fail.nfo'
38
- cat > "${UPGRADE_FAIL}" <<-EOFFAIL
41
+ cat >"${UPGRADE_FAIL}" <<-EOFFAIL
39
42
########################################################
40
43
# Upgrade attempt failed, this could be because either #
41
44
# plex update site is down, local network issues, or #
@@ -45,25 +48,27 @@ cat > "${UPGRADE_FAIL}" <<-EOFFAIL
45
48
########################################################
46
49
EOFFAIL
47
50
48
- # test for no version set or opt out for autoupdates
49
- if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ -n "$ADVANCED_DISABLEUPDATES" ]]; then
51
+ # test for no version set or opt out for auto updates
52
+ if [[ -z "${ VERSION} " ]] || [[ "${ VERSION} " == "0" ]] || [[ -n "${ ADVANCED_DISABLEUPDATES} " ]]; then
50
53
printf '\n\n\n%s\n\n\n' "$(</tmp/no-version.nfo)"
51
54
exit 0
52
55
fi
53
56
54
57
# set header for no preferences/token message
55
- [[ -e /tmp/no-token.nfo ]] && \
58
+ if [[ -e /tmp/no-token.nfo ]]; then
56
59
rm /tmp/no-token.nfo
60
+ fi
57
61
NOTOKEN_SET='/tmp/no-token.nfo'
58
- cat > "${NOTOKEN_SET}" <<-EOFTOKEN
62
+ cat >"${NOTOKEN_SET}" <<-EOFTOKEN
59
63
#####################################################
60
64
# Login via the webui at http://<ip>:32400/web #
61
65
# and restart the container, because there was no #
62
66
EOFTOKEN
63
67
64
68
# if preferences files doesn't exist, exit out
65
- if [ ! -e "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then
66
- cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
69
+ PLEX_MEDIA_SERVER_PREFERENCES="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Preferences.xml"
70
+ if [[ ! -e "${PLEX_MEDIA_SERVER_PREFERENCES}" ]]; then
71
+ cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
67
72
# preference file found, possibly first startup. #
68
73
#####################################################
69
74
EOFTOKEN
@@ -72,13 +77,13 @@ EOFTOKEN
72
77
fi
73
78
74
79
# attempt to read plex token
75
- PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
76
- "/config/Library/Application Support/Plex Media Server/Preferences.xml" \
77
- | sed "s/\".*//")
80
+ PLEX_TOKEN=$(sed -n 's/.*PlexOnlineToken="//p' \
81
+ "${PLEX_MEDIA_SERVER_PREFERENCES}" |
82
+ sed "s/\".*//")
78
83
79
84
# if plex token isn't found, exit out
80
- if [ -z "$PLEX_TOKEN" ]; then
81
- cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
85
+ if [[ -z "${ PLEX_TOKEN}" ] ]; then
86
+ cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
82
87
# plex token found in the preference file #
83
88
#####################################################
84
89
EOFTOKEN
90
95
INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' plexmediaserver)
91
96
92
97
# start update routine
93
- if [[ "${VERSION,,}" = latest ]] || [[ "${VERSION,,}" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
94
- if [[ "${PLEX_ARCH}" = amd64 ]]; then
98
+ if [[ "${VERSION,,}" == " latest" ]] || [[ "${VERSION,,}" == " plexpass" ]] || [[ "${ PLEXPASS} " == "1" ]]; then
99
+ if [[ "${PLEX_ARCH}" == " amd64" ]]; then
95
100
PLEX_URL_ARCH="x86_64"
96
- elif [[ "${PLEX_ARCH}" = armhf ]]; then
101
+ elif [[ "${PLEX_ARCH}" == " armhf" ]]; then
97
102
PLEX_URL_ARCH="armv7hf_neon"
98
- elif [[ "${PLEX_ARCH}" = arm64 ]]; then
103
+ elif [[ "${PLEX_ARCH}" == " arm64" ]]; then
99
104
PLEX_URL_ARCH="aarch64"
100
105
fi
101
- REMOTE_VERSION=$(curl -s "https://plex.tv/downloads/details/5?distro=debian&build=linux-${PLEX_URL_ARCH}&channel=8&X-Plex-Token=$PLEX_TOKEN" | grep -oP 'version="\K[^"]+' | tail -n 1 )
102
- elif [[ "${VERSION,,}" = public ]]; then
106
+ REMOTE_VERSION=$(curl -s "https://plex.tv/downloads/details/5?distro=debian&build=linux-${PLEX_URL_ARCH}&channel=8&X-Plex-Token=${ PLEX_TOKEN}" | grep -oP 'version="\K[^"]+' | tail -n 1)
107
+ elif [[ "${VERSION,,}" == " public" ]]; then
103
108
REMOTE_VERSION=$(curl -s 'https://plex.tv/api/downloads/5.json' | jq -r '.computer.Linux.version')
104
109
else
105
110
REMOTE_VERSION="${VERSION}"
106
111
fi
107
112
108
- if [[ "$REMOTE_VERSION" == "$INSTALLED_VERSION" ]]; then
113
+ if [[ "${ REMOTE_VERSION} " == "${ INSTALLED_VERSION} " ]]; then
109
114
echo "No update required"
110
115
exit 0
111
116
fi
@@ -115,18 +120,18 @@ if [[ -z "${REMOTE_VERSION}" ]]; then
115
120
exit 0
116
121
fi
117
122
118
- echo "Atempting to upgrade to: $REMOTE_VERSION"
123
+ echo "Attempting to upgrade to: ${ REMOTE_VERSION} "
119
124
rm -f /tmp/plexmediaserver_*.deb
120
125
wget -nv -P /tmp \
121
126
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
122
127
last=$?
123
128
124
129
# test if deb file size is ok, or if download failed
125
- if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver_" ${REMOTE_VERSION}" _${PLEX_ARCH}.deb) -lt 10000 ]]; then
130
+ if [[ "${ last} " -gt "0" ]] || [[ $(stat -c %s " /tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb" ) -lt 10000 ]]; then
126
131
printf '\n\n\n%s\n\n\n' "$(</tmp/update_fail.nfo)"
127
132
exit 0
128
133
# if ok, try to install it.
129
134
else
130
- dpkg -i --force-confold /tmp/plexmediaserver_" ${REMOTE_VERSION}" _${PLEX_ARCH}.deb
135
+ dpkg -i --force-confold " /tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
131
136
rm -f /tmp/plexmediaserver_*.deb
132
137
fi
0 commit comments