From 21ff7318595451cdaec42fd7ee18a7015de7bbae Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Wed, 13 Dec 2023 19:10:25 -0500
Subject: [PATCH] feat(update script): add dracula updating

---
 common/overlays/dracula-theme/default.nix |  4 +--
 updateSha.sh                              | 41 ++++++++++++++---------
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/common/overlays/dracula-theme/default.nix b/common/overlays/dracula-theme/default.nix
index d4d2e3fd..f8af6408 100644
--- a/common/overlays/dracula-theme/default.nix
+++ b/common/overlays/dracula-theme/default.nix
@@ -9,8 +9,8 @@
     src = prev.fetchFromGitHub {
       owner = "dracula";
       repo = "gtk";
-      rev = "84dd7a3021938ceec8a0ee292a8561f8a6d47ebe";
-      hash = "sha256-xHf+f0RGMtbprJX+3c0cmp5LKkf0V7BHKcoiAW60du8=";
+      rev = "0b64e1108f4a222d40b333435a41d9f1963a3326";
+      hash = "sha256-SQHfHNE6OURAPYX5+0WLkm2sivWIrP0mMgkU+GZCCho=";
     };
 
     installPhase = ''
diff --git a/updateSha.sh b/updateSha.sh
index 13531219..a46a2c19 100755
--- a/updateSha.sh
+++ b/updateSha.sh
@@ -8,29 +8,39 @@ parseNurl() {
     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"
+}
+
 # TODO
 
-# https://github.com/dracula/xresources
-#
-# https://github.com/dracula/gtk
-# https://github.com/dracula/plymouth
-# https://github.com/matt1432/bat
-#
-# https://github.com/aynp/dracula-wallpapers/blob/main/Art/4k/Waves%201.png?raw=true
-#
 # https://github.com/dasJ/spotifywm
 #
 # https://github.com/tio/input-emulator
 # https://gitlab.com/mishakmak/pam-fprint-grosshack
 # https://gitlab.com/phoneybadger/pokemon-colorscripts
 
+updateDracula() {
+    FILE="/home/matt/.nix/common/overlays/dracula-theme"
+    parseNurl "https://github.com/matt1432/bat"       "$FILE/bat.nix"
+    parseNurl "https://github.com/dracula/gtk"        "$FILE/default.nix"
+    parseNurl "https://github.com/dracula/plymouth"   "$FILE/plymouth.nix"
+    parseNurl "https://github.com/dracula/git"        "$FILE/git.nix"
+    parseNurl "https://github.com/dracula/xresources" "$FILE/xresources.nix"
+    parseFetchurl "https://github.com/aynp/dracula-wallpapers/blob/main/Art/4k/Waves%201.png?raw=true" "$FILE/wallpaper.nix"
+}
+
 updateFFZ() {
     FILE="/home/matt/.nix/home/firefox/addons/default.nix"
     URL="https://cdn.frankerfacez.com/script/frankerfacez-4.0-an+fx.xpi"
-    HASH=$(nix store prefetch-file --refresh --json \
-        --hash-type sha256 $URL | jq -r .hash)
 
-    sed -i "s,sha256 = .*,sha256 = \"$HASH\";," "$FILE"
+    parseFetchurl "$URL" "$FILE"
 }
 
 updateFirefoxAddons() {
@@ -61,22 +71,21 @@ updateGSR() {
 
         REV=$(printf "r%s.%s\n" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)")
         URL=https://dec05eba.com/snapshot/gpu-screen-recorder.git."$REV".tar.gz
-        HASH="$(nix store prefetch-file --refresh --json \
-            --hash-type sha256 $URL | jq -r .hash)"
-
         FILE="/home/matt/.nix/devices/binto/modules/gpu-replay.nix"
-        sed -i "s,url = .*,url = \"$URL\";," "$FILE"
-        sed -i "s,hash = .*,hash = \"$HASH\";," "$FILE"
+
+        parseFetchurl "$URL" "$FILE"
     )
 }
 
 doAll() {
     updateFFZ
+    updateDracula
     updateFirefoxAddons
     updateGSR
 }
 
 [[ "$1" == "-a" || "$1" == "--all" ]] && doAll
+[[ "$1" == "-d" || "$1" == "--dracula" ]] && updateDracula
 [[ "$1" == "-f" || "$1" == "--firefox" ]] && updateFirefoxAddons
 [[ "$1" == "-ffz" || "$1" == "--frankerfacez" ]] && updateFFZ
 [[ "$1" == "-gsr" || "$1" == "--gpu-screen-recorder" ]] && updateGSR