From e9c729e07103aeff5f94e7cae7b3b3246dd28857 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Thu, 29 Mar 2018 13:50:46 +1100 Subject: [PATCH 1/3] Install a functional host helper on OS X Signed-off-by: Olivier Mehani --- src/install_host_app.sh | 28 ++++++++++++++++++++++++---- src/passff.py | 7 ++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/install_host_app.sh b/src/install_host_app.sh index aedcacf..79e2143 100755 --- a/src/install_host_app.sh +++ b/src/install_host_app.sh @@ -11,8 +11,10 @@ HOST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passf MANIFEST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passff.json" KERNEL_NAME=$(uname -s) +PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" + case "$KERNEL_NAME" in - *BSD*) + *BSD* | *Darwin*) IS_BSD=true ;; *) @@ -102,6 +104,14 @@ else exit 1 fi +PASS_PATH="$(which pass)" +if [ -x "$PASS_PATH" ]; then + echo "Pass executable located at $PASS_PATH" +else + echo "Pass executable not found, but Pass is required for PassFF to work!" + exit 1 +fi + if [ -z "$TARGET_DIR" ]; then usage exit 1 @@ -126,16 +136,26 @@ else curl -sSL "$MANIFEST_URL" > "$MANIFEST_FILE_PATH" fi -# When using sed on macOS, backup extension is an mandatory argument -# whereas on GNU sed or BSD sed backup extension may be omit. -if [ "$KERNEL_NAME" == 'Darwin' ]; then +if [ "$IS_BSD" = true ]; then + # Use BSD style sed on BSD-ish systems # Replace path to python3 executable /usr/bin/sed -i '' "1 s@.*@#\!${PYTHON3_PATH}@" "$HOST_FILE_PATH" + # Replace path to pass (only in a line starting with `COMMAND =`) + /usr/bin/sed -i '' "/^COMMAND *=/s@\"pass\"@\"$PASS_PATH\"@" "$HOST_FILE_PATH" + # Set the PATH to match this script's + /usr/bin/sed -i '' "s@\"PATH\":.*@\"PATH\": \"$PATH\"@" "$HOST_FILE_PATH" + # Replace path to host /usr/bin/sed -i '' -e "s/PLACEHOLDER/$ESCAPED_HOST_FILE_PATH/" "$MANIFEST_FILE_PATH" + else # Replace path to python3 executable sed -i "1 s@.*@#\!${PYTHON3_PATH}@" "$HOST_FILE_PATH" + # Replace path to pass (only in a line starting with `COMMAND =`) + /usr/bin/sed -i -e "/^COMMAND *=/s@\"pass\"@\"$PASS_PATH\"@" "$HOST_FILE_PATH" + # Set the PATH to match this script's + /usr/bin/sed -i -e "s@\"PATH\":.*@\"PATH\": \"$PATH\"@" "$HOST_FILE_PATH" + # Replace path to host sed -i -e "s/PLACEHOLDER/$ESCAPED_HOST_FILE_PATH/" "$MANIFEST_FILE_PATH" fi diff --git a/src/passff.py b/src/passff.py index 3cd2ca1..8e09bbb 100755 --- a/src/passff.py +++ b/src/passff.py @@ -12,14 +12,11 @@ VERSION = "_VERSIONHOLDER_" ################################################################################ ######################## Begin preferences section ############################# ################################################################################ -# Default command for MacOS: -#COMMAND = "/usr/local/bin/pass" -COMMAND = "/usr/bin/pass" +COMMAND = "pass" COMMAND_ARGS = [] COMMAND_ENV = { "TREE_CHARSET": "ISO-8859-1", - # Default PATH for MacOS: - #"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", + "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin", } CHARSET = "UTF-8" ################################################################################ From 77f8dbbd663ed90bdec93f2e8d439518555e440b Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 4 Apr 2018 10:44:11 +1000 Subject: [PATCH 2/3] Be POSIX sh compatible Signed-off-by: Olivier Mehani --- src/install_host_app.sh | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/install_host_app.sh b/src/install_host_app.sh index 79e2143..12490de 100755 --- a/src/install_host_app.sh +++ b/src/install_host_app.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # This script is derived from `install.sh` in Danny van Kooten's "browserpass": # https://github.com/dannyvankooten/browserpass @@ -11,22 +11,11 @@ HOST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passf MANIFEST_URL="https://github.com/passff/passff-host/releases/download/$VERSION/passff.json" KERNEL_NAME=$(uname -s) -PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" - -case "$KERNEL_NAME" in - *BSD* | *Darwin*) - IS_BSD=true - ;; - *) - IS_BSD=false - ;; -esac - # Find target dirs for various browsers & OS'es # https://developer.chrome.com/extensions/nativeMessaging#native-messaging-host-location # https://wiki.mozilla.org/WebExtensions/Native_Messaging -if [ "$KERNEL_NAME" == 'Darwin' ]; then - if [ "$(whoami)" == "root" ]; then +if [ "$KERNEL_NAME" = 'Darwin' ]; then + if [ "$(whoami)" = "root" ]; then TARGET_DIR_CHROME="/Library/Google/Chrome/NativeMessagingHosts" TARGET_DIR_CHROMIUM="/Library/Application Support/Chromium/NativeMessagingHosts" TARGET_DIR_FIREFOX="/Library/Application Support/Mozilla/NativeMessagingHosts" @@ -38,7 +27,7 @@ if [ "$KERNEL_NAME" == 'Darwin' ]; then TARGET_DIR_VIVALDI="$HOME/Library/Application Support/Vivaldi/NativeMessagingHosts" fi else - if [ "$(whoami)" == "root" ]; then + if [ "$(whoami)" = "root" ]; then TARGET_DIR_CHROME="/etc/opt/chrome/native-messaging-hosts" TARGET_DIR_CHROMIUM="/etc/chromium/native-messaging-hosts" TARGET_DIR_FIREFOX="/usr/lib/mozilla/native-messaging-hosts" @@ -51,7 +40,7 @@ else fi fi -function usage { +usage() { echo "Usage: $0 [OPTION] [chrome|chromium|firefox|opera|vivaldi] Options: @@ -59,7 +48,7 @@ function usage { -h, --help Show this message" } -while [[ $# -gt 0 ]]; do +while [ $# -gt 0 ]; do case $1 in chrome) BROWSER_NAME="Chrome" From 5799795fe506f31b3fac5e5b2d7e874d122efbbc Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 4 Apr 2018 10:45:28 +1000 Subject: [PATCH 3/3] Don't rely on sed's OS-specific behaviour Signed-off-by: Olivier Mehani --- src/install_host_app.sh | 47 +++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/src/install_host_app.sh b/src/install_host_app.sh index 12490de..7626ce4 100755 --- a/src/install_host_app.sh +++ b/src/install_host_app.sh @@ -108,45 +108,32 @@ fi HOST_FILE_PATH="$TARGET_DIR/$APP_NAME.py" MANIFEST_FILE_PATH="$TARGET_DIR/$APP_NAME.json" -ESCAPED_HOST_FILE_PATH="${HOST_FILE_PATH////\\/}" echo "Installing $BROWSER_NAME host config" # Create config dir if not existing mkdir -p "$TARGET_DIR" +# Replace path to python3 executable \ +# Replace path to pass (only in a line starting with "COMMAND =") \ +# Set the PATH to match this script's \ +HOST_SED=" \ +1 s@.*@#!${PYTHON3_PATH}@; \ +/^COMMAND *=/s@\"pass\"@\"$PASS_PATH\"@; \ +s@\"PATH\":.*@\"PATH\": \"$PATH\"@; \ +" +# Replace path to host \ +MANIFEST_SED=" \ +s@PLACEHOLDER@$HOST_FILE_PATH@; \ +" + if [ "$USE_LOCAL_FILES" = true ]; then - DIR="$( cd "$( dirname "$0" )" && pwd )" - cp "$DIR/passff.py" "$HOST_FILE_PATH" - cp "$DIR/passff.json" "$MANIFEST_FILE_PATH" + sed -e "${HOST_SED}" "$(dirname "$0")/passff.py" > "$HOST_FILE_PATH" + sed -e "${MANIFEST_SED}" "$(dirname "$0")/passff.json" > "$MANIFEST_FILE_PATH" else # Download native host script and manifest - curl -sSL "$HOST_URL" > "$HOST_FILE_PATH" - curl -sSL "$MANIFEST_URL" > "$MANIFEST_FILE_PATH" -fi - -if [ "$IS_BSD" = true ]; then - # Use BSD style sed on BSD-ish systems - # Replace path to python3 executable - /usr/bin/sed -i '' "1 s@.*@#\!${PYTHON3_PATH}@" "$HOST_FILE_PATH" - # Replace path to pass (only in a line starting with `COMMAND =`) - /usr/bin/sed -i '' "/^COMMAND *=/s@\"pass\"@\"$PASS_PATH\"@" "$HOST_FILE_PATH" - # Set the PATH to match this script's - /usr/bin/sed -i '' "s@\"PATH\":.*@\"PATH\": \"$PATH\"@" "$HOST_FILE_PATH" - - # Replace path to host - /usr/bin/sed -i '' -e "s/PLACEHOLDER/$ESCAPED_HOST_FILE_PATH/" "$MANIFEST_FILE_PATH" - -else - # Replace path to python3 executable - sed -i "1 s@.*@#\!${PYTHON3_PATH}@" "$HOST_FILE_PATH" - # Replace path to pass (only in a line starting with `COMMAND =`) - /usr/bin/sed -i -e "/^COMMAND *=/s@\"pass\"@\"$PASS_PATH\"@" "$HOST_FILE_PATH" - # Set the PATH to match this script's - /usr/bin/sed -i -e "s@\"PATH\":.*@\"PATH\": \"$PATH\"@" "$HOST_FILE_PATH" - - # Replace path to host - sed -i -e "s/PLACEHOLDER/$ESCAPED_HOST_FILE_PATH/" "$MANIFEST_FILE_PATH" + curl -sSL "$HOST_URL" | sed -e "${HOST_SED}" > "$HOST_FILE_PATH" + curl -sSL "$MANIFEST_URL" | sed -e "${MANIFEST_SED}" > "$MANIFEST_FILE_PATH" fi # Set permissions for the manifest so that all users can read it.