: bharatvaj/scripts

commit 11cb1e75fcbc126b091bc60e50712be321109d46
parent 4ff50ec956fac69f3912bf0de8746db5fe4f31c3
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sat, 10 Oct 2026 16:04:27 +0530

Add ai/copy-pi-agent-model-tokens.sh
1 file changed, 32 insertions(+), 0 deletions(-)
A
ai/copy-pi-agent-model-tokens.sh
|
32
++++++++++++++++++++++++++++++++
diff --git a/ai/copy-pi-agent-model-tokens.sh b/ai/copy-pi-agent-model-tokens.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Copy Pi agent model/provider tokens from this machine to another host.
+# Usage: copy-pi-agent-model-tokens.sh [ssh-host]
+
+set -eu
+
+host="$1"
+[ -z "$host" ] && { echo "Usage $0 <host>"; exit 1; }
+src_dir=${PI_AGENT_DIR:-$HOME/.pi/agent}
+files="auth.json models-store.json"
+
+for f in $files; do
+    if [ ! -f "$src_dir/$f" ]; then
+        echo "missing: $src_dir/$f" >&2
+        exit 1
+    fi
+done
+
+# shellcheck disable=SC2088
+remote_dir='~/.pi/agent'
+stamp=$(date +%Y%m%d-%H%M%S)
+
+ssh "$host" "mkdir -p $remote_dir && chmod 700 ~/.pi ~/.pi/agent && for f in $files; do [ ! -e $remote_dir/\$f ] || cp -p $remote_dir/\$f $remote_dir/\$f.bak-$stamp; done"
+
+# Stream a tar archive so token contents never appear in argv, logs, or temp files.
+(
+    cd "$src_dir"
+    tar cf - $files
+) | ssh "$host" "cd $remote_dir && tar xf - && chmod 600 $files"
+
+echo "copied Pi agent token files to $host:$remote_dir"
+echo "remote backups, if any, are named *.bak-$stamp"