2020-10-24 07:03:13 +02:00
|
|
|
#!/bin/bash -eux
|
|
|
|
|
2020-10-30 08:50:07 +01:00
|
|
|
if [[ "$#" -lt 1 || (
|
|
|
|
! ( ( "$1" == "firefox" && "$#" -eq 1 ) ||
|
|
|
|
( "$1" == "chrome" && "$#" -eq 2 && ${#2} -eq 32 ) ||
|
|
|
|
( "$1" == "chromium" && "$#" -eq 2 && ${#2} -eq 32 ) ) ) ]]; then
|
2020-10-30 07:54:40 +01:00
|
|
|
echo "Usage: $0 <chrome EXTENSION_ID | chromium EXTENSION_ID | firefox>"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2020-10-24 07:03:13 +02:00
|
|
|
OS="$(uname -s)"
|
2020-10-30 07:54:40 +01:00
|
|
|
BROWSER="$(echo $1 | tr '[:upper:]' '[:lower:]')"
|
2020-10-24 07:03:13 +02:00
|
|
|
|
|
|
|
# https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#Manifest_location
|
|
|
|
# https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location
|
|
|
|
case "$OS $BROWSER" in
|
|
|
|
"Linux firefox")
|
|
|
|
MANIFEST_LOCATION="$HOME/.mozilla/native-messaging-hosts";;
|
|
|
|
"Darwin firefox")
|
|
|
|
MANIFEST_LOCATION="$HOME/Library/Application Support/Mozilla/NativeMessagingHosts";;
|
|
|
|
"Linux chrome")
|
|
|
|
MANIFEST_LOCATION="$HOME/.config/google-chrome/NativeMessagingHosts";;
|
|
|
|
"Linux chromium")
|
|
|
|
MANIFEST_LOCATION="$HOME/.config/chromium/NativeMessagingHosts";;
|
|
|
|
"Darwin chrome")
|
|
|
|
MANIFEST_LOCATION="$HOME/Library/Application Support/Google/Chrome/NativeMessagingHosts";;
|
|
|
|
"Darwin chromium")
|
|
|
|
MANIFEST_LOCATION="$HOME/Library/Application Support/Chromium/NativeMessagingHosts";;
|
|
|
|
esac
|
|
|
|
|
|
|
|
mkdir -p "$MANIFEST_LOCATION"
|
|
|
|
|
|
|
|
APP_NAME="com.rsnous.tabfs"
|
|
|
|
EXE_PATH=$(pwd)/fs/tabfs
|
|
|
|
|
|
|
|
case "$BROWSER" in
|
|
|
|
chrome | chromium)
|
2020-10-30 07:54:40 +01:00
|
|
|
EXTENSION_ID=$2
|
2020-10-24 07:03:13 +02:00
|
|
|
MANIFEST=$(cat <<EOF
|
|
|
|
{
|
|
|
|
"name": "$APP_NAME",
|
|
|
|
"description": "TabFS",
|
|
|
|
"path": "$EXE_PATH",
|
|
|
|
"type": "stdio",
|
|
|
|
"allowed_extensions": ["tabfs@rsnous.com"],
|
2020-10-30 07:54:40 +01:00
|
|
|
"allowed_origins": ["chrome-extension://$EXTENSION_ID/"]
|
2020-10-24 07:03:13 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
);;
|
|
|
|
firefox)
|
|
|
|
MANIFEST=$(cat <<EOF
|
|
|
|
{
|
|
|
|
"name": "$APP_NAME",
|
|
|
|
"description": "TabFS",
|
|
|
|
"path": "$EXE_PATH",
|
|
|
|
"type": "stdio",
|
|
|
|
"allowed_extensions": ["tabfs@rsnous.com"]
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
);;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "$MANIFEST" > "$MANIFEST_LOCATION/$APP_NAME.json"
|