The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ubuntu_disconnect_bubble 5.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
  4. #
  5. # Disconnect an Ubuntu 20.04 system from a Bubble
  6. # You must run this as a user who has "sudo" privileges
  7. #
  8. # Usage:
  9. #
  10. # ubuntu_disconnect_bubble [delete]
  11. #
  12. # delete : Delete all local files, including any installed certificate
  13. #
  14. # If delete is not specified, then the VPN is simply turned off.
  15. #
  16. # If delete is specified, then the VPN is turned off and then:
  17. # - VPN config file is removed
  18. # - Bubble certificate is removed and certificate wizard is re-run
  19. # - Local files in ~/bubble_devices are removed
  20. #
  21. # Environment Variables - these are only used when 'delete' is specified
  22. #
  23. # BUBBLE_USER : account to use
  24. # BUBBLE_PASS : password for account
  25. #
  26. #
  27. function die() {
  28. echo 1>&2 "$0: fatal error: ${1}"
  29. exit 1
  30. }
  31. SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
  32. DO_DELETE=0
  33. if [[ -n "${1}" ]] ; then
  34. if [[ "${1}" == "delete" ]] ; then
  35. DO_DELETE=1
  36. else
  37. die "Invalid argument: ${1} (expected 'delete' or nothing)"
  38. fi
  39. fi
  40. if [[ -z "$(which wg)" ]] ; then
  41. die "No wg command found - is WireGuard installed?"
  42. fi
  43. if [[ -z "$(which wg-quick)" ]] ; then
  44. die "No wg-quick command found - is WireGuard installed?"
  45. fi
  46. # Ensure WireGuard is not running
  47. if [[ -n "$(sudo wg show)" ]] ; then
  48. echo "Stopping WireGuard VPN ..."
  49. sudo wg-quick down wg0
  50. else
  51. echo "VPN not running"
  52. fi
  53. if [[ ${DO_DELETE} -eq 0 ]] ; then
  54. echo "
  55. ====================================================================
  56. ======= Ubuntu system successfully disconnected from Bubble! =======
  57. ====================================================================
  58. Public IP : $(curl -s http://checkip.amazonaws.com/)
  59. "
  60. exit 0
  61. fi
  62. if [[ -z "$(which bget)" ]] ; then
  63. export PATH=${PATH}:${SCRIPT_DIR}
  64. if [[ -z "$(which bget)" ]] ; then
  65. die "bget command not found, even after adding ${SCRIPT_DIR} to PATH"
  66. fi
  67. fi
  68. BUBBLE_DEVICE_BASE="${HOME}/bubble_devices"
  69. DEVICE_JSON_FILE="${BUBBLE_DEVICE_BASE}/current/device.json"
  70. if [[ ! -f "${DEVICE_JSON_FILE}" ]] ; then
  71. die "No ${DEVICE_JSON_FILE} file found"
  72. fi
  73. CURRENT_DEVICE_DIR="${BUBBLE_DEVICE_BASE}/current"
  74. CURRENT_DEVICE_JSON="$(cat "${CURRENT_DEVICE_DIR}/device.json")"
  75. if [[ -z "${CURRENT_DEVICE_JSON}" ]] ; then
  76. die "File was empty: ${CURRENT_DEVICE_JSON}"
  77. fi
  78. BUBBLE_HOST="$(basename "$(readlink -f "${CURRENT_DEVICE_DIR}")")"
  79. BUBBLE_DIR="${BUBBLE_DEVICE_BASE}/${BUBBLE_HOST}"
  80. CERT_FILE="${BUBBLE_DIR}"/bubble-${BUBBLE_HOST}.crt
  81. CERTS_DIR=/usr/share/ca-certificates/extra
  82. CERT_DEST="${CERTS_DIR}/$(basename "${CERT_FILE}")"
  83. if [[ -f "${CERT_DEST}" ]] ; then
  84. echo "Removing certificate: ${CERT_DEST} ..."
  85. sudo rm -f "${CERT_DEST}"
  86. else
  87. echo "Certificate not installed, not removing: ${CERT_DEST}"
  88. fi
  89. echo "
  90. ### Finishing Certificate Uninstallation for Ubuntu
  91. We're going to run the Ubuntu certificate wizard via:
  92. sudo dpkg-reconfigure ca-certificates
  93. When the wizard opens:
  94. - Press Enter with 'Yes' selected for 'Trust new certificates from certificate authorities?'
  95. - Press Enter to commit the changes
  96. To continue and run the Ubuntu certificate wizard, press Enter now
  97. "
  98. read -r DUMMY
  99. sudo dpkg-reconfigure ca-certificates || die "Error reconfiguring system CA certificates"
  100. WG_CONF=/etc/wireguard/wg0.conf
  101. echo "Removing WireGuard config: ${WG_CONF} ..."
  102. sudo rm -f ${WG_CONF} || die "Error removing ${WG_CONF}"
  103. DEVICE_NAME="$(echo "${CURRENT_DEVICE_JSON}" | jq -r .name)"
  104. if [[ -z "${DEVICE_NAME}" ]] ; then
  105. die "No device name could be read from JSON: ${CURRENT_DEVICE_JSON}"
  106. fi
  107. DEVICE_UUID="$(echo "${CURRENT_DEVICE_JSON}" | jq -r .uuid)"
  108. if [[ -z "${DEVICE_UUID}" ]] ; then
  109. die "No device UUID could be read from JSON: ${CURRENT_DEVICE_JSON}"
  110. fi
  111. if [[ -z "${BUBBLE_USER}" ]] ; then
  112. echo -n "BUBBLE_USER env var not defined.
  113. Enter Bubble username: "
  114. read -r BUBBLE_USER
  115. echo
  116. fi
  117. if [[ -z "${BUBBLE_PASS}" ]] ; then
  118. echo -n "BUBBLE_PASS env var not defined.
  119. Enter Bubble password: "
  120. read -rs BUBBLE_PASS
  121. echo
  122. fi
  123. BUBBLE_API="https://${BUBBLE_HOST}/api"
  124. echo "Logging in to Bubble ${BUBBLE_API} ..."
  125. export BUBBLE_API
  126. export BUBBLE_USER
  127. export BUBBLE_PASS
  128. export BUBBLE_SKIP_PATH_WARNING=true
  129. bget me | jq .email > /dev/null || die "Error logging into Bubble with API: ${BUBBLE_API}"
  130. echo "Deleting device: ${DEVICE_NAME}"
  131. bdelete "me/devices/${DEVICE_UUID}" || die "Error deleting device: ${DEVICE_NAME} (uuid ${DEVICE_UUID})"
  132. if [[ -d "${BUBBLE_DIR}" ]] ; then
  133. echo "Removing directory: ${BUBBLE_DIR}"
  134. rm -rf "${BUBBLE_DIR}" || die "Error removing ${BUBBLE_DIR}"
  135. fi
  136. echo "Removing symlink: ${BUBBLE_DEVICE_BASE}/current"
  137. rm -f "${BUBBLE_DEVICE_BASE}/current" || die "Error removing ${BUBBLE_DEVICE_BASE}/current"
  138. echo "
  139. ===============================================================
  140. ======= Ubuntu system successfully DELETED from Bubble! =======
  141. ===============================================================
  142. Device Name : ${DEVICE_NAME}
  143. Bubble Host : ${BUBBLE_HOST}
  144. Public IP : $(curl -s http://checkip.amazonaws.com/)
  145. "
  146. if [[ -n "$(which firefox)" ]] ; then
  147. echo "
  148. ===========================================================
  149. ===================== Firefox Warning =====================
  150. ===========================================================
  151. Firefox does not use the Ubuntu certificate store. It has its
  152. own certificate store.
  153. If you installed the Bubble certificate in Firefox, now would
  154. be the time to remove it from Firefox.
  155. "
  156. fi