2023-12-04 16:02:20 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-14 15:35:58 +03:00
|
|
|
set -e
|
2023-12-04 16:02:20 +03:00
|
|
|
|
2024-01-14 15:35:58 +03:00
|
|
|
usage() {
|
2024-01-30 21:32:35 +03:00
|
|
|
echo "Usage: $(basename "$0") [-xqh] [ -o DIR] YANDEX_MUSIC_EXE"
|
2024-01-14 15:35:58 +03:00
|
|
|
echo
|
|
|
|
echo " Options:"
|
2024-01-30 20:59:19 +03:00
|
|
|
echo " -o DIR Path to destination folder"
|
|
|
|
echo " -x Extract and fix only to destination folder"
|
2024-02-11 15:11:59 +03:00
|
|
|
echo " -p Do not apply patches"
|
2024-01-14 15:35:58 +03:00
|
|
|
echo " -h Show this help and exit"
|
|
|
|
}
|
|
|
|
|
|
|
|
exe_location=
|
2024-01-30 20:59:19 +03:00
|
|
|
dst="$PWD/app"
|
2024-02-09 17:35:17 +03:00
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
2024-02-11 15:11:59 +03:00
|
|
|
nopatch=0
|
|
|
|
while getopts :xo:ph name; do
|
2024-01-14 15:35:58 +03:00
|
|
|
case $name in
|
|
|
|
x) extract_only=1 ;;
|
2024-03-10 10:05:11 +03:00
|
|
|
o) dst="$(realpath "$OPTARG")" ;;
|
2024-02-11 15:11:59 +03:00
|
|
|
p) nopatch=1 ;;
|
2024-01-14 15:35:58 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
2024-01-14 15:35:58 +03:00
|
|
|
if [ -z "$exe_location" ]; then
|
|
|
|
echo "No exe file specified"
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-01-30 20:59:19 +03:00
|
|
|
clear() {
|
|
|
|
rm -rf "$TEMPDIR"
|
|
|
|
}
|
|
|
|
TEMPDIR="$(mktemp -d)"
|
|
|
|
trap clear EXIT
|
|
|
|
|
|
|
|
|
|
|
|
EXTRACTED="$TEMPDIR/Extracted"
|
2024-01-14 15:35:58 +03:00
|
|
|
# unpacking
|
2024-01-30 20:59:19 +03:00
|
|
|
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"
|
2024-02-08 15:02:02 +03:00
|
|
|
asar extract "$TEMPDIR/app.asar" "$TEMPDIR/app"
|
2024-01-30 20:59:19 +03:00
|
|
|
rm "$TEMPDIR/app.asar"
|
|
|
|
|
|
|
|
curdir="$PWD"
|
|
|
|
cd "$TEMPDIR/app"
|
2024-01-14 15:35:58 +03:00
|
|
|
|
2024-02-09 17:25:54 +03:00
|
|
|
|
2023-12-04 16:02:20 +03:00
|
|
|
# fixing secretKey issue
|
|
|
|
echo "Fixing SecretKey"
|
|
|
|
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
|
|
|
|
sed -i "s/secretKey:this.secretKey/secretKey:'superSecretKey'/g" "$file"
|
|
|
|
done
|
|
|
|
echo "SecretKey replaced"
|
|
|
|
|
2024-02-09 17:25:54 +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-03-10 10:05:11 +03:00
|
|
|
cp -drf "$SCRIPT_DIR/icons/." "./build/next-desktop/"
|
2024-03-07 22:16:21 +03:00
|
|
|
echo "Replaced Icons"
|
|
|
|
|
2024-02-09 17:25:54 +03:00
|
|
|
# applying patches
|
2024-02-11 15:11:59 +03:00
|
|
|
|
|
|
|
# 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`.
|
2024-02-09 17:25:54 +03:00
|
|
|
apply_patch()
|
|
|
|
{
|
2024-02-11 15:11:59 +03:00
|
|
|
local patchfile patchname re
|
2024-02-09 17:25:54 +03:00
|
|
|
|
|
|
|
patchfile="$(realpath "$1")"
|
|
|
|
patchname="$(basename "$patchfile")"
|
|
|
|
patchname="${patchname,,}"
|
2024-02-11 15:11:59 +03:00
|
|
|
re='[[:digit:]]+\-optional\-(.+).patch ]]'
|
|
|
|
if [[ $patchname =~ $re ]]; then
|
2024-02-09 17:25:54 +03:00
|
|
|
patchname="${BASH_REMATCH[1]}"
|
|
|
|
patchname="${patchname//[- ]/_}"
|
|
|
|
if eval [ \"\$"patch_$patchname"\" != 1 ]; then
|
2024-02-11 15:11:59 +03:00
|
|
|
echo "Skipping patch '$patchfile'"
|
2024-02-09 17:25:54 +03:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo "Applying patch '$patchfile'"
|
|
|
|
(cd "$TEMPDIR/app" && patch -p1 < "$patchfile")
|
|
|
|
}
|
2024-01-20 19:42:39 +03:00
|
|
|
|
2024-02-11 15:11:59 +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
|
|
|
|
2024-01-29 21:41:52 +03:00
|
|
|
if [ -n "$extract_only" ]; then
|
2024-02-09 17:25:54 +03:00
|
|
|
eval cp -r "$TEMPDIR/app/*" "$dst"
|
2024-01-29 21:41:52 +03:00
|
|
|
exit 0
|
2023-12-04 16:02:20 +03:00
|
|
|
fi
|
|
|
|
|
2024-01-29 21:41:52 +03:00
|
|
|
echo "Packing"
|
2024-01-30 20:59:19 +03:00
|
|
|
cd "$curdir"
|
2024-02-14 14:07:10 +03:00
|
|
|
asar pack "$TEMPDIR/app" "$dst/yandex-music.asar"
|
2024-01-30 21:21:59 +03:00
|
|
|
for ext in png svg; do
|
|
|
|
mv "$TEMPDIR/app/build/next-desktop/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"
|
2024-01-29 21:41:52 +03:00
|
|
|
|
2024-01-30 20:59:19 +03:00
|
|
|
echo "Done"
|