-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
97 lines (75 loc) · 2.28 KB
/
install.sh
File metadata and controls
97 lines (75 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -e
SERVER_BASE="${SERVER_BASE}"
SERVER_API="${SERVER_API}"
SERVER_IDENTITY="${SERVER_IDENTITY}"
REQUIRED_PACKAGES="curl unzip sudo ca-certificates jq"
TARGET_PATH=/usr/local/bin/bws
error() {
echo "$1" >&2
echo "Exiting..." >&2
exit 1
}
apt_get_update()
{
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update
apt-get -y install --no-install-recommends "$@"
fi
}
platform_detect() {
if [ "$(uname -s)" = "Linux" ]; then
PLATFORM="unknown-linux-gnu"
elif [ "$(uname -s)" = "Darwin" ]; then
PLATFORM="apple-darwin"
else
error "Unsupported platform: $(uname -s)"
fi
}
arch_detect() {
if [ "$(uname -m)" = "x86_64" ]; then
ARCH="x86_64"
elif [ "$(uname -m)" = "aarch64" ]; then # Linux
ARCH="aarch64"
elif [ "$(uname -m)" = "arm64" ]; then # Darwin/macOS
ARCH="aarch64"
else
error "Unsupported architecture: $(uname -m)"
fi
}
export DEBIAN_FRONTEND=noninteractive
check_packages $REQUIRED_PACKAGES
CURRENT_TAG="$(curl --request GET https://api.github.com/repos/bitwarden/sdk-sm/releases?per_page=100 | jq --raw-output '[.[] | select(.draft == false) | select(.prerelease == false) | select(.tag_name | startswith("bws-")) | .tag_name][0]')"
CURRENT_VERSION="${CURRENT_TAG#bws-v}"
VERSION="${VERSION:-$CURRENT_VERSION}"
platform_detect
arch_detect
install() {
curl -L "https://github.com/bitwarden/sdk-sm/releases/download/bws-v${VERSION}/bws-${ARCH}-${PLATFORM}-${VERSION}.zip" -o bws.zip
unzip bws.zip
rm bws.zip
chmod a+x bws
mv bws $TARGET_PATH
}
configure() {
configCmd="sudo -u ${_REMOTE_USER} -i ${TARGET_PATH} config"
[ "${SERVER_BASE}" != "" ] && $configCmd server-base $SERVER_BASE
[ "${SERVER_API}" != "" ] && $configCmd server-api $SERVER_API
[ "${SERVER_IDENTITY}" != "" ] && $configCmd server-identity $SERVER_IDENTITY
return 0
}
echo "(*) Installing Bitwarden Secrets Manager CLI..."
install
if [ "${SERVER_BASE}" != "" ] || [ "${SERVER_API}" != "" ] || [ "${SERVER_IDENTITY}" != "" ]; then
echo "(*) Configure custom Bitwarden server URLs..."
configure
fi
# Clean up
rm -rf /var/lib/apt/lists/*
echo "Done!"