keepassxc-snap-helper.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. ]
  51. }
  52. EOF
  53. )
  54. askBrowserSnap() {
  55. if (whiptail --title "Snap Choice" --defaultno \
  56. --yesno "Is this browser installed as a snap (usually NO)?" 8 60); then
  57. # BASE_DIR="$1"
  58. whiptail --title "Snap Choice" --msgbox "Sorry, browsers installed as snaps are not supported at this time" 8 50
  59. exit 0
  60. fi
  61. }
  62. setupFirefox() {
  63. askBrowserSnap "./snap/firefox/common"
  64. JSON_OUT=${JSON_FIREFOX}
  65. INSTALL_DIR="${BASE_DIR}/.mozilla/native-messaging-hosts"
  66. }
  67. setupChrome() {
  68. JSON_OUT=${JSON_CHROME}
  69. INSTALL_DIR="${BASE_DIR}/.config/google-chrome/NativeMessagingHosts"
  70. }
  71. setupChromium() {
  72. askBrowserSnap "./snap/chromium/current"
  73. JSON_OUT=${JSON_CHROME}
  74. INSTALL_DIR="${BASE_DIR}/.config/chromium/NativeMessagingHosts"
  75. }
  76. setupVivaldi() {
  77. JSON_OUT=${JSON_CHROME}
  78. INSTALL_DIR="${BASE_DIR}/.config/vivaldi/NativeMessagingHosts"
  79. }
  80. setupBrave() {
  81. JSON_OUT=${JSON_CHROME}
  82. INSTALL_DIR="${BASE_DIR}/.config/BraveSoftware/Brave-Browser/NativeMessagingHosts"
  83. }
  84. setupTorBrowser() {
  85. JSON_OUT=${JSON_FIREFOX}
  86. INSTALL_DIR="${BASE_DIR}/.tor-browser/app/Browser/TorBrowser/Data/Browser/.mozilla/native-messaging-hosts"
  87. }
  88. # --------------------------------
  89. # Start of script
  90. # --------------------------------
  91. BROWSER=$(whiptail \
  92. --title "Browser Selection" \
  93. --menu "Choose a browser to integrate with KeePassXC:" \
  94. 15 60 5 \
  95. "1" "Firefox" \
  96. "2" "Chrome" \
  97. "3" "Chromium" \
  98. "4" "Vivaldi" \
  99. "5" "Brave" \
  100. "6" "Tor Browser" \
  101. 3>&1 1>&2 2>&3)
  102. clear
  103. exitstatus=$?
  104. if [ $exitstatus = 0 ]; then
  105. # Configure settings for the chosen browser
  106. case "$BROWSER" in
  107. 1) setupFirefox ;;
  108. 2) setupChrome ;;
  109. 3) setupChromium ;;
  110. 4) setupVivaldi ;;
  111. 5) setupBrave ;;
  112. 6) setupTorBrowser ;;
  113. esac
  114. # Install the JSON file
  115. cd ~
  116. mkdir -p "$INSTALL_DIR"
  117. echo "$JSON_OUT" > ${INSTALL_DIR}/${INSTALL_FILE}
  118. whiptail \
  119. --title "Installation Complete" \
  120. --msgbox "You will need to restart your browser in order to connect to KeePassXC" \
  121. 8 50
  122. else
  123. whiptail --title "Installation Canceled" --msgbox "No changes were made to your system" 8 50
  124. fi