Преглед на файлове

install wireguard if needed

tags/v1.4.28
Jonathan Cobb преди 4 години
родител
ревизия
bb46877833
променени са 2 файла, в които са добавени 29 реда и са изтрити 28 реда
  1. +14
    -13
      bin/ubuntu_connect_bubble
  2. +15
    -15
      bin/ubuntu_disconnect_bubble

+ 14
- 13
bin/ubuntu_connect_bubble Целия файл

@@ -2,7 +2,7 @@
#
# Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
#
# Connect an Ubuntu system to a Bubble
# Connect an Ubuntu 20.04 system to a Bubble
# You must run this as a user who has "sudo" privileges
#
# Usage:
@@ -42,16 +42,17 @@ function uriencode { jq -nr --arg v "$1" '$v|@uri'; }

SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"

if [[ -z "$(which wg)" ]]; then
die "No wg command found - is WireGuard installed?"
if [[ -z "$(which wg)" ]] ; then
echo "Installing WireGuard ..."
sudo apt install -y wireguard || die "Error installing WireGuard"
fi
if [[ -z "$(which wg-quick)" ]]; then
if [[ -z "$(which wg-quick)" ]] ; then
die "No wg-quick command found - is WireGuard installed?"
fi

if [[ -z "$(which bget)" ]]; then
if [[ -z "$(which bget)" ]] ; then
export PATH=${PATH}:${SCRIPT_DIR}
if [[ -z "$(which bget)" ]]; then
if [[ -z "$(which bget)" ]] ; then
die "bget command not found, even after adding ${SCRIPT_DIR} to PATH"
fi
fi
@@ -76,13 +77,13 @@ else
BUBBLE_API="https://${ARG_HOST}/api"
fi

if [[ -z "${BUBBLE_USER}" ]]; then
if [[ -z "${BUBBLE_USER}" ]] ; then
echo -n "BUBBLE_USER env var not defined.
Enter Bubble username: "
read -r BUBBLE_USER
echo
fi
if [[ -z "${BUBBLE_PASS}" ]]; then
if [[ -z "${BUBBLE_PASS}" ]] ; then
echo -n "BUBBLE_PASS env var not defined.
Enter Bubble password: "
read -rs BUBBLE_PASS
@@ -90,7 +91,7 @@ Enter Bubble password: "
fi

BUBBLE_HOST="$(echo -n "${BUBBLE_API}" | awk -F '/' '{print $3}' | awk -F ':' '{print $1}')"
if [[ -z "${BUBBLE_HOST}" ]]; then
if [[ -z "${BUBBLE_HOST}" ]] ; then
die "No hostname could be determined from BUBBLE_API: ${BUBBLE_API}"
fi

@@ -115,7 +116,7 @@ CERT_FILE="${BUBBLE_DIR}"/bubble-${BUBBLE_HOST}.crt
VPN_FILE="${BUBBLE_DIR}"/vpn.conf

DEVICE_NAME_FILE=${BUBBLE_DIR}/bubble_device_name
if [[ ! -f "${DEVICE_NAME_FILE}" ]]; then
if [[ ! -f "${DEVICE_NAME_FILE}" ]] ; then
DISTRO="$(cat /etc/os-release | grep ^NAME= | awk -F '=' '{print $2}' | tr -d '"')"
echo -n "Linux_${DISTRO}_$(hostname -s)" >"${DEVICE_NAME_FILE}"
echo "Initialized device: ${DEVICE_NAME_FILE}"
@@ -123,7 +124,7 @@ fi
DEVICE_NAME="$(cat "${DEVICE_NAME_FILE}")"

# Check API to see if device is already registered
if [[ $(bgetn me/devices | grep -c "${DEVICE_NAME}") -eq 0 ]]; then
if [[ $(bgetn me/devices | grep -c "${DEVICE_NAME}") -eq 0 ]] ; then
echo "Device not found, registering now: ${DEVICE_NAME}"
echo "{
\"name\": \"${DEVICE_NAME}\",
@@ -139,12 +140,12 @@ else
fi

# Do we have both a cert file and a vpn.conf? If so, we are done
if [[ ! -s "${CERT_FILE}" ]]; then
if [[ ! -s "${CERT_FILE}" ]] ; then
# Download cert file
echo "Downloading certificate ..."
bget auth/cacert?deviceType=Linux --raw >"${CERT_FILE}" || die "Error downloading certificate file"
fi
if [[ ! -s "${VPN_FILE}" ]]; then
if [[ ! -s "${VPN_FILE}" ]] ; then
# Download vpn.conf file
echo "Downloading vpn.conf ..."
bget "me/devices/${DEVICE_NAME}/vpn/vpn.conf" --raw >"${VPN_FILE}" || die "Error downloading vpn.conf file"


+ 15
- 15
bin/ubuntu_disconnect_bubble Целия файл

@@ -2,7 +2,7 @@
#
# Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
#
# Disconnect an Ubuntu system from a Bubble
# Disconnect an Ubuntu 20.04 system from a Bubble
# You must run this as a user who has "sudo" privileges
#
# Usage:
@@ -31,43 +31,43 @@ function die() {

SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
DO_DELETE=0
if [[ ! -z "${1}" ]]; then
if [[ "${1}" == "delete" ]]; then
if [[ ! -z "${1}" ]] ; then
if [[ "${1}" == "delete" ]] ; then
DO_DELETE=1
else
die "Invalid argument: ${1} (expected 'delete' or nothing)"
fi
fi

if [[ -z "$(which wg)" ]]; then
if [[ -z "$(which wg)" ]] ; then
die "No wg command found - is WireGuard installed?"
fi
if [[ -z "$(which wg-quick)" ]]; then
if [[ -z "$(which wg-quick)" ]] ; then
die "No wg-quick command found - is WireGuard installed?"
fi

# Ensure WireGuard is not running
if [[ ! -z "$(sudo wg show)" ]]; then
if [[ ! -z "$(sudo wg show)" ]] ; then
echo "Stopping WireGuard VPN ..."
sudo wg-quick down wg0
else
echo "VPN not running"
fi

if [[ ${DO_DELETE} -eq 0 ]]; then
if [[ ${DO_DELETE} -eq 0 ]] ; then
exit 0
fi

if [[ -z "$(which bget)" ]]; then
if [[ -z "$(which bget)" ]] ; then
export PATH=${PATH}:${SCRIPT_DIR}
if [[ -z "$(which bget)" ]]; then
if [[ -z "$(which bget)" ]] ; then
die "bget command not found, even after adding ${SCRIPT_DIR} to PATH"
fi
fi

BUBBLE_DEVICE_BASE="${HOME}/bubble_devices"
DEVICE_JSON_FILE="${BUBBLE_DEVICE_BASE}/current/device.json"
if [[ ! -f "${DEVICE_JSON_FILE}" ]]; then
if [[ ! -f "${DEVICE_JSON_FILE}" ]] ; then
die "No ${DEVICE_JSON_FILE} file found"
fi
CURRENT_DEVICE_DIR="${BUBBLE_DEVICE_BASE}/current"
@@ -81,7 +81,7 @@ CERT_FILE="${BUBBLE_DIR}"/bubble-${BUBBLE_HOST}.crt

CERTS_DIR=/usr/share/ca-certificates/extra
CERT_DEST="${CERTS_DIR}/$(basename "${CERT_FILE}")"
if [[ -f "${CERT_DEST}" ]]; then
if [[ -f "${CERT_DEST}" ]] ; then
echo "Removing certificate: ${CERT_DEST} ..."
sudo rm -f "${CERT_DEST}"
else
@@ -116,13 +116,13 @@ DEVICE_UUID="$(echo "${CURRENT_DEVICE_JSON}" | jq -r .uuid)"
if [[ -z "${DEVICE_UUID}" ]] ; then
die "No device UUID could be read from JSON: ${CURRENT_DEVICE_JSON}"
fi
if [[ -z "${BUBBLE_USER}" ]]; then
if [[ -z "${BUBBLE_USER}" ]] ; then
echo -n "BUBBLE_USER env var not defined.
Enter Bubble username: "
read -r BUBBLE_USER
echo
fi
if [[ -z "${BUBBLE_PASS}" ]]; then
if [[ -z "${BUBBLE_PASS}" ]] ; then
echo -n "BUBBLE_PASS env var not defined.
Enter Bubble password: "
read -rs BUBBLE_PASS
@@ -140,7 +140,7 @@ bget me | jq .email > /dev/null || die "Error logging into Bubble with API: ${BU
echo "Deleting device: ${DEVICE_NAME}"
bdelete "me/devices/${DEVICE_UUID}" || die "Error deleting device: ${DEVICE_NAME} (uuid ${DEVICE_UUID})"

if [[ -d "${BUBBLE_DIR}" ]]; then
if [[ -d "${BUBBLE_DIR}" ]] ; then
echo "Removing directory: ${BUBBLE_DIR}"
rm -rf "${BUBBLE_DIR}" || die "Error removing ${BUBBLE_DIR}"
fi
@@ -155,7 +155,7 @@ Device Name : ${DEVICE_NAME}
Bubble Host : ${BUBBLE_HOST}
"

if [[ ! -z "$(which firefox)" ]]; then
if [[ ! -z "$(which firefox)" ]] ; then
echo "
===========================================================
===================== Firefox Warning =====================


Зареждане…
Отказ
Запис