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.
This commit is contained in:
Jonathan White 2020-10-12 21:52:45 -04:00
parent dc57025218
commit d7a9e48a9c
No known key found for this signature in database
GPG Key ID: 440FC65F2E0C6E01

View File

@ -18,13 +18,24 @@
set -e 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 JSON_FIREFOX=$(cat << EOF
{ {
"name": "org.keepassxc.keepassxc_browser", "name": "org.keepassxc.keepassxc_browser",
"description": "KeePassXC integration with native messaging support", "description": "KeePassXC integration with native messaging support",
"path": "/snap/bin/keepassxc.proxy", "path": "${PROXY_PATH}",
"type": "stdio", "type": "stdio",
"allowed_extensions": [ "allowed_extensions": [
"keepassxc-browser@keepassxc.org" "keepassxc-browser@keepassxc.org"
@ -37,7 +48,7 @@ JSON_CHROME=$(cat << EOF
{ {
"name": "org.keepassxc.keepassxc_browser", "name": "org.keepassxc.keepassxc_browser",
"description": "KeePassXC integration with native messaging support", "description": "KeePassXC integration with native messaging support",
"path": "/snap/bin/keepassxc.proxy", "path": "${PROXY_PATH}",
"type": "stdio", "type": "stdio",
"allowed_origins": [ "allowed_origins": [
"chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/",
@ -47,21 +58,6 @@ JSON_CHROME=$(cat << EOF
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() { askBrowserSnap() {
if (whiptail --title "Snap Choice" --defaultno \ if (whiptail --title "Snap Choice" --defaultno \
--yesno "Is this browser installed as a snap (usually NO)?" 8 60); then --yesno "Is this browser installed as a snap (usually NO)?" 8 60); then
@ -73,33 +69,33 @@ askBrowserSnap() {
setupFirefox() { setupFirefox() {
askBrowserSnap "./snap/firefox/common" askBrowserSnap "./snap/firefox/common"
buildJson "firefox" JSON_OUT=${JSON_FIREFOX}
INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts" INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts"
} }
setupChrome() { setupChrome() {
buildJson JSON_OUT=${JSON_CHROME}
INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts" INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts"
} }
setupChromium() { setupChromium() {
askBrowserSnap "./snap/chromium/current" askBrowserSnap "./snap/chromium/current"
buildJson JSON_OUT=${JSON_CHROME}
INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts" INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts"
} }
setupVivaldi() { setupVivaldi() {
buildJson JSON_OUT=${JSON_CHROME}
INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts" INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts"
} }
setupBrave() { setupBrave() {
buildJson JSON_OUT=${JSON_CHROME}
INSTALL_DIR="${BASE_DIR}/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts" INSTALL_DIR="${BASE_DIR}/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts"
} }
setupTorBrowser() { setupTorBrowser() {
buildJson "firefox" JSON_OUT=${JSON_FIREFOX}
INSTALL_DIR="${BASE_DIR}/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts" 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" mkdir -p "$INSTALL_DIR"
echo "$JSON_OUT" > ${INSTALL_DIR}/${INSTALL_FILE} echo "$JSON_OUT" > ${INSTALL_DIR}/${INSTALL_FILE}
$DEBUG && echo "Installed to: ${INSTALL_DIR}/${INSTALL_FILE}"
whiptail \ whiptail \
--title "Installation Complete" \ --title "Installation Complete" \
--msgbox "You will need to restart your browser in order to connect to KeePassXC" \ --msgbox "You will need to restart your browser in order to connect to KeePassXC" \