diff options
author | Jonathan White <support@dmapps.us> | 2020-10-13 04:52:45 +0300 |
---|---|---|
committer | Jonathan White <support@dmapps.us> | 2020-10-14 05:38:03 +0300 |
commit | d7a9e48a9c6ea335cf5c295c3f6f66923fee88fe (patch) | |
tree | a68992e8a639037e03dc21a6d0e6cb4e7a56f0ff /utils | |
parent | dc57025218fc4b7ae7673be175d6b98b4f8f3b19 (diff) |
Make snap helper script more robust
* Fix #5127 - use `which keepassxc.proxy` to find the path of the snap proxy. Warn the user if the snap proxy was not found and bail out early.
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/keepassxc-snap-helper.sh | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/utils/keepassxc-snap-helper.sh b/utils/keepassxc-snap-helper.sh index ecb290daa..61f966a0b 100755 --- a/utils/keepassxc-snap-helper.sh +++ b/utils/keepassxc-snap-helper.sh @@ -18,13 +18,24 @@ set -e -DEBUG=false +JSON_OUT="" +BASE_DIR="." +INSTALL_DIR="" +INSTALL_FILE="org.keepassxc.keepassxc_browser.json" + +# Early out if the keepassxc.proxy executable cannot be found +if ! command -v keepassxc.proxy; then + echo "Could not find keepassxc.proxy! Ensure the keepassxc snap is installed properly." + exit 0 +fi + +PROXY_PATH=$(command -v keepassxc.proxy) JSON_FIREFOX=$(cat << EOF { "name": "org.keepassxc.keepassxc_browser", "description": "KeePassXC integration with native messaging support", - "path": "/snap/bin/keepassxc.proxy", + "path": "${PROXY_PATH}", "type": "stdio", "allowed_extensions": [ "keepassxc-browser@keepassxc.org" @@ -37,7 +48,7 @@ JSON_CHROME=$(cat << EOF { "name": "org.keepassxc.keepassxc_browser", "description": "KeePassXC integration with native messaging support", - "path": "/snap/bin/keepassxc.proxy", + "path": "${PROXY_PATH}", "type": "stdio", "allowed_origins": [ "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", @@ -47,21 +58,6 @@ JSON_CHROME=$(cat << EOF EOF ) -JSON_OUT="" -BASE_DIR="." -INSTALL_DIR="" -INSTALL_FILE="org.keepassxc.keepassxc_browser.json" - -buildJson() { - if [ -n "$1" ]; then - # Insert Firefox data - JSON_OUT=$JSON_FIREFOX - else - # Insert Chrome data - JSON_OUT=$JSON_CHROME - fi -} - askBrowserSnap() { if (whiptail --title "Snap Choice" --defaultno \ --yesno "Is this browser installed as a snap (usually NO)?" 8 60); then @@ -73,33 +69,33 @@ askBrowserSnap() { setupFirefox() { askBrowserSnap "./snap/firefox/common" - buildJson "firefox" + JSON_OUT=${JSON_FIREFOX} INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts" } setupChrome() { - buildJson + JSON_OUT=${JSON_CHROME} INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts" } setupChromium() { askBrowserSnap "./snap/chromium/current" - buildJson + JSON_OUT=${JSON_CHROME} INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts" } setupVivaldi() { - buildJson + JSON_OUT=${JSON_CHROME} INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts" } setupBrave() { - buildJson + JSON_OUT=${JSON_CHROME} INSTALL_DIR="${BASE_DIR}/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts" } setupTorBrowser() { - buildJson "firefox" + JSON_OUT=${JSON_FIREFOX} INSTALL_DIR="${BASE_DIR}/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts" } @@ -138,8 +134,6 @@ if [ $exitstatus = 0 ]; then mkdir -p "$INSTALL_DIR" echo "$JSON_OUT" > ${INSTALL_DIR}/${INSTALL_FILE} - $DEBUG && echo "Installed to: ${INSTALL_DIR}/${INSTALL_FILE}" - whiptail \ --title "Installation Complete" \ --msgbox "You will need to restart your browser in order to connect to KeePassXC" \ |