0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2025-09-28 01:29:03 +03:00

Add some style fixes for shell scripts

* use `mktemp -d` for temporary files
* use trap to remove temporary files
* fix some shellcheck warnings

Change-Id: Ib73f5a52d7bcd21232e7ef31a815c28a06dcd857
This commit is contained in:
Yury Shvedov
2024-01-30 20:59:19 +03:00
parent 6c24593616
commit 46e9a0e494
3 changed files with 46 additions and 51 deletions

View File

@@ -1,38 +1,22 @@
#!/bin/bash
set -e
prompt_yes_no() {
local question="$1"
local response
while true; do
read -rp "$question (y/n): " response
case $response in
[Yy]*)
return 0 # Returning success status code
;;
[Nn]*)
return 1 # Returning failure status code
;;
*)
echo "Please enter 'y' (yes) or 'n' (no)."
;;
esac
done
}
usage() {
echo "Usage: $(basename "$0") [-xh] YANDEX_MUSIC_EXE"
echo "Usage: $(basename "$0") [-xh] [ -o DIR] YANDEX_MUSIC_EXE"
echo
echo " Options:"
echo " -x Extract and fix only to ./app folder"
echo " -o DIR Path to destination folder"
echo " -x Extract and fix only to destination folder"
echo " -h Show this help and exit"
}
extract_only=
exe_location=
while getopts :xh name; do
dst="$PWD/app"
while getopts :xo:h name; do
case $name in
x) extract_only=1 ;;
o) dst="$OPTARG" ;;
h)
usage
exit 0
@@ -56,18 +40,27 @@ if [ -z "$exe_location" ]; then
exit 1
fi
# unpacking
7z x "$exe_location" -oExtracted
cp "./Extracted/\$PLUGINSDIR/app-64.7z" "./app-64.7z"
rm -rf ./Extracted
7z x "./app-64.7z" -oExtracted
cp "./Extracted/resources/app.asar" "./app.asar"
rm -rf ./Extracted
rm ./app-64.7z
asar extract "./app.asar" "./app"
rm "./app.asar"
clear() {
rm -rf "$TEMPDIR"
}
TEMPDIR="$(mktemp -d)"
trap clear EXIT
cd ./app
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"
# fixing secretKey issue
echo "Fixing SecretKey"
@@ -97,22 +90,21 @@ fi
jq --arg license "UNLICENSED" '. + {license: $license}' package.json > tmp_package.json
mv tmp_package.json package.json
echo "Updated license field in package.json"
version=$(jq -r .version package.json)
jq '. + {icon: {"48x48": "build/next-desktop/favicon.png", "scalable": "build/next-desktop/favicon.svg"}}' package.json > tmp_package.json
mv tmp_package.json package.json
echo "Updated icon field in package.json"
if [ -n "$extract_only" ]; then
mkdir -p "$(dirname "$dst")"
mv "$TEMPDIR/app" "$dst"
exit 0
fi
cd ../
mkdir -p out
mkdir -p "$dst"
echo "Packing"
asar pack "./app" "./out/yandexmusic.asar"
cd "$curdir"
asar pack "$TEMPDIR/app" "$dst/yandexmusic.asar"
rm -rf ./app
echo "Done"
echo "Done"