Redesign patcher (#43)

pull/144/head
AlexPresso 4 years ago committed by GitHub
parent 5b99a3639c
commit 6b6c5c797d

@ -5,14 +5,21 @@
############################### ###############################
dsm_version=$(cat /etc.defaults/VERSION | grep productversion | sed 's/productversion=//' | tr -d '"') dsm_version=$(cat /etc.defaults/VERSION | grep productversion | sed 's/productversion=//' | tr -d '"')
repo_base_url=https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher repo_base_url="https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher"
version="2.0"
action="patch" action="patch"
branch="main" branch="main"
dependencies=("ffmpeg") dependencies=("ffmpeg")
wrappers=("ffmpeg")
vs_path=/var/packages/VideoStation/target vs_path=/var/packages/VideoStation/target
libsynovte_path="$vs_path/lib/libsynovte.so" libsynovte_path="$vs_path/lib/libsynovte.so"
cp_bin_path=/var/packages/CodecPack/target/bin cp_bin_path=/var/packages/CodecPack/target/bin
cp_to_patch=("ffmpeg41" "ffmpeg27") cp_to_patch=(
"ffmpeg41:ffmpeg"
"ffmpeg27:ffmpeg"
"ffmpeg33:ffmpeg"
)
############################### ###############################
# UTILS # UTILS
@ -29,7 +36,7 @@ function error() {
} }
function welcome_motd() { function welcome_motd() {
info "ffmpeg-patcher v1.5" info "ffmpeg-patcher v$version"
motd=$(curl -s -L "$repo_base_url/blob/$branch/motd.txt?raw=true") motd=$(curl -s -L "$repo_base_url/blob/$branch/motd.txt?raw=true")
if [ "${#motd}" -ge 1 ]; then if [ "${#motd}" -ge 1 ]; then
@ -42,7 +49,7 @@ function welcome_motd() {
function restart_packages() { function restart_packages() {
if [[ -d $cp_bin_path ]]; then if [[ -d $cp_bin_path ]]; then
log "INFO" "Restarting CodecPack..." info "Restarting CodecPack..."
synopkg restart CodecPack synopkg restart CodecPack
fi fi
@ -51,9 +58,9 @@ function restart_packages() {
} }
function check_dependencies() { function check_dependencies() {
for dependecy in "${dependencies[@]}"; do for dependency in "${dependencies[@]}"; do
if [[ ! -d "/var/packages/$dependecy" ]]; then if [[ ! -d "/var/packages/$dependency" ]]; then
error "Missing $dependecy package, please install it and re-run the patcher." error "Missing $dependency package, please install it and re-run the patcher."
exit 1 exit 1
fi fi
done done
@ -66,22 +73,29 @@ function check_dependencies() {
function patch() { function patch() {
info "====== Patching procedure (branch: $branch) ======" info "====== Patching procedure (branch: $branch) ======"
info "Saving current ffmpeg as ffmpeg.orig" for filename in "${wrappers[@]}"; do
mv -n "$vs_path/bin/ffmpeg" "$vs_path/bin/ffmpeg.orig" if [[ -f "$vs_path/bin/$filename" ]]; then
info "Saving current $filename as $filename.orig"
mv -n "$vs_path/bin/$filename" "$vs_path/bin/$filename.orig"
info "Downloading ffmpeg's wrapper..." info "Downloading and installing $filename's wrapper..."
wget -q -O - "$repo_base_url/blob/$branch/ffmpeg-wrapper.sh?raw=true" > "$vs_path/bin/ffmpeg" wget -q -O - "$repo_base_url/blob/$branch/$filename-wrapper.sh?raw=true" > "$vs_path/bin/$filename"
chown root:VideoStation "$vs_path/bin/ffmpeg" chown root:VideoStation "$vs_path/bin/$filename"
chmod 750 "$vs_path/bin/ffmpeg" chmod 750 "$vs_path/bin/$filename"
chmod u+s "$vs_path/bin/ffmpeg" chmod u+s "$vs_path/bin/$filename"
fi
done
if [[ -d $cp_bin_path ]]; then if [[ -d $cp_bin_path ]]; then
for filename in "${cp_to_patch[@]}"; do for file in "${cp_to_patch[@]}"; do
filename="${file%%:*}"
target="${file##*:}"
if [[ -f "$cp_bin_path/$filename" ]]; then if [[ -f "$cp_bin_path/$filename" ]]; then
info "Patching CodecPack's $filename" info "Patching CodecPack's $filename"
mv -n "$cp_bin_path/$filename" "$cp_bin_path/$filename.orig" mv -n "$cp_bin_path/$filename" "$cp_bin_path/$filename.orig"
ln -s -f "$vs_path/bin/ffmpeg" "$cp_bin_path/$filename" ln -s -f "$vs_path/bin/$target" "$cp_bin_path/$filename"
fi fi
done done
fi fi
@ -103,13 +117,15 @@ function unpatch() {
info "====== Unpatch procedure ======" info "====== Unpatch procedure ======"
info "Restoring libsynovte.so" info "Restoring libsynovte.so"
mv -f "$libsynovte_path.orig" "$libsynovte_path" mv -T -f "$libsynovte_path.orig" "$libsynovte_path"
info "Restoring VideoStation's ffmpeg" find "$vs_path/bin" -type f -name "*.orig" | while read -r filename; do
mv -f "$vs_path/bin/ffmpeg.orig" "$vs_path/bin/ffmpeg" info "Restoring VideoStation's $filename"
mv -T -f "$filename" "${filename::-5}"
done
if [[ -d $cp_bin_path ]]; then if [[ -d $cp_bin_path ]]; then
find $cp_bin_path -type f -name "ffmpeg*.orig" | while read filename; do find $cp_bin_path -type f -name "*.orig" | while read -r filename; do
info "Restoring CodecPack's $filename" info "Restoring CodecPack's $filename"
mv -T -f "$filename" "${filename::-5}" mv -T -f "$filename" "${filename::-5}"
done done
@ -136,7 +152,7 @@ welcome_motd
check_dependencies check_dependencies
info "You're running DSM $dsm_version" info "You're running DSM $dsm_version"
if [[ $dsm_version > 7.0 ]]; then if [[ -d /var/packages/CodecPack/target/pack ]]; then
cp_bin_path=/var/packages/CodecPack/target/pack/bin cp_bin_path=/var/packages/CodecPack/target/pack/bin
info "Tuned script for DSM $dsm_version" info "Tuned script for DSM $dsm_version"
fi fi

Loading…
Cancel
Save