-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.sh
executable file
·50 lines (39 loc) · 1.44 KB
/
install.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Susumu OTA <[email protected]>
# SPDX-License-Identifier: MIT
# settings
node_path=$(which node) # specify node path if you want to use another one
# constants (do not edit)
keychain="keychain.mjs"
json="io.github.susumuota.nostr_keyx.json"
# make paths absolute
script_dir=$(cd $(dirname $0); pwd)
json_path="${script_dir}/$(basename $json)"
json_stab_path="${json_path}.stab"
keychain_path="${script_dir}/$(basename $keychain)"
# ask extension ID if not specified
if [ -z "$1" ]; then
read -p "Enter Chrome extension ID: " extension_id
else
extension_id=$1
fi
# check extension ID
if [ -z "$extension_id" ]; then
echo "Usage: $0 <extension_id>"
exit 1
fi
echo "Extension ID: ${extension_id}"
# replace node path at shebang of keychain.mjs
# TODO: error handling
if [ ! -z "$node_path" ] && [ "$node_path" != "/usr/local/bin/node" ]; then
sed -i -e "1 s|/usr/local/bin/node|${node_path}|" "$keychain_path"
fi
# replace __EXTENSION_ID__ and path of keychain.mjs in json file
# TODO: error handling
sed -e "s/__EXTENSION_ID__/${extension_id}/" \
-e "s|/path/to/keychain.mjs|${keychain_path}|" \
"$json_stab_path" > "$json_path"
# copy json file to native messaging host location
# https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location
cp -f "$json_path" ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/
echo "Installed successfully"