3 # sh-compatible version of Tridactyl native binary updater
4 # Python 3 is required. If it is not present, installation will fail.
7 # curl -fsSl 'url to this script' | sh
9 # wget -qO - 'url to this script' | sh
11 # Handle errors (bash only)
15 echo -e "$red$@$normal" >&2
17 trap "echoerr 'Failed to install!'" ERR >/dev/null 2>&1 #can't trap ERR in sh
19 # Check requirements for native messenger
20 python_path=$(which python3 | head -1) || python_path=""
21 if [ ! -x "$python_path" ]; then
22 echoerr "Error: Python 3 must exist in PATH."
23 echoerr "Please install it and run this script again."
28 manifest_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/tridactyl.json"
29 native_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/native_main.py"
30 OSTYPE="${OSTYPE:-`uname -s | tr '[:upper:]' '[:lower:]'`}"
31 XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
32 data_home="${XDG_LOCAL_HOME:-$XDG_DATA_HOME/tridactyl}"
33 native_file="$data_home/native_main.py.new"
34 native_file_final="$data_home/native_main.py"
35 # Decide where to put the manifest based on OS
37 darwin*) manifest_home="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts";;
38 *) manifest_home="$HOME/.mozilla/native-messaging-hosts";;
40 manifest_file="$manifest_home/tridactyl.json"
42 if ! command -v curl; then
43 # Based on busybox-compatible wget
49 echo "Installing script here: $data_home"
50 echo "Installing manifest here: $manifest_home"
53 mkdir -p "$manifest_home" "$data_home"
54 # Use local copy for testing and/or use in git repo
55 if [ "$1" == "local" ]; then
56 cp -f native/tridactyl.json "$manifest_file"
57 cp -f native/native_main.py "$native_file"
59 $dl "$manifest_file" "$manifest_loc"
60 $dl "$native_file" "$native_loc"
65 sed 's/[&/\]/\\&/g' <<_EOF_
69 # Replace native executable path in manifest
70 sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file_final")/" "$manifest_file"
72 # Replace python shebang in native messenger script
73 sed -i.bak "1s/.*/#!$(sedEscape /usr/bin/env) $(sedEscape "$python_path")/" "$native_file"
74 mv "$native_file" "$native_file_final"
77 echo "Successfully installed Tridactyl native messenger!"
78 echo "Run ':native' in Firefox to check."