nixos-configs/updateSha.sh

70 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Deps:
# - nurl
# - jq
# - mozilla-addons-to-nix
# - alejandra
parseNurl() {
REV=$(nurl -j "$1" | jq '.["args"].["rev"]')
HASH=$(nurl -j "$1" | jq '.["args"].["hash"]')
sed -i "s,rev = .*,rev = $REV;," "$2"
sed -i "s,hash = .*,hash = $HASH;," "$2"
}
parseFetchurl() {
URL="$1"
FILE="$2"
HASH="$(nix store prefetch-file --refresh --json \
--hash-type sha256 "$URL" --name "escaped" | jq -r .hash)"
sed -i "s,url = .*,url = \"$URL\";," "$FILE"
sed -i "s,hash = .*,hash = \"$HASH\";," "$FILE"
# For Firefox addons
sed -i "s,sha256 = .*,sha256 = \"$HASH\";," "$FILE"
}
2023-12-13 16:53:40 -05:00
updateFFZ() {
FILE="$FLAKE/home/firefox/addons/default.nix"
2023-12-13 16:53:40 -05:00
URL="https://cdn.frankerfacez.com/script/frankerfacez-4.0-an+fx.xpi"
parseFetchurl "$URL" "$FILE"
2023-12-13 16:53:40 -05:00
}
updateFirefoxAddons() {
echo "Updating firefox addons using mozilla-addons-to-nix"
(
cd "$FLAKE/home/firefox/addons" || return;
file=generated-firefox-addons.nix
if [[ -f $file ]]; then
printf "\nOld versions: \n"
grep -A 1 --no-group-separator 'pname' "$file" |
awk '{ gsub(/"/, ""); gsub(/;/, ""); print $3 }' |
awk 'NR%2{printf $0" version ";next;}1' | paste -sd'\n' -
printf "\nNew versions: \n"
fi
mozilla-addons-to-nix addons.json generated-firefox-addons.nix
)
}
doAll() {
2023-12-13 16:53:40 -05:00
updateFFZ
updateFirefoxAddons
}
[[ "$1" == "-a" || "$1" == "--all" ]] && doAll
[[ "$1" == "-f" || "$1" == "--firefox" ]] && updateFirefoxAddons
2023-12-13 16:53:40 -05:00
[[ "$1" == "-ffz" || "$1" == "--frankerfacez" ]] && updateFFZ
alejandra "$FLAKE"