forked from browserpass/browserpass-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·148 lines (134 loc) · 4.85 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
set -e
DIR="$( cd "$( dirname "$0" )" && pwd )"
APP_NAME="com.dannyvankooten.browserpass"
HOST_FILE="$DIR/browserpass"
# Find target dirs for various browsers & OS'es
# https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location
# https://wiki.mozilla.org/WebExtensions/Native_Messaging
OPERATING_SYSTEM=$(uname -s)
case $OPERATING_SYSTEM in
Linux)
HOST_FILE="$DIR/browserpass-linux64"
if [ "$(whoami)" == "root" ]; then
TARGET_DIR_CHROME="/etc/opt/chrome/native-messaging-hosts"
TARGET_DIR_CHROMIUM="/etc/chromium/native-messaging-hosts"
TARGET_DIR_FIREFOX="/usr/lib/mozilla/native-messaging-hosts"
TARGET_DIR_VIVALDI="/etc/chromium/native-messaging-hosts"
else
TARGET_DIR_CHROME="$HOME/.config/google-chrome/NativeMessagingHosts"
TARGET_DIR_CHROMIUM="$HOME/.config/chromium/NativeMessagingHosts"
TARGET_DIR_FIREFOX="$HOME/.mozilla/native-messaging-hosts"
TARGET_DIR_VIVALDI="$HOME/.config/vivaldi/NativeMessagingHosts"
fi
;;
Darwin)
HOST_FILE="$DIR/browserpass-darwinx64"
if [ "$(whoami)" == "root" ]; then
TARGET_DIR_CHROME="/Library/Google/Chrome/NativeMessagingHosts"
TARGET_DIR_CHROMIUM="/Library/Application Support/Chromium/NativeMessagingHosts"
TARGET_DIR_FIREFOX="/Library/Application Support/Mozilla/NativeMessagingHosts"
TARGET_DIR_VIVALDI="/Library/Application Support/Vivaldi/NativeMessagingHosts"
else
TARGET_DIR_CHROME="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts"
TARGET_DIR_CHROMIUM="$HOME/Library/Application Support/Chromium/NativeMessagingHosts"
TARGET_DIR_FIREFOX="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts"
TARGET_DIR_VIVALDI="$HOME/Library/Application Support/Vivaldi/NativeMessagingHosts"
fi
;;
OpenBSD)
HOST_FILE="$DIR/browserpass-openbsd64"
if [ "$(whoami)" == "root" ]; then
echo "Installing as root not supported."
exit 1
fi
TARGET_DIR_CHROME="$HOME/.config/google-chrome/NativeMessagingHosts"
TARGET_DIR_CHROMIUM="$HOME/.config/chromium/NativeMessagingHosts"
TARGET_DIR_FIREFOX="$HOME/.mozilla/native-messaging-hosts"
TARGET_DIR_VIVALDI="$HOME/.config/vivaldi/NativeMessagingHosts"
;;
FreeBSD)
HOST_FILE="$DIR/browserpass-freebsd64"
if [ "$(whoami)" == "root" ]; then
echo "Installing as root not supported"
exit 1
fi
TARGET_DIR_CHROME="$HOME/.config/google-chrome/NativeMessagingHosts"
TARGET_DIR_CHROMIUM="$HOME/.config/chromium/NativeMessagingHosts"
TARGET_DIR_FIREFOX="$HOME/.mozilla/native-messaging-hosts"
TARGET_DIR_VIVALDI="$HOME/.config/vivaldi/NativeMessagingHosts"
;;
*)
echo "$OPERATING_SYSTEM is not supported"
exit 1
;;
esac
if [ -e "$DIR/browserpass" ]; then
echo "Detected development binary"
HOST_FILE="$DIR/browserpass"
fi
echo ""
echo "Select your browser:"
echo "===================="
echo "1) Chrome"
echo "2) Chromium"
echo "3) Firefox"
echo "4) Vivaldi"
echo -n "1-4: "
read BROWSER
echo ""
# Set target dir from user input
case $BROWSER in
1)
BROWSER_NAME="Chrome"
TARGET_DIR="$TARGET_DIR_CHROME"
;;
2)
BROWSER_NAME="Chromium"
TARGET_DIR="$TARGET_DIR_CHROMIUM"
;;
3)
BROWSER_NAME="Firefox"
TARGET_DIR="$TARGET_DIR_FIREFOX"
;;
4)
BROWSER_NAME="Vivaldi"
TARGET_DIR="$TARGET_DIR_VIVALDI"
;;
*)
echo "Invalid selection. Please select 1-4."
exit 1
;;
esac
echo "Installing $BROWSER_NAME host config"
# Create config dir if not existing
mkdir -p "$TARGET_DIR"
# Escape host file
ESCAPED_HOST_FILE=${HOST_FILE////\\/}
# Copy manifest host config file
if [ "$BROWSER_NAME" == "Chrome" ] || \
[ "$BROWSER_NAME" == "Chromium" ] || \
[ "$BROWSER_NAME" == "Vivaldi" ]; then
if [ ! -f "$DIR/chrome-host.json" ] || [ ! -f "$DIR/chrome-policy.json" ]; then
echo "ERROR: '$DIR/chrome-host.json' or '$DIR/chrome-policy.json' is missing."
echo "If you are running './install.sh' from a release archive, please file a bug."
echo "If you are running './install.sh' from the source code, make sure to follow CONTRIBUTING.md on how to build first."
exit 1
fi
cp "$DIR/chrome-host.json" "$TARGET_DIR/$APP_NAME.json"
mkdir -p "$TARGET_DIR"/../policies/managed/
cp "$DIR/chrome-policy.json" "$TARGET_DIR/../policies/managed/$APP_NAME.json"
else
if [ ! -f "$DIR/firefox-host.json" ]; then
echo "ERROR: '$DIR/firefox-host.json' is missing."
echo "If you are running './install.sh' from a release archive, please file a bug."
echo "If you are running './install.sh' from the source code, make sure to follow CONTRIBUTING.md on how to build first."
exit 1
fi
cp "$DIR/firefox-host.json" "$TARGET_DIR/$APP_NAME.json"
fi
# Replace path to host
sed -i -e "s/%%replace%%/$ESCAPED_HOST_FILE/" "$TARGET_DIR/$APP_NAME.json"
# Set permissions for the manifest so that all users can read it.
chmod o+r "$TARGET_DIR/$APP_NAME.json"
echo "Native messaging host for $BROWSER_NAME has been installed to $TARGET_DIR."