-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
86 lines (69 loc) · 1.74 KB
/
install.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
set -u
PROGRAM_NAME=obsidian-garden
BASE_URL=https://github.com/ecarrara/obsidian-garden/releases/latest/download
message () {
case $1 in
error) tput setaf 1 2>/dev/null ;;
success) tput setaf 2 2>/dev/null ;;
warning) tput setaf 3 2>/dev/null ;;
info) tput setaf 4 2>/dev/null ;;
esac
echo $2
tput sgr0 2>/dev/null
}
exists () {
command -v "$1" 1>/dev/null 2>&1
}
download () {
url="$1"
destination="$2"
sudo="${3-}"
if exists curl; then
cmd="curl --silent --fail --location --output $destination $url"
elif exists wget; then
cmd="wget --quiet --output-document $destination $url"
else
message error "Unable to found curl or wget, exiting..."
return 2
fi
message info "Downloading $url to $destination"
$sudo $cmd
if [[ "$?" -ne 0 ]]; then
message error "Download failed."
message warning "Only Linux x86_64 and MacOS are supported."
exit -1
fi
}
detect_platform () {
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$platform" in
linux) platform="unknown-linux-musl" ;;
darwin) platform="apple-darwin" ;;
esac
echo -n "$platform"
}
detect_arch () {
arch=$(uname -m | tr '[:upper:]' '[:lower:]')
case "$arch" in
amd64) arch="x86_64" ;;
arm64) arch="aarch64" ;;
esac
echo -n "$arch"
}
PLATFORM=$(detect_platform)
ARCH=$(detect_arch)
if [ -z "${INSTALL_DIR-}" ]; then
INSTALL_DIR=/usr/local/bin
fi
URL=${BASE_URL}/${PROGRAM_NAME}-${ARCH}-${PLATFORM}
TARGET=${INSTALL_DIR}/${PROGRAM_NAME}
if [ -w "$INSTALL_DIR" ]; then
download $URL $TARGET
chmod +x $TARGET
else
message warning "$INSTALL_DIR is not writable, sudo is required."
download $URL $TARGET sudo
sudo chmod +x $TARGET
fi
message success "$PROGRAM_NAME installed."