2024-01-30 16:19:10 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-01-30 20:59:19 +03:00
|
|
|
set -e
|
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
TEMPDIR=
|
|
|
|
exe_link=
|
|
|
|
version=
|
|
|
|
exe_name=
|
|
|
|
exe_sha256=
|
|
|
|
|
2024-01-30 20:59:19 +03:00
|
|
|
clear() {
|
|
|
|
rm -rf "$TEMPDIR"
|
|
|
|
}
|
|
|
|
TEMPDIR="$(mktemp -d)"
|
|
|
|
trap clear EXIT
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
check_dep() {
|
|
|
|
if ! command -v "$@" &>/dev/null; then
|
|
|
|
echo "$@" not installed. >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
check_deps() {
|
|
|
|
check_dep sed
|
|
|
|
check_dep curl
|
|
|
|
check_dep jq
|
|
|
|
}
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
load_current_version() {
|
|
|
|
# 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 > "$TEMPDIR"/download.json
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
exe_link=$(jq -r '.windows' "$TEMPDIR"/download.json)
|
|
|
|
version="$(echo "$exe_link" | grep -oP '(?<=x64_).*(?=.exe)')"
|
|
|
|
exe_name="$(basename "$exe_link")"
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
echo "Windows url: $exe_link"
|
|
|
|
echo "Version: $version"
|
|
|
|
echo "Exe name: $exe_name"
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
curl "$exe_link" > "$TEMPDIR/$exe_name"
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
exe_sha256="$(sha256sum "$TEMPDIR/$exe_name" | awk '{print $1}')"
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
echo "Exe sha256: $exe_sha256"
|
|
|
|
}
|
|
|
|
|
|
|
|
update_version() {
|
2024-02-09 15:07:50 +03:00
|
|
|
rm -rf ./utility/version_info.json
|
2024-01-31 21:56:40 +03:00
|
|
|
|
2024-02-09 15:07:50 +03:00
|
|
|
cat > ./utility/version_info.json <<EOF
|
2024-01-31 21:56:40 +03:00
|
|
|
{
|
2024-02-18 21:00:32 +03:00
|
|
|
"ym": {
|
|
|
|
"version": "$version",
|
|
|
|
"exe_name": "$exe_name",
|
|
|
|
"exe_link": "$exe_link",
|
|
|
|
"exe_sha256": "$exe_sha256"
|
|
|
|
}
|
2024-01-31 21:56:40 +03:00
|
|
|
}
|
|
|
|
EOF
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
update_pkbuild() {
|
|
|
|
cp ./templates/PKGBUILD ./PKGBUILD
|
|
|
|
|
|
|
|
sed -i "s#%version%#$version#g" ./PKGBUILD
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-09 10:56:16 +03:00
|
|
|
is_nix_version_2_19() {
|
|
|
|
local version re major minor
|
|
|
|
|
|
|
|
version="$(nix --version | awk '{print $3}')"
|
|
|
|
re='([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)'
|
|
|
|
if [[ $version =~ $re ]]; then
|
|
|
|
major="${BASH_REMATCH[1]}"
|
|
|
|
minor="${BASH_REMATCH[2]}"
|
|
|
|
if [ "$major" -gt 2 ] || [ "$minor" -ge 19 ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
update_flake() {
|
2024-02-09 10:56:16 +03:00
|
|
|
local nixcmd="nix --extra-experimental-features nix-command --extra-experimental-features flakes"
|
2024-01-31 21:56:40 +03:00
|
|
|
sed -i 's#\(ymExe\.url\s*=\s*\).*;#\1'"$exe_link"';#' ./flake.nix
|
|
|
|
if check_dep nix; then
|
2024-02-09 10:56:16 +03:00
|
|
|
# Starting from 2.19 the interface of `nix flake` command changed. See
|
|
|
|
# https://nixos.org/manual/nix/stable/release-notes/rl-2.19
|
|
|
|
if is_nix_version_2_19; then
|
|
|
|
$nixcmd flake update ymExe
|
|
|
|
else
|
|
|
|
$nixcmd flake lock --update-input ymExe
|
|
|
|
fi
|
|
|
|
if [[ $(git status --porcelain -- flake.lock) ]]; then
|
|
|
|
$nixcmd flake update
|
|
|
|
fi
|
2024-01-31 21:56:40 +03:00
|
|
|
else
|
2024-02-05 16:18:51 +03:00
|
|
|
echo "flake.nix was updated, but nix is not installed to update flake.lock"
|
2024-01-31 21:56:40 +03:00
|
|
|
fi
|
|
|
|
}
|
2024-01-30 16:19:10 +03:00
|
|
|
|
2024-01-31 21:56:40 +03:00
|
|
|
check_deps
|
|
|
|
load_current_version
|
|
|
|
update_version
|
|
|
|
update_pkbuild
|
|
|
|
update_flake
|