-
Notifications
You must be signed in to change notification settings - Fork 31
/
install.sh
executable file
·189 lines (144 loc) · 4.22 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env sh
# This script attempts to install sq via apt, yum, apk, or brew.
# Parts of the script are inspired by the get-docker.sh
# script at https://get.docker.com
get_distribution() {
lsb_dist=""
# Every Linux system that we officially support has /etc/os-release
if [ -r /etc/os-release ]; then
# shellcheck disable=SC1091
lsb_dist="$(. /etc/os-release && echo "$ID")"
fi
# Returning an empty string here should be alright since the
# case statements don't act unless you provide an actual value
echo "$lsb_dist"
}
# Use command exists to test if a command is present on the system. E.g.
#
# if command_exists lsb_release; then
command_exists() {
command -v "$@" > /dev/null 2>&1
}
get_distribution
# Void Linux / xbps
if command_exists xbps-install; then
set -e
printf "Using xbps-install to install sq...\n\n"
(xbps-install -Syu || true) && xbps-install -yu xbps
xbps-install -yu sq
exit
fi
# apt / deb
if [ -r /etc/debian_version ] && command_exists apt; then
set -e
printf "Using apt to install sq...\n\n"
apt update -y && apt install -y --no-upgrade curl gpg
curl -fsSL https://apt.fury.io/neilotoole/gpg.key | gpg --dearmor -o /usr/share/keyrings/sq.gpg
echo "deb [signed-by=/usr/share/keyrings/sq.gpg] https://apt.fury.io/neilotoole/ * *" > /etc/apt/sources.list.d/sq.list
cat <<EOF > /etc/apt/preferences.d/sq
Package: sq
Pin: origin apt.fury.io
Pin-Priority: 501
EOF
apt update -y && apt install -y sq
printf "\n"
sq version
printf "\n"
exit
fi
# Yum / rpm
if command_exists yum; then
set -e
set +x
printf "Using yum to install sq...\n\n"
cat <<EOF > /etc/yum.repos.d/sq.repo
[sq]
name=sq
baseurl=https://yum.fury.io/neilotoole/
enabled=1
gpgcheck=0
gpgkey=https://apt.fury.io/neilotoole/gpg.key
EOF
yum install -y sq
printf "\n"
sq version
printf "\n"
exit
fi
# apk / alpine
if command_exists apk; then
set -e
printf "Using apk to install sq...\n\n"
apk update
# sq isn't published to an Alpine repo yet, so we download the
# file from GitHub, and execute "apk add" with the local apk file.
# e.g. "v1.0.0"
semver=$(wget -qO- "https://api.github.com/repos/neilotoole/sq/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# e.g. "1.0.0"
ver=$(echo "$semver" | sed -e "s/^v//")
# Should be "x86_64" for amd64, and "aarch64" for arm64
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
arch="amd64"
elif [ "$arch" = "aarch64" ]; then
arch="arm64"
else
printf "sq install package not available for architecture: %s\n" "$arch"
exit 1
fi
# e.g. "sq_0.18.1_linux_arm64.apk"
file_name=$(printf "sq_%s_linux_%s.apk" "$ver" $arch)
file_path="/tmp/$file_name"
# https://github.com/neilotoole/sq/releases/download/v0.18.1/sq_0.18.1_linux_amd64.apk
# https://github.com/neilotoole/sq/releases/download/v0.18.1/sq_0.18.1_linux_arm64.apk
download_url=$(printf "https://github.com/neilotoole/sq/releases/download/%s/%s" "$semver" "$file_name")
echo "Downloading apk from: $download_url"
wget "$download_url" -O "$file_path"
apk add --allow-untrusted "$file_path"
rm "$file_path"
printf "\n"
sq version
printf "\n"
exit
fi
# Arch Linux
if command_exists pacman; then
if [ "$(id -u)" -eq 0 ]; then
echo "AUR packages shouldn't be installed as root"
exit 1
fi
# First check if there's an AUR helper available instead
# of downloading and using pacman
if command_exists yay; then
echo "Installing via yay..."
yay -S --noconfirm sq-bin
exit
fi
if command_exists paru; then
echo "Installing via paru..."
paru -S --noconfirm sq-bin
exit
fi
# Fall back to pacman
echo "Installing via pacman..."
cd /tmp
curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/sq-bin.tar.gz
tar -xf sq-bin.tar.gz
cd sq-bin
makepkg -sri --noconfirm
rm -rf /tmp/sq-bin*
exit
fi
# brew
if command_exists brew; then
set -e
printf "Using brew to install sq...\n\n"
brew install neilotoole/sq/sq
printf "\n"
sq version
printf "\n"
exit
fi
printf "\nCould not find a suitable install mechanism to install sq.\n"
printf "\nVisit https://github.com/neilotoole/sq for more installation options.\n"
exit 1