Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Recommended installation method is with Brew:
```
brew tap defenseunicorns/tap && brew install uds
```

An `install.sh` file is also available for installation with curl (requires `sudo`):
```
curl -sSL https://raw.githubusercontent.com/defenseunicorns/uds-cli/main/install.sh | bash
```
Comment on lines +14 to +17
Copy link
Copy Markdown
Contributor

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).


UDS CLI binaries are also included with each [Github Release](https://github.com/defenseunicorns/uds-cli/releases)

## Official Documentation
Expand Down
92 changes: 92 additions & 0 deletions install.sh
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