2018-04-18 21:49:33 +01:00
|
|
|
#!/bin/bash
|
2018-04-17 18:28:11 +01:00
|
|
|
|
2018-04-25 22:23:31 +01:00
|
|
|
set -e
|
|
|
|
|
2018-05-09 12:46:09 +01:00
|
|
|
echoerr() {
|
|
|
|
red="\033[31m"
|
|
|
|
normal="\e[0m"
|
|
|
|
echo -e "$red$@$normal" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
sedEscape() {
|
|
|
|
sed 's/[&/\]/\\&/g' <<< "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "echoerr 'Failed to install!'" ERR
|
|
|
|
|
2018-04-18 21:49:33 +01:00
|
|
|
# To install, curl -fsSl 'url to this script' | bash
|
2018-04-17 18:28:11 +01:00
|
|
|
|
|
|
|
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config/tridactyl}"
|
|
|
|
XDG_DATA_HOME="${XDG_LOCAL_HOME:-$HOME/.local/share/tridactyl}"
|
|
|
|
manifest_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/tridactyl.json"
|
|
|
|
native_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/native_main.py"
|
|
|
|
|
|
|
|
# Decide where to put the manifest based on OS
|
|
|
|
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
|
|
|
manifest_home="$HOME/.mozilla/native-messaging-hosts/"
|
|
|
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
manifest_home="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "$manifest_home" "$XDG_DATA_HOME"
|
|
|
|
|
|
|
|
manifest_file="$manifest_home/tridactyl.json"
|
2018-04-28 18:01:44 +01:00
|
|
|
native_file="$XDG_DATA_HOME/native_main.py.new"
|
|
|
|
native_file_final="$XDG_DATA_HOME/native_main.py"
|
2018-04-17 18:28:11 +01:00
|
|
|
|
2018-04-25 22:23:31 +01:00
|
|
|
echo "Installing manifest here: $manifest_home"
|
|
|
|
echo "Installing script here: XDG_DATA_HOME: $XDG_DATA_HOME"
|
2018-04-17 18:28:11 +01:00
|
|
|
|
|
|
|
# Until this PR is merged into master, we'll be copying the local version over
|
|
|
|
# instead of downloading it
|
2018-04-17 18:45:54 +01:00
|
|
|
if [[ "$1" == "local" ]]; then
|
|
|
|
cp -f native/tridactyl.json "$manifest_file"
|
|
|
|
cp -f native/native_main.py "$native_file"
|
|
|
|
else
|
2018-04-25 22:23:31 +01:00
|
|
|
curl -sS --create-dirs -o "$manifest_file" "$manifest_loc"
|
|
|
|
curl -sS --create-dirs -o "$native_file" "$native_loc"
|
2018-04-17 18:45:54 +01:00
|
|
|
fi
|
2018-04-17 18:28:11 +01:00
|
|
|
|
2018-05-09 12:46:09 +01:00
|
|
|
sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file_final")/" "$manifest_file"
|
2018-04-17 18:45:54 +01:00
|
|
|
chmod +x $native_file
|
2018-04-21 18:17:39 +01:00
|
|
|
|
|
|
|
# Requirements for native messenger
|
2018-05-09 12:46:09 +01:00
|
|
|
python_path=$(which python3) || python_path=""
|
|
|
|
if [[ -x "$python_path" ]]; then
|
2018-05-17 13:54:56 +01:00
|
|
|
sed -i.bak "1s/.*/#!$(sedEscape /usr/bin/env) $(sedEscape "$python_path")/" "$native_file"
|
2018-04-28 18:01:44 +01:00
|
|
|
mv "$native_file" "$native_file_final"
|
2018-04-21 18:17:39 +01:00
|
|
|
else
|
2018-05-09 13:43:23 +01:00
|
|
|
echoerr "Error: Python 3 must exist in PATH."
|
|
|
|
echoerr "Please install it and run this script again."
|
2018-04-25 22:23:31 +01:00
|
|
|
exit 1
|
2018-04-21 18:17:39 +01:00
|
|
|
fi
|
2018-04-25 22:23:31 +01:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Successfully installed Tridactyl native messenger!"
|
|
|
|
echo "Run ':native' in Firefox to check."
|