0
0
mirror of https://github.com/cucumber-sp/yandex-music-linux.git synced 2024-12-23 22:22:59 +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,21 +1,27 @@
#!/bin/bash
mkdir -p ./tmp
set -e
clear() {
rm -rf "$TEMPDIR"
}
TEMPDIR="$(mktemp -d)"
trap clear EXIT
# loading json from file https://music-desktop-application.s3.yandex.net/stable/download.json
curl -s https://music-desktop-application.s3.yandex.net/stable/download.json > ./tmp/download.json
curl -s https://music-desktop-application.s3.yandex.net/stable/download.json > "$TEMPDIR"/download.json
exe_link=$(jq -r '.windows' ./tmp/download.json)
version=$(echo $exe_link | grep -oP '(?<=x64_).*(?=.exe)')
exe_name=$(basename $exe_link)
exe_link=$(jq -r '.windows' "$TEMPDIR"/download.json)
version="$(echo "$exe_link" | grep -oP '(?<=x64_).*(?=.exe)')"
exe_name="$(basename "$exe_link")"
echo "Windows url: $exe_link"
echo "Version: $version"
echo "Exe name: $exe_name"
curl $exe_link > ./tmp/$exe_name
curl "$exe_link" > "$TEMPDIR/$exe_name"
exe_sha256=$(sha256sum ./tmp/$exe_name | awk '{print $1}')
exe_sha256="$(sha256sum "$TEMPDIR/$exe_name" | awk '{print $1}')"
echo "Exe sha256: $exe_sha256"
@ -36,5 +42,3 @@ sed -i "s#%release%#1#g" ./PKGBUILD
sed -i "s#%exe_name%#$exe_name#g" ./PKGBUILD
sed -i "s#%exe_link%#$exe_link#g" ./PKGBUILD
sed -i "s#%exe_sha256%#$exe_sha256#g" ./PKGBUILD
rm -rf ./tmp

View File

@ -18,8 +18,7 @@ let
repack = ./../repack.sh;
src = ymExe;
} ''
bash "$repack" -x "$src"
mv ./app "$out"
bash "$repack" -x -o "$out" "$src"
'';
launcher = writeShellApplication {
name = "yandex-music";

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"
rm -rf ./app
cd "$curdir"
asar pack "$TEMPDIR/app" "$dst/yandexmusic.asar"
echo "Done"