-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.sh
executable file
·65 lines (54 loc) · 1.1 KB
/
lib.sh
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
#!/bin/bash
set -eo pipefail
function install_bin() {
BIN=$1
URL=$2
echo "Installing binary '$BIN'..."
echo "Getting release from '$URL'..."
curl -sSLo $BIN $URL
chmod +x $BIN
mv $BIN /usr/local/bin/$BIN
}
function install_tar() {
BIN=$1
URL=$2
TAR_DIR=$3
echo "Installing binary '$BIN' from tar.gz..."
echo "Getting release from '$URL'..."
curl -sSLo $BIN $URL
mkdir -p /tmp/$BIN
tar -C /tmp/$BIN -zxvf $BIN > /dev/null 2>&1
BIN_PATH=/tmp/$BIN/$BIN
if [ ! -z $TAR_DIR ]; then
BIN_PATH=/tmp/$BIN/$TAR_DIR/$BIN
fi
chmod +x $BIN_PATH
mv $BIN_PATH /usr/local/bin/$BIN
rm -rf $BIN_PATH $BIN
}
function get_user_home() {
USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
echo $USER_HOME
}
function get_username() {
if [ -n "$SUDO_USER" ]; then
echo "$SUDO_USER"
else
echo "$(whoami)"
fi
}
function get_architecture() {
ARCH=$(uname -m)
if [ $ARCH = "x86_64" ]; then
echo "amd64"
elif [ $ARCH = "aarch64" ]; then
echo "arm64"
elif [[ $ARCH = "arm" ]]; then
echo "arm"
else
echo ""
fi
}
function log() {
echo "🧰 $1"
}