-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpatcher.sh
128 lines (101 loc) · 3.08 KB
/
patcher.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
###############################
# VARS
###############################
dsm_version=$(cat /etc.defaults/VERSION | grep productversion | sed 's/productversion=//' | tr -d '"')
repo_base_url="https://github.com/AlexPresso/mediaserver-ffmpeg-patcher"
version="1.0"
action="patch"
branch="main"
dependencies=("MediaServer" "ffmpeg")
wrappers=("ffmpeg")
ms_path=/var/packages/MediaServer/target
libsynovte_path="$ms_path/lib/libsynovte.so"
###############################
# UTILS
###############################
function log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2"
}
function info() {
log "INFO" "$1"
}
function error() {
log "ERROR" "$1"
}
function root_check() {
if [[ "$EUID" -ne 0 ]]; then
error "This tool needs root access (please run 'sudo -i' before proceeding)."
exit 1
fi
}
function restart_packages() {
info "Restarting MediaServer..."
synopkg restart MediaServer
}
function check_dependencies() {
missingDeps=false
for dependency in "${dependencies[@]}"; do
if [[ ! -d "/var/packages/$dependency" ]]; then
error "Missing $dependency package, please install it and re-run the patcher."
missingDeps=true
fi
done
if [[ $missingDeps -eq 1 ]]; then
exit 1
fi
}
################################
# PATCH PROCEDURES
################################
function patch() {
info "====== Patching procedure (branch: $branch) ======"
for filename in "${wrappers[@]}"; do
if [[ -f "$ms_path/bin/$filename" ]]; then
info "Saving current $filename as $filename.orig"
mv -n "$ms_path/bin/$filename" "$ms_path/bin/$filename.orig"
info "Downloading and installing $filename's wrapper..."
wget -q -O - "$repo_base_url/blob/$branch/$filename-wrapper.sh?raw=true" > "$ms_path/bin/$filename"
chown root:MediaServer "$ms_path/bin/$filename"
chmod 750 "$ms_path/bin/$filename"
chmod u+s "$ms_path/bin/$filename"
fi
done
info "Saving current libsynovte.so as libsynovte.so.orig"
cp -n "$libsynovte_path" "$libsynovte_path.orig"
chown MediaServer:MediaServer "$libsynovte_path.orig"
info "Enabling eac3, dts and truehd"
sed -i -e 's/eac3/3cae/' -e 's/dts/std/' -e 's/truehd/dheurt/' "$libsynovte_path"
restart_packages
echo ""
info "Done patching, you can now enjoy your movies ;) (please add a star to the repo if it worked for you)"
}
function unpatch() {
info "====== Unpatch procedure ======"
info "Restoring libsynovte.so"
mv -T -f "$libsynovte_path.orig" "$libsynovte_path"
find "$ms_path/bin" -type f -name "*.orig" | while read -r filename; do
info "Restoring MediaServer $filename"
mv -T -f "$filename" "${filename::-5}"
done
restart_packages
echo ""
info "unpatch complete"
}
################################
# ENTRYPOINT
################################
root_check
check_dependencies
while getopts a:b: flag; do
case "${flag}" in
a) action=${OPTARG};;
b) branch=${OPTARG};;
*) echo "usage: $0 [-a patch|unpatch] [-b branch]" >&2; exit 1;;
esac
done
info "You're running DSM $dsm_version"
case "$action" in
unpatch) unpatch;;
patch) patch;;
esac