0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2024-12-24 14:34:39 +03:00
yandex-music-linux/repack.sh

140 lines
3.5 KiB
Bash
Raw Normal View History

2023-12-04 16:02:20 +03:00
#!/bin/bash
set -e
2023-12-04 16:02:20 +03:00
usage() {
echo "Usage: $(basename "$0") [-xqh] [ -o DIR] YANDEX_MUSIC_EXE"
echo
echo " Options:"
echo " -o DIR Path to destination folder"
echo " -x Extract and fix only to destination folder"
echo " -p Do not apply patches"
echo " -h Show this help and exit"
}
exe_location=
dst="$PWD/app"
2024-02-09 17:35:17 +03:00
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
nopatch=0
while getopts :xo:ph name; do
case $name in
x) extract_only=1 ;;
o) dst="$(realpath "$OPTARG")" ;;
p) nopatch=1 ;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if [ "$OPTIND" -le "$#" ]; then
shift "$(( OPTIND - 1))"
exe_location="$1"
fi
2023-12-04 16:02:20 +03:00
if [ -z "$exe_location" ]; then
echo "No exe file specified"
usage
exit 1
fi
clear() {
rm -rf "$TEMPDIR"
}
TEMPDIR="$(mktemp -d)"
trap clear EXIT
EXTRACTED="$TEMPDIR/Extracted"
# unpacking
7z x "$exe_location" -o"$EXTRACTED"
mv "$EXTRACTED/\$PLUGINSDIR/app-64.7z" "$TEMPDIR/app-64.7z"
rm -rf "$EXTRACTED"
7z x "$TEMPDIR/app-64.7z" -o"$EXTRACTED"
mv "$EXTRACTED/resources/app.asar" "$TEMPDIR/app.asar"
rm -rf "$EXTRACTED"
rm "$TEMPDIR/app-64.7z"
asar extract "$TEMPDIR/app.asar" "$TEMPDIR/app"
rm "$TEMPDIR/app.asar"
curdir="$PWD"
cd "$TEMPDIR/app"
2023-12-04 16:02:20 +03:00
echo "Fixing SecretKey"
2024-07-05 22:25:42 +03:00
echo "Spoofing OS"
2023-12-04 16:02:20 +03:00
find "./" -type f \( -name "*.js" -o -name "*.js.map" \) -print0 | while IFS= read -r -d $'\0' file; do
# Use 'sed' to perform the replacement in-place
2024-08-17 00:24:23 +03:00
sed -i "s/a.t.WINDOWS/a.t.LINUX/g" "$file"
2024-07-05 22:25:42 +03:00
sed -i "s/B.LINUX/B.WINDOWS/g" "$file"
2023-12-04 16:02:20 +03:00
done
echo "OS spoofed"
2023-12-04 16:02:20 +03:00
# fixing titile
2023-12-04 16:02:20 +03:00
echo "Fixing Title"
find "./" -type f -name "*.html" -print0 | while IFS= read -r -d $'\0' file; do
# Use 'sed' to perform the replacement in-place
sed -i "s/Яндекс Музыка — собираем музыку для вас/Яндекс Музыка/g" "$file"
done
echo "Title Fixed"
2024-03-07 22:16:21 +03:00
echo "Replacing Icons"
2024-07-04 08:23:31 +03:00
cp -drf "$SCRIPT_DIR/icons/." "./app/"
2024-03-07 22:16:21 +03:00
echo "Replaced Icons"
# applying patches
# This function accepts patch file. If it names starts with `XXXX-optional`,
# then this function check is there the variable with tail name of patch and
# prefix patch_ defined to 1 and apply conditionally the patch. So, if the passed
# file has name `0003-optional-some-magic-feature.patch` the function will apply
# it only when the variable `patch_some_magic_feature` defined to `1`.
apply_patch()
{
local patchfile patchname re
patchfile="$(realpath "$1")"
patchname="$(basename "$patchfile")"
patchname="${patchname,,}"
re='[[:digit:]]+\-optional\-(.+).patch ]]'
if [[ $patchname =~ $re ]]; then
patchname="${BASH_REMATCH[1]}"
patchname="${patchname//[- ]/_}"
if eval [ \"\$"patch_$patchname"\" != 1 ]; then
echo "Skipping patch '$patchfile'"
return 0
fi
fi
echo "Applying patch '$patchfile'"
(cd "$TEMPDIR/app" && patch -p1 < "$patchfile")
}
2024-01-20 19:42:39 +03:00
if [ "$nopatch" != "1" ]; then
for f in $(eval echo "$SCRIPT_DIR"/patches/*.patch); do
apply_patch "$f"
done
fi
mkdir -p "$dst"
2023-12-04 16:02:20 +03:00
if [ -n "$extract_only" ]; then
eval cp -r "$TEMPDIR/app/*" "$dst"
exit 0
2023-12-04 16:02:20 +03:00
fi
echo "Packing"
cd "$curdir"
2024-02-14 14:07:10 +03:00
asar pack "$TEMPDIR/app" "$dst/yandex-music.asar"
for ext in png svg; do
2024-07-04 08:23:31 +03:00
mv "$TEMPDIR/app/app/favicon.$ext" "$dst"
done
2024-04-20 14:04:50 +03:00
python "$SCRIPT_DIR/utility/extract_release_notes.py" "$TEMPDIR/app/main/translations/compiled/ru.json" "$dst/release_notes.json"
echo "Done"