This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create installation script + fix release pipeline
- Loading branch information
1 parent
08e725d
commit 5dd98ba
Showing
4 changed files
with
152 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#! /usr/bin/bash | ||
|
||
PROJECT="aws-sso-auth" | ||
|
||
set -eu | ||
declare -a commands=("curl" "jq" "unzip") | ||
|
||
trap ctrl_c INT | ||
|
||
function ctrl_c(){ | ||
clean | ||
echo -e "\nBye!" | ||
exit 0 | ||
} | ||
|
||
command_exists() { | ||
for command in "${commands[@]}" | ||
do | ||
if ! command -v "$command" &> /dev/null | ||
then | ||
echo "ERROR: $command could not be found. Install it!" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
clean(){ | ||
echo -e "Cleaning $tmpdir" | ||
rm -r "$tmpdir" | ||
} | ||
|
||
# Pre flight checks | ||
command_exists | ||
|
||
happyexit(){ | ||
echo "" | ||
echo "${PROJECT} successfully installed! 🎉" | ||
echo "" | ||
echo "Now run:" | ||
echo "" | ||
echo " ${PROJECT} usage" | ||
echo "" | ||
exit 0 | ||
} | ||
|
||
validate_checksum(){ | ||
echo "Not implemented yet" | ||
} | ||
|
||
# Check OS | ||
OS=$(uname -s) | ||
arch=$(uname -m) | ||
cli_arch="" | ||
case $OS in | ||
Darwin) | ||
case $arch in | ||
x86_64) | ||
cli_arch=amd64 | ||
;; | ||
arm64) | ||
cli_arch=$arch | ||
;; | ||
*) | ||
echo "There is no ${PROJECT} $OS support for $arch" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
Linux) | ||
case $arch in | ||
x86_64) | ||
cli_arch=amd64 | ||
;; | ||
armv8*) | ||
cli_arch=arm64 | ||
;; | ||
aarch64*) | ||
cli_arch=arm64 | ||
;; | ||
amd64|arm64) | ||
cli_arch=$arch | ||
;; | ||
*) | ||
echo "There is no ${PROJECT} $OS support for $arch" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
*) | ||
echo "There is no ${PROJECT} $OS support for $arch" | ||
exit 1 | ||
;; | ||
esac | ||
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]') | ||
|
||
download_release() { | ||
LATEST_VERSION=$(curl -s https://api.github.com/repos/containerscrew/$PROJECT/releases/latest | jq -r ".name") | ||
INSTALLATION_PATH="/usr/local/bin/" | ||
tmpdir=$(mktemp -d) | ||
|
||
cd $tmpdir | ||
echo -e "Downloading... ${LATEST_VERSION}/${PROJECT}-${OS}-${cli_arch}.zip \n" | ||
curl -L --fail --remote-name-all https://github.com/containerscrew/${PROJECT}/releases/download/"${LATEST_VERSION}"/${PROJECT}-${OS}-${cli_arch}.zip | ||
unzip ${PROJECT}-${OS}-${cli_arch}.zip ${PROJECT} | ||
} | ||
|
||
# Start install | ||
download_release | ||
|
||
if [ "$EUID" -ne 0 ] | ||
then command_exists sudo | ||
sudo mv ${PROJECT} $INSTALLATION_PATH | ||
else | ||
mv ${PROJECT} $INSTALLATION_PATH | ||
chmod +x $INSTALLATION_PATH/${PROJECT} | ||
fi | ||
|
||
clean | ||
happyexit |