61 lines
2.0 KiB
Bash
Executable File
61 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
echoerr() {
|
|
red="\\033[31m"
|
|
normal="\\e[0m"
|
|
printf "%b\n" "$red$*$normal" >&2
|
|
}
|
|
|
|
sedEscape() {
|
|
printf "%s" "$@" | sed 's/[&/\]/\\&/g'
|
|
}
|
|
|
|
run() {
|
|
set -e
|
|
|
|
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
|
manifest_home="$HOME/.librewolf/native-messaging-hosts/"
|
|
binary_suffix="Linux"
|
|
native_version="$(curl -sSL https://api.github.com/repos/tridactyl/native_messenger/releases/latest | grep "tag_name" | cut -d':' -f2- | sed 's|[^0-9\.]||g')"
|
|
|
|
manifest_loc="https://raw.githubusercontent.com/tridactyl/native_messenger/$native_version/tridactyl.json"
|
|
native_loc="https://github.com/tridactyl/native_messenger/releases/download/$native_version/native_main-$binary_suffix"
|
|
manifest_file="$manifest_home/tridactyl.json"
|
|
native_file="$XDG_DATA_HOME/tridactyl/native_main"
|
|
|
|
echo "Installing manifest here: $manifest_home"
|
|
echo "Installing script here: XDG_DATA_HOME: $XDG_DATA_HOME/tridactyl"
|
|
|
|
mkdir -p "$manifest_home" "$XDG_DATA_HOME"
|
|
curl -sSL --create-dirs -o "$manifest_file" "$manifest_loc"
|
|
curl -sSL --create-dirs -o "$native_file" "$native_loc"
|
|
|
|
if [ ! -f "$manifest_file" ] ; then
|
|
echoerr "Failed to create '$manifest_file'. Please make sure that the directories exist and that you have the necessary permissions."
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f "$native_file" ] ; then
|
|
echoerr "Failed to create '$native_file'. Please make sure that the directories exist and that you have the necessary permissions."
|
|
exit 1
|
|
fi
|
|
|
|
sed -i.bak "s/REPLACE_ME_WITH_SED/$(sedEscape "$native_file")/" "$manifest_file"
|
|
chmod +x "$native_file"
|
|
|
|
echo
|
|
echo "Successfully installed Tridactyl native messenger!"
|
|
echo "Run ':native' in Firefox to check."
|
|
}
|
|
|
|
# Run the run function in a subshell so that it can be exited early if an error
|
|
# occurs
|
|
if ret="$(run "$@")"; then
|
|
# Print captured output
|
|
printf "%b\n" "$ret"
|
|
else
|
|
# Print captured output, ${ret:+\n} adds a newline only if ret isn't empty
|
|
printf "%b" "$ret${ret:+\n}"
|
|
echoerr 'Failed to install!'
|
|
fi
|