-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
145 lines (119 loc) · 3.4 KB
/
Copy pathinstall.sh
File metadata and controls
145 lines (119 loc) · 3.4 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
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
141
142
143
144
145
#!/usr/bin/env sh
# Nothing nicer than a sexy install script to get you going.
# Use me babe: curl -fsSL https://raw.githubusercontent.com/degoog-org/cli/main/install.sh | sh
set -e
CMD_NAME="degoog-cli"
IMAGE="ghcr.io/degoog-org/cli:latest"
RELEASES="https://github.com/degoog-org/cli/releases/latest/download"
GREEN="\033[32m"
RESET="\033[0m"
ok() { printf "${GREEN}ok${RESET} %s\n" "$1"; }
die() { printf "error: %s\n" "$1" >&2; exit 1; }
check_path() {
DIR="$(dirname "$1")"
case ":$PATH:" in
*":$DIR:"*) ;;
*) printf "note: add %s to your PATH: export PATH=\"%s:\$PATH\"\n" "$DIR" "$DIR" ;;
esac
}
pick_install_dir() {
if [ -w "/usr/local/bin" ]; then
printf "/usr/local/bin"
elif command -v sudo > /dev/null 2>&1; then
printf "/usr/local/bin"
else
mkdir -p "$HOME/.local/bin"
printf "%s/.local/bin" "$HOME"
fi
}
install_to() {
INSTALL_DIR="$(pick_install_dir)"
if [ -w "$INSTALL_DIR" ]; then
mv "$1" "$INSTALL_DIR/$CMD_NAME"
chmod +x "$INSTALL_DIR/$CMD_NAME"
else
sudo mv "$1" "$INSTALL_DIR/$CMD_NAME"
sudo chmod +x "$INSTALL_DIR/$CMD_NAME"
fi
printf "%s" "$INSTALL_DIR/$CMD_NAME"
}
HAS_DOCKER=0
HAS_DOWNLOAD=0
command -v docker > /dev/null 2>&1 && HAS_DOCKER=1
{ command -v curl > /dev/null 2>&1 || command -v wget > /dev/null 2>&1; } && HAS_DOWNLOAD=1
exec 3</dev/tty 2>/dev/null || exec 3<&0
# Build the menu dynamically based on what's available
printf "\nHow do you want to install degoog-cli?\n\n"
OPTS=""
N=0
if [ "$HAS_DOCKER" = "1" ]; then
N=$((N+1)); printf " %s) Docker (recommended)\n" "$N"
OPTS="${OPTS}docker "
fi
if [ "$HAS_DOWNLOAD" = "1" ]; then
N=$((N+1)); printf " %s) Native binary\n" "$N"
OPTS="${OPTS}binary "
fi
if [ "$N" = "0" ]; then
die "Docker is not installed and no download tool found. Install Docker from https://docs.docker.com/get-docker/ and try again."
fi
printf "\n"
printf "Choice [1]: "
read -r CHOICE <&3 2>/dev/null || CHOICE=""
CHOICE="${CHOICE:-1}"
METHOD=$(echo "$OPTS" | cut -d' ' -f"$CHOICE")
if [ -z "$METHOD" ]; then
die "invalid choice"
fi
# Docker
if [ "$METHOD" = "docker" ]; then
printf "Pulling image...\n"
docker pull "$IMAGE"
TMP="$(mktemp)"
cat > "$TMP" <<EOF
#!/usr/bin/env sh
set -e
CONFIG_DIR="\$HOME/.config/degoog"
mkdir -p "\$CONFIG_DIR"
docker run --rm -it \\
-e DEGOOG_CONFIG_HOME=/degoog-config \\
-v "\$CONFIG_DIR:/degoog-config" \\
-v "\$(pwd):/workspace" \\
-w /workspace \\
$IMAGE "\$@"
EOF
INSTALLED="$(install_to "$TMP")"
ok "installed degoog-cli (Docker) to $INSTALLED"
check_path "$INSTALLED"
exit 0
fi
# Binary
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux)
case "$ARCH" in
x86_64) BINARY="degoog-cli-linux-x64" ;;
aarch64) BINARY="degoog-cli-linux-arm64" ;;
*) die "unsupported architecture: $ARCH" ;;
esac
;;
darwin)
case "$ARCH" in
x86_64) BINARY="degoog-cli-darwin-x64" ;;
arm64) BINARY="degoog-cli-darwin-arm64" ;;
*) die "unsupported architecture: $ARCH" ;;
esac
;;
*) die "unsupported OS: $OS - install Docker instead: https://docs.docker.com/get-docker/" ;;
esac
TMP="$(mktemp)"
printf "Downloading %s...\n" "$BINARY"
if command -v curl > /dev/null 2>&1; then
curl -fsSL "$RELEASES/$BINARY" -o "$TMP"
else
wget -qO "$TMP" "$RELEASES/$BINARY"
fi
INSTALLED="$(install_to "$TMP")"
ok "installed degoog-cli (binary) to $INSTALLED"
check_path "$INSTALLED"