Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(cli): add bb install script (#1160)

qsliu8b95167a3f4c
diff --git a/.github/workflows/install-bb.yml b/.github/workflows/install-bb.yml
new file mode 100644
index 0000000000..aa2ef05f4d
--- /dev/null
+++ b/.github/workflows/install-bb.yml
@@ -0,0 +1,21 @@
+# This workflow tests if scripts/install_bb.sh is working correctly.
+name: install bb
+
+on:
+ push:
+ branches:
+ - "main"
+ pull_request:
+
+jobs:
+ install:
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest]
+ runs-on: ${{matrix.os}}
+ steps:
+ - uses: actions/checkout@v2
+ - name: run install script
+ run: ./scripts/install_bb.sh
+ - name: check bb version
+ run: bb version
diff --git a/scripts/install_bb.sh b/scripts/install_bb.sh
new file mode 100755
index 0000000000..95f8612a58
--- /dev/null
+++ b/scripts/install_bb.sh
@@ -0,0 +1,69 @@
+#! /bin/sh
+set -u
+
+abort() {
+ printf "%s\n" "$@" >&2
+ exit 1
+}
+
+uname_os() {
+ OS="$(uname -s)"
+ if [[ "${OS}" != "Darwin" && "${OS}" != "Linux" ]]; then
+ abort "OS ${OS} is not support, bb is only supported on Linux and MacOS"
+ fi
+ echo $OS
+}
+
+uname_arch() {
+ ARCH=$(uname -m)
+ if [[ "${ARCH}" == "amd64" || "${ARCH}" == "x86_64" ]]; then
+ ARCH="x86_64"
+ elif [[ "${ARCH}" != "arm64" ]]; then
+ abort "Arch ${ARCH} is not support, bb is only supported on x86_64, amd64 and arm64"
+ fi
+ echo $ARCH
+}
+
+http_download() {
+ local_file=$1
+ source_url=$2
+
+ echo "Start downloading $source_url..."
+
+ code=$(curl -w '%{http_code}' -sL -o "$local_file" "$source_url")
+ if [ "$code" != "200" ]; then
+ abort "Failed to download $source_url, status code: $code"
+ fi
+
+ echo "Completed downloading $source_url"
+ return 0
+}
+
+execute() {
+ BB_VERSION="1.0.3"
+ OS="$(uname_os)"
+ ARCH="$(uname_arch)"
+
+ tmpdir=$(mktemp -d)
+ echo "Downloading tarball into ${tmpdir}"
+
+ http_download "${tmpdir}/bytebase_${BB_VERSION}_${OS}_${ARCH}.tar.gz" \
+ "https://github.com/bytebase/bytebase/releases/download/${BB_VERSION}/bytebase_${BB_VERSION}_${OS}_${ARCH}.tar.gz"
+
+ echo "Start extracting tarball..."
+ (cd "${tmpdir}" && tar -xf "bytebase_${BB_VERSION}_${OS}_${ARCH}.tar.gz" "bb")
+ echo "Completed extracting tarball"
+
+ echo "Start installing bb..."
+ install "${tmpdir}/bb" "/usr/local/bin"
+ echo "Installed bb to /usr/local/bin"
+
+ echo ""
+ echo "Check the usage with"
+ echo " bb --help"
+ echo ""
+ echo "You can clean up the installation files with"
+ echo " rm -rf ${tmpdir}"
+}
+
+execute