diff --git a/README.md b/README.md index 31c682b..82908be 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ Build from source: make ``` -Or download pre-built binaries (coming soon): +Or install using pre-built binaries: ```bash -// TODO +curl -fsSL https://raw.githubusercontent.com/malletgaetan/dockermon/main/install.sh | sudo bash ``` ### Basic Usage diff --git a/TODO.md b/TODO.md index a7e773f..437d543 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ - [x] Resilience on events listening fail - [x] Add more tests - [x] CI/CD Pipeline, no push on main (tests, fmt and static analysis) -- [ ] One file installer +- [x] One line installer - [ ] Event Type wildcard - [ ] Windows compatibility \ No newline at end of file diff --git a/installer.sh b/installer.sh new file mode 100755 index 0000000..78f0452 --- /dev/null +++ b/installer.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Function to get latest release tag from GitHub API +get_latest_tag() { + local repo=$1 + curl -s "https://api.github.com/repos/$repo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' +} + +# Function to detect OS and architecture +detect_platform() { + OS=$(uname -s | tr '[:upper:]' '[:lower:]') + ARCH=$(uname -m) + + case "$ARCH" in + x86_64) + ARCH="amd64" + ;; + *) + echo "Unsupported architecture: $ARCH" + exit 1 + ;; + esac + + case "$OS" in + linux|darwin) + ;; + *) + echo "Unsupported operating system: $OS" + exit 1 + ;; + esac +} + +# Main installation function +install_dockermon() { + # Replace with your GitHub username/repo + REPO="malletgaetan/dockermon" + INSTALL_DIR="/usr/local/bin" + + echo "Detecting platform..." + detect_platform + + echo "Getting latest release..." + TAG=$(get_latest_tag "$REPO") + if [ -z "$TAG" ]; then + echo "Failed to get latest release tag" + exit 1 + fi + + BINARY_NAME="dockermon-$OS-$ARCH" + DOWNLOAD_URL="https://github.com/$REPO/releases/download/$TAG/$BINARY_NAME" + + echo "Downloading $BINARY_NAME..." + if ! curl -L -o "$INSTALL_DIR/dockermon" "$DOWNLOAD_URL"; then + echo "Failed to download binary" + exit 1 + fi + + echo "Setting executable permissions..." + chmod +x "$INSTALL_DIR/dockermon" + + echo "Installation complete! dockermon has been installed to $INSTALL_DIR/dockermon" + echo "You can now run 'dockermon' from anywhere" +} + +if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root (sudo)" + exit 1 +fi + +install_dockermon \ No newline at end of file diff --git a/internal/config/parser.go b/internal/config/parser.go index 0439803..cbb613c 100644 --- a/internal/config/parser.go +++ b/internal/config/parser.go @@ -41,7 +41,6 @@ type parser struct { pos Position } -// TODO: fix func keys[T any](m map[string]T) []string { arr := make([]string, len(m)) i := 0