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:
Neil O'Toole 2022-12-25 02:44:52 -07:00 committed by GitHub
parent 3ef5522ea5
commit aee9e2ed5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 24 deletions

View File

@ -16,7 +16,7 @@ builds:
- arm64 - arm64
ldflags: ldflags:
- -s -w - -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.Commit={{ .ShortCommit }}
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }} - -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}

View File

@ -17,7 +17,7 @@ builds:
- amd64 - amd64
ldflags: ldflags:
- -s -w - -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.Commit={{ .ShortCommit }}
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }} - -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}

View File

@ -20,7 +20,7 @@ builds:
ldflags: ldflags:
- -extld=aarch64-linux-gnu-gcc - -extld=aarch64-linux-gnu-gcc
- -s -w - -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.Commit={{ .ShortCommit }}
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }} - -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}

View File

@ -15,7 +15,7 @@ builds:
- amd64 - amd64
ldflags: ldflags:
- -s -w - -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.Commit={{ .ShortCommit }}
- -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }} - -X github.com/neilotoole/sq/cli/buildinfo.Timestamp={{ .Date }}

View File

@ -1,13 +1,33 @@
#!/usr/bin/env sh #!/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 get_distribution() {
apt --version >/dev/null 2>&1 lsb_dist=""
if [ "$?" -eq "0" ]; then # 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 set -e
echo "Using apt to install sq..." printf "Using apt to install sq...\n\n"
echo ""
apt update -y && apt install -y --no-upgrade curl gpg apt update -y && apt install -y --no-upgrade curl gpg
@ -23,16 +43,18 @@ EOF
apt update -y && apt install -y sq apt update -y && apt install -y sq
printf "\n"
sq version
printf "\n"
exit exit
fi fi
# Test if yum is installed # Yum / rpm
yum version >/dev/null 2>&1 if command_exists yum; then
if [ "$?" -eq "0" ]; then
set -e set -e
echo "Using yum to install sq..." set +x
echo "" printf "Using yum to install sq...\n\n"
cat <<EOF > /etc/yum.repos.d/sq.repo cat <<EOF > /etc/yum.repos.d/sq.repo
[sq] [sq]
@ -45,28 +67,78 @@ EOF
yum install -y sq yum install -y sq
printf "\n"
sq version
printf "\n"
exit exit
fi fi
# Test if brew is installed # apk / alpine
brew --version >/dev/null 2>&1 if command_exists apk; then
if [ "$?" -eq "0" ]; then
set -e set -e
echo "Using brew to install sq..." printf "Using apk to install sq...\n\n"
echo "" 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 brew install neilotoole/sq/sq
printf "\n"
sq version
printf "\n"
exit exit
fi fi
echo "" printf "\nCould not find a suitable install mechanism to install sq.\n"
echo "Could not find a suitable install mechanism to install sq." printf "\nVisit https://github.com/neilotoole/sq for more installation options.\n"
echo ""
echo "Visit https://github.com/neilotoole/sq for more installation options."
exit 1 exit 1