-
Notifications
You must be signed in to change notification settings - Fork 15
/
install.sh
executable file
·140 lines (121 loc) · 3.36 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#! /bin/sh
# based on https://tailscale.com/install.sh
# original copyright:
# Copyright (c) Tailscale Inc & AUTHORS
# SPDX-License-Identifier: BSD-3-Clause
set -eu
main() {
OS=
if type uname >/dev/null 2>&1; then
case "$(uname)" in
Darwin)
OS="darwin"
echo "macos is not supported yet, follow https://github.com/leptonai/gpud/blob/main/docs/INSTALL.md to build by yourself"
exit 1
;;
Linux)
OS="linux"
;;
*)
echo "OS $(uname) is not supported, follow https://github.com/leptonai/gpud/blob/main/docs/INSTALL.md to build by yourself"
exit 1
;;
esac
fi
ARCH=
if type uname >/dev/null 2>&1; then
case "$(uname -m)" in
x86_64)
ARCH="amd64"
;;
arm64|aarch64)
ARCH="arm64"
echo "arm64 is not supported yet, follow https://github.com/leptonai/gpud/blob/main/docs/INSTALL.md to build by yourself"
exit 1
;;
*)
echo "Processor $(uname -m) is not supported, follow https://github.com/leptonai/gpud/blob/main/docs/INSTALL.md to build by yourself"
exit 1
;;
esac
fi
CAN_ROOT=
SUDO=
if [ "$(id -u)" = 0 ]; then
CAN_ROOT=1
SUDO=""
elif type sudo >/dev/null; then
CAN_ROOT=1
SUDO="sudo"
elif type doas >/dev/null; then
CAN_ROOT=1
SUDO="doas"
fi
if [ "$CAN_ROOT" != "1" ]; then
echo "This installer needs to run commands as root."
echo "We tried looking for 'sudo' and 'doas', but couldn't find them."
echo "Either re-run this script as root, or set up sudo/doas."
exit 1
fi
TRACK="${TRACK:-unstable}"
VERSION=$(curl -fsSL https://pkg.gpud.dev/"$TRACK"_latest.txt)
if ! type lsb_release >/dev/null 2>&1; then
. /etc/os-release
OS_NAME=$(echo "$ID" | tr '[:upper:]' '[:lower:]')
OS_VERSION=$(echo "$VERSION" | tr -d '"')
else
# e.g., ubuntu20.04, ubuntu22.04, ubuntu24.04
OS_NAME=$(lsb_release -i -s | tr '[:upper:]' '[:lower:]' 2>/dev/null)
OS_VERSION=$(lsb_release -r -s 2>/dev/null || echo "")
fi
if [ "$OS_NAME" = "ubuntu" ]; then
case "$OS_VERSION" in
20.04|22.04|24.04)
OS_DISTRO="_${OS_NAME}${OS_VERSION}"
;;
*)
echo "Ubuntu version $OS_VERSION is not supported, only 20.04, 22.04, and 24.04 are supported."
exit 1
;;
esac
elif [ "$OS_NAME" = "amzn" ]; then
case "$OS_VERSION" in
2|2023)
OS_DISTRO="_${OS_NAME}${OS_VERSION}"
;;
*)
echo "Amazon Linux version $OS_VERSION is not supported, only version 2, 2023 is supported."
exit 1
;;
esac
else
OS_DISTRO=""
fi
FILEBASE=gpud_"$VERSION"_"$OS"_"$ARCH""$OS_DISTRO"
FILENAME=$FILEBASE.tgz
if [ -e "$FILENAME" ]; then
echo "file '$FILENAME' already exists"
exit 1
fi
DIR=/tmp/$FILEBASE
if [ -d "$DIR" ]; then
echo "temporal directory $DIR already exists"
exit 1
fi
mkdir "$DIR"
DLPATH=/tmp/"$FILENAME"
if ! curl -fsSL "https://pkg.gpud.dev/$FILENAME" -o "$DLPATH" 2>/tmp/gpud_curl_error.log; then
echo "failed to download file from 'https://pkg.gpud.dev/$FILENAME'"
echo "\nerror message:"
cat /tmp/gpud_curl_error.log
rm -f "$DLPATH" /tmp/gpud_curl_error.log
exit 1
fi
rm -f /tmp/gpud_curl_error.log
tar xzf "$DLPATH" -C "$DIR"
$SUDO cp -f "$DIR"/gpud /usr/sbin
echo "installed gpud version $VERSION"
rm /tmp/"$FILENAME"
rm -rf "$DIR"
}
main