Skip to content

Commit

Permalink
New installs should use our install.sh instead of brew (#29)
Browse files Browse the repository at this point in the history
* New installs should use our install.sh instead of brew

Signed-off-by: Eddie Knight <[email protected]>

* polishing the install.sh

Signed-off-by: Eddie Knight <[email protected]>

* Debugging for windows

Signed-off-by: Eddie Knight <[email protected]>

* Updated readme, sorta

Signed-off-by: Eddie Knight <[email protected]>

---------

Signed-off-by: Eddie Knight <[email protected]>
  • Loading branch information
eddie-knight authored Sep 27, 2024
1 parent 686093f commit 5c35295
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 48 deletions.
7 changes: 0 additions & 7 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ release:
universal_binaries:
- replace: true

brews:
- name: privateer
homepage: https://github.com/privateerproj/privateer
tap:
owner: privateerproj
name: homebrew-privateer

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Ref: https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications

BUILD_FLAGS=-X 'main.GitCommitHash=`git rev-parse --short HEAD`' -X 'main.BuiltAt=`date +%FT%T%z`' -X 'main.Version=`git describe --tags`'
BUILD_WIN=@env GOOS=windows GOARCH=amd64 go build -o privateer.exe
BUILD_LINUX=@env GOOS=linux GOARCH=amd64 go build -o privateer
BUILD_WIN=@env GOOS=windows GOARCH=amd64 go build -o privateer-windows.exe
BUILD_LINUX=@env GOOS=linux GOARCH=amd64 go build -o privateer-linux
BUILD_MAC=@env GOOS=darwin GOARCH=amd64 go build -o privateer-darwin

binary: go-tidy go-test go-build
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Welcome to Privateer, your all-inclusive test harness designed to streamline the

Privateer has been meticulously crafted with infrastructure engineers in mind. If you're seeking to validate your resources against regulations, taxonomies, or standards, Privateer is your trusted companion. With a user-friendly interface and powerful features, you can now effortlessly navigate the complexities of resource validation.

### Unlocking the Power of Raids
### Privateer Raids

There are several key benefits to Privateer Raids:

Expand All @@ -38,7 +38,10 @@ Privateer empowers you to ensure the security, compliance, and integrity of your

### Installation

1. **Download Privateer**: Obtain the latest release of Privateer from the [GitHub repository](https://github.com/privateerproj/privateer/releases).
1. **Download Privateer**: Obtain the latest release of Privateer:
- from GitHub Repository source, with `go build`
- from the [GitHub Releases](https://github.com/privateerproj/privateer/releases)
- from the [installation script](install.sh)
1. **Install Raids**: Choose the raid(s) you wish to use from the same release on GitHub. Install them to your preferred `binaries-path`. By default, this is `$HOME/privateer/bin`, but you can customize it in your configuration or via `--binaries-path`.

#### Build Privateer from Source
Expand Down
127 changes: 127 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/bin/bash

set -e

# Constants
DEFAULT_INSTALL_DIR="$HOME/.privateer/bin"
PRIVATEER_REPO="privateerproj/privateer"
LATEST_RELEASE_URL="https://api.github.com/repos/${PRIVATEER_REPO}/releases/latest"

# Detect OS (darwin = macOS, linux = Linux, msys or cygwin = Windows)
OS=""
case "$(uname -s)" in
Darwin)
OS="darwin"
;;
Linux)
OS="linux"
;;
CYGWIN*|MSYS*|MINGW*)
OS="windows"
;;
*)
echo "Unsupported Environment: $(uname -s)"
exit 1
;;
esac

download_latest_release() {
local install_dir="$1"
local install_file="$install_dir/privateer"

# Ensure the directory exists
mkdir -p "$install_dir"

# Fetch the download URL for the latest release
local url
url=$(curl -s ${LATEST_RELEASE_URL} | grep "browser_download_url.*${OS}.*" | cut -d '"' -f 4)

if [[ -z "$url" ]]; then
echo "Failed to fetch the download URL for the latest release."
exit 1
fi

echo "Downloading from: $url"

# Download the binary to the specified install directory
curl -L -o "$install_file" "$url"

if [[ $? -ne 0 ]]; then
echo "Failed to download the binary."
exit 1
fi

# Ensure the binary is executable
chmod +x "$install_file"

echo "Downloaded binary to $install_file"
}

update_path() {
local install_dir="$1"

# Check if the install directory is already in PATH
if [[ ":$PATH:" != *":$install_dir:"* ]]; then
echo "$install_dir is not in the PATH."

# Detect current shell
current_shell=$(basename "$SHELL")

case "$current_shell" in
bash)
config_file="$HOME/.bashrc"
;;
zsh)
config_file="$HOME/.zshrc"
;;
fish)
config_file="$HOME/.config/fish/config.fish"
;;
*)
echo "Unsupported shell: $current_shell. You may need to manually add $install_dir to your PATH."
return
;;
esac

# Check if the path is already added to the config file
if ! grep -q "$install_dir" "$config_file"; then
echo "export PATH=\"$install_dir:\$PATH\"" >> "$config_file"
echo "$install_dir added to $config_file"
source $config_file
else
echo "$install_dir is already in $config_file."
fi
else
echo "$install_dir is already in the PATH."
fi
}

# Main logic
main() {
local install_dir="$DEFAULT_INSTALL_DIR"

# Handle CLI arguments for installation path override
while getopts "p:" opt; do
case $opt in
p)
install_dir="$OPTARG"
;;
*)
echo "Usage: $0 [-p install_path]"
exit 1
;;
esac
done

mkdir -p "$install_dir"

# Download the latest release
download_latest_release "$install_dir"

# Ensure the binary is accessible via PATH
update_path "$install_dir"

echo "Privateer installation complete!"
}

main "$@"
37 changes: 0 additions & 37 deletions privateer.rb

This file was deleted.

0 comments on commit 5c35295

Please sign in to comment.