about summary refs log tree commit diff
path: root/pkgs/applications/misc/1password
diff options
context:
space:
mode:
authorMario Rodas <marsam@users.noreply.github.com>2024-04-21 04:20:00 +0000
committerMario Rodas <marsam@users.noreply.github.com>2024-04-21 04:20:00 +0000
commitd1d5568d94788976716e101a2d97d6670e816d57 (patch)
tree7c162d47adb079826dd211905fa6371e1eba99f3 /pkgs/applications/misc/1password
parentb53ce73d70bf254d078785aa3858fe3a053f2cfe (diff)
_1password: add passthru.updateScript
Diffstat (limited to 'pkgs/applications/misc/1password')
-rw-r--r--pkgs/applications/misc/1password/default.nix2
-rwxr-xr-xpkgs/applications/misc/1password/update.sh42
2 files changed, 44 insertions, 0 deletions
diff --git a/pkgs/applications/misc/1password/default.nix b/pkgs/applications/misc/1password/default.nix
index a213c7ef89b8c..7ef91e330cbd5 100644
--- a/pkgs/applications/misc/1password/default.nix
+++ b/pkgs/applications/misc/1password/default.nix
@@ -63,6 +63,8 @@ stdenv.mkDerivation {
     $out/bin/${mainProgram} --version
   '';
 
+  passthru.updateScript = ./update.sh;
+
   passthru.tests.version = testers.testVersion {
     package = _1password;
   };
diff --git a/pkgs/applications/misc/1password/update.sh b/pkgs/applications/misc/1password/update.sh
new file mode 100755
index 0000000000000..562c1af31a257
--- /dev/null
+++ b/pkgs/applications/misc/1password/update.sh
@@ -0,0 +1,42 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl gnused nurl xq-xml
+
+set -eu
+
+ROOT="$(dirname "$(readlink -f "$0")")"
+NIX_DRV="$ROOT/default.nix"
+if [ ! -f "$NIX_DRV" ]; then
+  echo "ERROR: cannot find default.nix in $ROOT"
+  exit 1
+fi
+
+fetch_linux() {
+  VER="$1"
+  ARCH="$2"
+  URL="https://cache.agilebits.com/dist/1P/op2/pkg/v${VER}/op_${ARCH}_v${VER}.zip"
+  nurl --hash --expr "(import <nixpkgs> { }).fetchzip { url = \"$URL\"; stripRoot = false; }"
+}
+
+fetch_darwin() {
+  VER="$1"
+  URL="https://cache.agilebits.com/dist/1P/op2/pkg/v${VER}/op_apple_universal_v${VER}.pkg"
+  nurl --hash --expr "(import <nixpkgs> { }).fetchurl { url = \"$URL\"; }"
+}
+
+replace_sha() {
+  sed -i "s|\"$1\" \"sha256-.\{44\}\"|\"$1\" \"$2\"|" "$NIX_DRV"
+}
+
+CLI_VERSION="$(curl -Ls https://app-updates.agilebits.com/product_history/CLI2 | xq -q 'h3' | head -n1)"
+
+CLI_LINUX_AARCH64_SHA256=$(fetch_linux "$CLI_VERSION" "linux_arm64")
+CLI_LINUX_I686_SHA256=$(fetch_linux "$CLI_VERSION" "linux_386")
+CLI_LINUX_X64_SHA256=$(fetch_linux "$CLI_VERSION" "linux_amd64")
+CLI_DARWIN_UNIVERSAL_SHA256=$(fetch_darwin "$CLI_VERSION")
+
+sed -i "s/version = \".*\"/version = \"$CLI_VERSION\"/" "$NIX_DRV"
+
+replace_sha "linux_arm64" "$CLI_LINUX_AARCH64_SHA256"
+replace_sha "linux_386" "$CLI_LINUX_I686_SHA256"
+replace_sha "linux_amd64" "$CLI_LINUX_X64_SHA256"
+replace_sha "apple_universal" "$CLI_DARWIN_UNIVERSAL_SHA256"