-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathinstall.sh
executable file
·113 lines (107 loc) · 2.89 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
#!/usr/bin/env bash
# Select browser
if [[ -n $1 ]]; then
browser=$1
elif [[ -n "${BROWSER}" ]]; then
browser=$(basename "${BROWSER}")
echo "Using browser ${browser} from environment variable"
else
# does not default; users need to specify the browser
:
fi
# Common variables
LINUX_NMH_DIR="NativeMessagingHosts"
JSON_FILE="ff2mpv-chromium.json"
select_browser() {
trap 'echo; exit 1' INT
case $browser in
# https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location
chromium)
linux_path="$HOME/.config/chromium"
mac_path="$HOME/Library/Application Support/Chromium"
;;
chrome)
linux_path="$HOME/.config/google-chrome"
mac_path="$HOME/Library/Application Support/Google/Chrome"
;;
brave)
linux_path="$HOME/.config/BraveSoftware/Brave-Browser"
mac_path="$HOME/Library/Application Support/BraveSoftware/Brave-Browser"
;;
edge)
# https://docs.microsoft.com/en-us/microsoft-edge/extensions-chromium/developer-guide/native-messaging#step-3---copy-the-native-messaging-host-manifest-file-to-your-system
linux_path="$HOME/.config/microsoft-edge"
mac_path="$HOME/Library/Application Support/Microsoft Edge"
;;
firefox)
linux_path="$HOME/.mozilla"
mac_path="$HOME/Library/Application Support/Mozilla"
LINUX_NMH_DIR="native-messaging-hosts"
JSON_FILE="ff2mpv.json"
;;
custom-chromium)
if (($# == 2)); then
linux_path="$2" mac_path="$2"
else
printf "path: " && read -r linux_path
mac_path="$linux_path"
fi
;;
custom-firefox)
if (($# == 2)); then
linux_path="$2" mac_path="$2"
else
printf "path: " && read -r linux_path
mac_path="$linux_path"
fi
LINUX_NMH_DIR="native-messaging-hosts"
JSON_FILE="ff2mpv.json"
;;
*)
echo >&2 '
Invalid option. Please select a valid browser:
- "chrome"
- "chromium"
- "brave"
- "edge"
- "firefox"
- "custom-chromium"
- "custom-firefox"
'
printf "browser: " && read -r browser
select_browser "$@"
;;
esac
}
select_browser "$@"
# Some environment path variables
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
case "$(uname)" in
Linux*)
BROWSER_DEST="$linux_path"
JSON_DEST="$BROWSER_DEST/$LINUX_NMH_DIR"
;;
FreeBSD*)
BROWSER_DEST="$linux_path"
JSON_DEST="$BROWSER_DEST/$LINUX_NMH_DIR"
;;
Darwin*)
BROWSER_DEST="$mac_path"
JSON_DEST="$BROWSER_DEST/NativeMessagingHosts"
;;
*)
echo "Unsupported OS, please follow the manual instructions in the wiki"
exit 1
;;
esac
OLD_PATH="/home/william/scripts/ff2mpv"
# Copying the JSON
if [[ -d "$BROWSER_DEST" ]]; then
mkdir -p "$JSON_DEST"
# Replace the placeholder path in the JSON file and install it
sed -e "s|$OLD_PATH|$CURRENT_DIR/ff2mpv.py|g" "$JSON_FILE" >"$JSON_DEST"/ff2mpv.json
else
echo "Please start your browser at least once to generate the required directories"
exit 1
fi
echo "Install successful!"