forked from bakerboy448/StarrScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmm-update.sh
52 lines (47 loc) · 1.84 KB
/
pmm-update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
force=${1:false}
# Get Current User
uid=$(id -u)
# Set Variables
pmmPath="/opt/Plex-Meta-Manager"
pmmVenvName="pmm-venv"
pmmServiceName="pmm"
pmmUpstreamGitRemote="origin"
# Create Paths
pmmVersionFile="$pmmPath/VERSION"
pmmRequirementsFile="$pmmPath/requirements.txt"
pmmVenvPath="$pmmPath"/"$pmmVenvName"
currentVersion=$(cat "$pmmVersionFile")
currentRequirements=$(sha1sum "$pmmRequirementsFile" | awk '{print $1}')
# Check if PMM is installed & Get Repo Owner
# Check if user executing script owns PMM Repo
if [ -d "$pmmPath" ]; then
pmmRepoOwner=$(stat -c '%u' "$pmmPath")
if [ "$pmmRepoOwner" != "$uid" ]; then
echo "Plex Meta Manager folder does exist but you [$uid] do not own the repo. Please run this script as the user that owns the repo [$pmmRepoOwner]"
exit 1
fi
else
echo "Plex Meta Manager folder does not exist. Please install Plex Meta Manager before running this script."
exit 1
fi
# Get current Branch
branch=$(git -C "$pmmPath" rev-parse --abbrev-ref HEAD)
echo "Current Branch: $branch. Checking for updates..."
git -C "$pmmPath" fetch
echo "force update is:$force"
if [ "$(git -C "$pmmPath" rev-parse HEAD)" = "$(git -C "$pmmPath" rev-parse @'{u}')" ] && [ "$force" != true ]; then
echo "=== Already up to date $currentVersion on $branch ==="
exit 0
fi
git -C "$pmmPath" reset --hard "$pmmUpstreamGitRemote"/"$branch"
newVersion=$(cat "$pmmVersionFile")
newRequirements=$(sha1sum "$pmmRequirementsFile" | awk '{print $1}')
if [ "$currentRequirements" != "$newRequirements" ] || [ "$force" = true ]; then
echo "=== Requirements changed, updating venv ==="
"$pmmVenvPath"/bin/python3 "$pmmVenvPath"/bin/pip install -r "$pmmRequirementsFile"
fi
echo "=== Restarting PMM Service ==="
sudo systemctl restart "$pmmServiceName"
echo "=== Updated from $currentVersion to $newVersion on $branch"
exit 0