]> git.sev.monster Git - dotfiles.git/blame_incremental - bin/update-tridactyl-native.sh
update firefox theming
[dotfiles.git] / bin / update-tridactyl-native.sh
... / ...
CommitLineData
1#!/bin/sh
2
3# sh-compatible version of Tridactyl native binary updater
4# Python 3 is required. If it is not present, installation will fail.
5
6# Installation:
7# curl -fsSl 'url to this script' | sh
8# or:
9# wget -qO - 'url to this script' | sh
10
11# Handle errors (bash only)
12echoerr() {
13 red="\033[31m"
14 normal="\e[0m"
15 echo -e "$red$@$normal" >&2
16}
17trap "echoerr 'Failed to install!'" ERR >/dev/null 2>&1 #can't trap ERR in sh
18
19# Check requirements for native messenger
20python_path=$(which python3) || python_path=""
21if [ ! -x "$python_path" ]; then
22 echoerr "Error: Python 3 must exist in PATH."
23 echoerr "Please install it and run this script again."
24 exit 1
25fi
26
27# Set up environment
28manifest_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/tridactyl.json"
29native_loc="https://raw.githubusercontent.com/cmcaine/tridactyl/master/native/native_main.py"
30OSTYPE="${OSTYPE:-`uname -s | tr '[:upper:]' '[:lower:]'`}"
31XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
32data_home="${XDG_LOCAL_HOME:-$XDG_DATA_HOME/tridactyl}"
33native_file="$data_home/native_main.py.new"
34native_file_final="$data_home/native_main.py"
35# Decide where to put the manifest based on OS
36case "$OSTYPE" in
37 darwin*) manifest_home="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts";;
38 *) manifest_home="$HOME/.mozilla/native-messaging-hosts";;
39esac
40manifest_file="$manifest_home/tridactyl.json"
41# Test for curl
42if ! command -v curl; then
43 # Based on busybox-compatible wget
44 dl="wget -qO"
45else
46 dl="curl -sSo"
47fi
48
49echo "Installing script here: $data_home"
50echo "Installing manifest here: $manifest_home"
51
52# Download files
53mkdir -p "$manifest_home" "$data_home"
54# Use local copy for testing and/or use in git repo
55if [ "$1" == "local" ]; then
56 cp -f native/tridactyl.json "$manifest_file"
57 cp -f native/native_main.py "$native_file"
58else
59 $dl "$manifest_file" "$manifest_loc"
60 $dl "$native_file" "$native_loc"
61fi
62
63# Fix file contents
64sedEscape() {
65 sed 's/[&/\]/\\&/g' <<_EOF_
66$@
67_EOF_
68}
69# Replace native executable path in manifest
70sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file_final")/" "$manifest_file"
71chmod +x $native_file
72# Replace python shebang in native messenger script
73sed -i.bak "1s/.*/#!$(sedEscape /usr/bin/env) $(sedEscape "$python_path")/" "$native_file"
74mv "$native_file" "$native_file_final"
75
76echo
77echo "Successfully installed Tridactyl native messenger!"
78echo "Run ':native' in Firefox to check."
This page took 0.032633 seconds and 4 git commands to generate.