Skip to content

Commit

Permalink
Make snap helper script more robust
Browse files Browse the repository at this point in the history
* Fix keepassxreboot#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.
  • Loading branch information
droidmonkey committed Oct 14, 2020
1 parent dc57025 commit d7a9e48
Showing 1 changed file with 20 additions and 26 deletions.
46 changes: 20 additions & 26 deletions utils/keepassxc-snap-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/",
Expand All @@ -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
Expand All @@ -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"
}

Expand Down Expand Up @@ -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" \
Expand Down

0 comments on commit d7a9e48

Please sign in to comment.