keepassxc-snap-helper.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env bash
  2. #
  3. # KeePassXC Browser Extension Native Messaging Installer Tool
  4. # Copyright (C) 2017 KeePassXC team <https://keepassxc.org/>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 or (at your option)
  9. # version 3 of the License.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. set -e
  19. JSON_OUT=""
  20. BASE_DIR="."
  21. INSTALL_DIR=""
  22. INSTALL_FILE="org.keepassxc.keepassxc_browser.json"
  23. # Early out if the keepassxc.proxy executable cannot be found
  24. if ! command -v keepassxc.proxy; then
  25. echo "Could not find keepassxc.proxy! Ensure the keepassxc snap is installed properly."
  26. exit 0
  27. fi
  28. PROXY_PATH=$(command -v keepassxc.proxy)
  29. JSON_FIREFOX=$(cat << EOF
  30. {
  31. "name": "org.keepassxc.keepassxc_browser",
  32. "description": "KeePassXC integration with native messaging support",
  33. "path": "${PROXY_PATH}",
  34. "type": "stdio",
  35. "allowed_extensions": [
  36. "keepassxc-browser@keepassxc.org"
  37. ]
  38. }
  39. EOF
  40. )
  41. JSON_CHROME=$(cat << EOF
  42. {
  43. "name": "org.keepassxc.keepassxc_browser",
  44. "description": "KeePassXC integration with native messaging support",
  45. "path": "${PROXY_PATH}",
  46. "type": "stdio",
  47. "allowed_origins": [
  48. "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/",
  49. "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/",
  50. "chrome-extension://pdffhmdngciaglkoonimfcmckehcpafo/"
  51. ]
  52. }
  53. EOF
  54. )
  55. setupFirefox() {
  56. JSON_OUT=${JSON_FIREFOX}
  57. INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts"
  58. }
  59. setupChrome() {
  60. JSON_OUT=${JSON_CHROME}
  61. INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts"
  62. }
  63. setupChromium() {
  64. JSON_OUT=${JSON_CHROME}
  65. INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts"
  66. }
  67. setupVivaldi() {
  68. JSON_OUT=${JSON_CHROME}
  69. INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts"
  70. }
  71. setupBrave() {
  72. JSON_OUT=${JSON_CHROME}
  73. INSTALL_DIR="${BASE_DIR}/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts"
  74. }
  75. setupTorBrowser() {
  76. JSON_OUT=${JSON_FIREFOX}
  77. INSTALL_DIR="${BASE_DIR}/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts"
  78. }
  79. setupEdge() {
  80. JSON_OUT=${JSON_CHROME}
  81. INSTALL_DIR="${BASE_DIR}/.config/microsoft-edge/NativeMessagingHosts"
  82. }
  83. # --------------------------------
  84. # Start of script
  85. # --------------------------------
  86. BROWSER=$(whiptail \
  87. --title "Browser Selection" \
  88. --menu "Choose a browser to integrate with KeePassXC:" \
  89. 15 60 5 \
  90. "1" "Firefox" \
  91. "2" "Chrome" \
  92. "3" "Chromium" \
  93. "4" "Vivaldi" \
  94. "5" "Brave" \
  95. "6" "Tor Browser" \
  96. "7" "Microsoft Edge" \
  97. 3>&1 1>&2 2>&3)
  98. exitstatus=$?
  99. clear
  100. if [[ $exitstatus == 0 ]]; then
  101. # Configure settings for the chosen browser
  102. case $BROWSER in
  103. 1) setupFirefox ;;
  104. 2) setupChrome ;;
  105. 3) setupChromium ;;
  106. 4) setupVivaldi ;;
  107. 5) setupBrave ;;
  108. 6) setupTorBrowser ;;
  109. 7) setupEdge ;;
  110. esac
  111. # Install the JSON file
  112. cd ~
  113. mkdir -p "$INSTALL_DIR"
  114. echo "$JSON_OUT" > "${INSTALL_DIR}/${INSTALL_FILE}"
  115. whiptail \
  116. --title "Installation Complete" \
  117. --msgbox "You will need to restart your browser in order to connect to KeePassXC" \
  118. 8 50
  119. else
  120. whiptail --title "Installation Canceled" --msgbox "No changes were made to your system" 8 50
  121. fi