-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathset_key.sh
More file actions
executable file
·35 lines (29 loc) · 1.03 KB
/
set_key.sh
File metadata and controls
executable file
·35 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Usage: ./set_key.sh sk-ant-your-key-here
# Pushes Anthropic API key to the watch via ADB (no shell interpolation)
KEY=$1
PKG="com.thinkoff.clawwatch"
if [ -z "$KEY" ]; then
echo "Usage: ./set_key.sh sk-ant-..."
exit 1
fi
# Validate key — only alphanumeric, dash, underscore allowed
if ! echo "$KEY" | grep -qE '^[a-zA-Z0-9_-]+$'; then
echo "Error: invalid key format"
exit 1
fi
# Write to temp file — never interpolate key into shell command
TMP=$(mktemp /tmp/clawwatch_prefs_XXXXXX.xml)
cat > "$TMP" << XMLEOF
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<map>
<string name="anthropic_api_key">${KEY}</string>
</map>
XMLEOF
echo "Pushing API key to watch..."
adb push "$TMP" /data/local/tmp/clawwatch_tmp.xml
adb shell "run-as $PKG sh -c 'mkdir -p /data/data/$PKG/shared_prefs'"
adb shell "run-as $PKG sh -c 'cp /data/local/tmp/clawwatch_tmp.xml /data/data/$PKG/shared_prefs/clawwatch_prefs.xml'"
adb shell "rm /data/local/tmp/clawwatch_tmp.xml"
rm "$TMP"
echo "Done. Restart ClawWatch on the watch."