mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-28 18:53:35 +03:00
Feature/apk install (#134)
* wip * wip * Updated install.sh to support alpine/apk * tidied up install.sh output for apk * refactor install.sh; hopefully embedded version info now includes 'v' * install.sh cleanup
This commit is contained in:
parent
3ef5522ea5
commit
aee9e2ed5b
@ -16,7 +16,7 @@ builds:
|
||||
- arm64
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version=v{{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
|
||||
|
||||
|
@ -17,7 +17,7 @@ builds:
|
||||
- amd64
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version=v{{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
|
||||
|
||||
|
@ -20,7 +20,7 @@ builds:
|
||||
ldflags:
|
||||
- -extld=aarch64-linux-gnu-gcc
|
||||
- -s -w
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version=v{{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
|
||||
|
||||
|
@ -15,7 +15,7 @@ builds:
|
||||
- amd64
|
||||
ldflags:
|
||||
- -s -w
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version={{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Version=v{{ .Version }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Commit={{ .ShortCommit }}
|
||||
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}
|
||||
|
||||
|
112
install.sh
112
install.sh
@ -1,13 +1,33 @@
|
||||
#!/usr/bin/env sh
|
||||
# This script attempts to install sq via apt, yum, or brew.
|
||||
# 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
|
||||
|
||||
|
||||
# Test if apt is installed
|
||||
apt --version >/dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
get_distribution() {
|
||||
lsb_dist=""
|
||||
# Every system that we officially support has /etc/os-release
|
||||
if [ -r /etc/os-release ]; then
|
||||
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"
|
||||
}
|
||||
|
||||
# Usage:
|
||||
#
|
||||
# if command_exists lsb_release; then
|
||||
command_exists() {
|
||||
command -v "$@" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
get_distribution
|
||||
|
||||
# apt / deb
|
||||
if [ -r /etc/debian_version ] && command_exists apt; then
|
||||
set -e
|
||||
echo "Using apt to install sq..."
|
||||
echo ""
|
||||
printf "Using apt to install sq...\n\n"
|
||||
|
||||
apt update -y && apt install -y --no-upgrade curl gpg
|
||||
|
||||
@ -23,16 +43,18 @@ EOF
|
||||
|
||||
apt update -y && apt install -y sq
|
||||
|
||||
printf "\n"
|
||||
sq version
|
||||
printf "\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
# Test if yum is installed
|
||||
yum version >/dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
# Yum / rpm
|
||||
if command_exists yum; then
|
||||
set -e
|
||||
echo "Using yum to install sq..."
|
||||
echo ""
|
||||
set +x
|
||||
printf "Using yum to install sq...\n\n"
|
||||
|
||||
cat <<EOF > /etc/yum.repos.d/sq.repo
|
||||
[sq]
|
||||
@ -45,28 +67,78 @@ EOF
|
||||
|
||||
yum install -y sq
|
||||
|
||||
printf "\n"
|
||||
sq version
|
||||
printf "\n"
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
# Test if brew is installed
|
||||
brew --version >/dev/null 2>&1
|
||||
if [ "$?" -eq "0" ]; then
|
||||
# apk / alpine
|
||||
if command_exists apk; then
|
||||
set -e
|
||||
echo "Using brew to install sq..."
|
||||
echo ""
|
||||
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 %q\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
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
echo ""
|
||||
echo "Could not find a suitable install mechanism to install sq."
|
||||
echo ""
|
||||
echo "Visit https://github.com/neilotoole/sq for more installation options."
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user