-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add an install.sh script #1034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8c45cd8
feat: add install.sh script
colinlodter 74b1ff7
chore: add install.sh instructions to readme
colinlodter 1eee1fd
chore: add license header
colinlodter 609732d
fix: add randomness to dir
colinlodter 06804f0
fix: add more X's
colinlodter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,92 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright 2024 Defense Unicorns | ||
| # SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial | ||
|
|
||
|
|
||
| # Parse command-line arguments for debug flag | ||
| DEBUG=false | ||
| while [[ "$#" -gt 0 ]]; do | ||
| case $1 in | ||
| --debug) DEBUG=true ;; | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| # Function to print debug messages | ||
| debug() { | ||
| if [ "${DEBUG}" = true ]; then | ||
| echo "$1" | ||
| fi | ||
| } | ||
|
|
||
| # Determine OS type (linux or macos) | ||
| OS=$(uname | tr '[:upper:]' '[:lower:]') | ||
| if [[ "${OS}" == "darwin" ]]; then | ||
| OS="Darwin" | ||
| elif [[ "${OS}" == "linux" ]]; then | ||
| OS="Linux" | ||
| else | ||
| debug "Unsupported OS: ${OS}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Determine architecture (amd64 or arm64) | ||
| ARCH=$(uname -m) | ||
| if [[ "${ARCH}" == "x86_64" ]]; then | ||
| ARCH="amd64" | ||
| elif [[ "${ARCH}" == "arm64" || "${ARCH}" == "aarch64" ]]; then | ||
| ARCH="arm64" | ||
| else | ||
| debug "Unsupported architecture: ${ARCH}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Construct the download URL | ||
| URL="https://github.com/defenseunicorns/uds-cli" | ||
| RELEASE_URL="${URL}/releases/latest" | ||
|
|
||
|
|
||
| # Define the version to install | ||
| VERSION=$(curl --tlsv1.2 --proto "=https" --fail --show-error -Ls -o /dev/null -w %{url_effective} ${RELEASE_URL} | grep -oE "[^/]+$" ) | ||
| debug "Version set to ${VERSION}" | ||
|
|
||
| # Set binary name | ||
| BINARY_NAME="uds" | ||
|
|
||
| # Set full path to binary download | ||
| FULL_PATH="releases/download/${VERSION}/uds-cli_${VERSION}_${OS}_${ARCH}" | ||
|
|
||
| UDS_TMP_DIR="$(mktemp -d -t uds-binary-XXXXXXXX)" | ||
| UDS_TMP_FILE="${UDS_TMP_DIR}/${BINARY_NAME}" | ||
|
|
||
| # Download the binary | ||
| debug "Downloading uds-cli for ${OS}-${ARCH}..." | ||
| curl --tlsv1.2 --proto "=https" --fail --show-error -L -o "${UDS_TMP_FILE}" "${URL}/${FULL_PATH}" | ||
| if [[ $? -ne 0 ]]; then | ||
| debug "Failed to download uds-cli from ${URL}/${FULL_PATH}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Make the binary executable | ||
| chmod +x "${UDS_TMP_FILE}" | ||
|
|
||
| # Define the installation directory and binary name | ||
| INSTALL_DIR="/usr/local/bin" | ||
|
|
||
| # Move the binary to the installation directory | ||
| debug "Installing uds-cli to ${INSTALL_DIR}..." | ||
| sudo mv "${UDS_TMP_FILE}" "${INSTALL_DIR}/" | ||
| if [[ $? -ne 0 ]]; then | ||
| echo "Failed to move uds-cli to ${INSTALL_DIR}" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify the installation | ||
| debug "Verifying uds-cli installation..." | ||
| "${INSTALL_DIR}/${BINARY_NAME}" version > /dev/null 2>&1 | ||
| if [[ $? -eq 0 ]]; then | ||
| debug "uds-cli ${VERSION} installed successfully!" | ||
| else | ||
| debug "Installation failed." | ||
| exit 1 | ||
| fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer something more like the zarf docs here: https://docs.zarf.dev/getting-started/install/#github-releases
Essentially it just provides the curl, chmod, and mv commands you'd need to grab the right binary per your system, in easy copy/paste blocks. I think it still meets the desire of providing an alternative install mechanism that's relatively simple, but avoids the (1) potential suspect nature of piping a curl-ed script right to a shell and (2) keeps it simple and trusts the end user to know their platform. Open to other opinions here though. I think this is generally in line with zarf as linked, but also kubectl (which also teaches additional good habits like verifying the sha, etc).