Skip to content

Commit

Permalink
Merge pull request #105 from PierreBeucher/install-script.sh
Browse files Browse the repository at this point in the history
feat: added plain install script
  • Loading branch information
PierreBeucher authored Apr 15, 2024
2 parents 40516dd + 02839fd commit e73b023
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 18 deletions.
48 changes: 31 additions & 17 deletions docs/src/install.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
# Installation

- [Linux](#linux)
- [MacOS (Darwin)](#macos-darwin)
- [Windows](#windows)
- [Arch Linux](#arch-linux)
- [Nix](#nix)
- [Direct binary download](#direct-binary-download)
- [Build from source](#build-from-source)
- [Updating](#updating)
- [Automated installation (Linux, MacOS and Windows with WSL)](#automated-installation-linux-macos-and-windows-with-wsl)
- [Manual installation](#manual-installation)
- [Linux](#linux)
- [MacOS (Darwin)](#macos-darwin)
- [Windows](#windows)
- [Arch Linux](#arch-linux)
- [Nix](#nix)
- [Direct binary download](#direct-binary-download)
- [Build from source](#build-from-source)
- [Updating](#updating)

Novops is distributed as a standalone static binary. No dependencies are required.

## Linux
## Automated installation (Linux, MacOS and Windows with WSL)

Run command:

```sh
sh -c "$(curl --location https://raw.githubusercontent.com/PierreBeucher/novops/main/install.sh)"
```

Install script will take care of downloading latest Novops version, verify checksum and make it available on `PATH`.

## Manual installation

### Linux

Download latest Novops binary latest version:

Expand Down Expand Up @@ -48,7 +62,7 @@ Check it works:
novops --version
```

## MacOS (Darwin)
### MacOS (Darwin)

Download latest Novops binary latest version:

Expand Down Expand Up @@ -85,19 +99,19 @@ Check it works:
novops --version
```

## Windows
### Windows

Novops does not offer native Windows ([coming soon](https://github.com/PierreBeucher/novops/issues/90)). You can use [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) in the meantime, following Linux installation.
Use [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) and follow [Linux](#linux) installation.

## Arch Linux
### Arch Linux

Available in the AUR (Arch User Repository)

```sh
yay -S novops-git
```

## Nix
### Nix

Use a `flake.nix` such as:

Expand Down Expand Up @@ -142,14 +156,14 @@ Use a `flake.nix` such as:
}
```

## Direct binary download
### Direct binary download

See [GithHub releases](https://github.com/PierreBeucher/novops/releases) to download binaries directly.

## Build from source
### Build from source

See [Development and contribution guide](contributing/development.md) to build from source.

### Updating
## Updating

To update Novops, replace binary with a new one following installation steps above.
93 changes: 93 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env sh

set -x

TMP_INSTALL_DIR="${TMPDIR:-/tmp}/novops-install"
INSTALL_DIR="/usr/local/bin"
YELLOW='\e[0;33m'
RESET='\033[0m'

# Check required tools are available
if ! curl --version > /dev/null
then
echo "Error: curl is not installed. Please install curl first." >&2
exit 1
fi

if ! unzip -v > /dev/null
then
echo "Error: unzip is not installed. Please install unzip first." >&2
exit 1
fi

# Detect OS and Architecture
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH="x86_64"
;;
aarch64)
ARCH="aarch64"
;;
arm64)
ARCH="aarch64" # macOS sometimes reports ARM as arm64
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac

# Define installation directory and zip file
RELEASE_FILE_PREFIX="novops_${OS}_${ARCH}"

ZIP_NAME="${RELEASE_FILE_PREFIX}.zip"
ZIP_PATH="${TMP_INSTALL_DIR}/${ZIP_NAME}"

CHECKSUM_NAME="${RELEASE_FILE_PREFIX}.sha256sum"
CHECKSUM_PATH="${TMP_INSTALL_DIR}/${CHECKSUM_NAME}"

NOVOPS_BIN_TMP_PATH="${TMP_INSTALL_DIR}/novops"

ZIP_URL="https://github.com/PierreBeucher/novops/releases/latest/download/${ZIP_NAME}"
CHECKSUM_URL="https://github.com/PierreBeucher/novops/releases/latest/download/${CHECKSUM_NAME}"

# Download and unzip the package
mkdir -p $TMP_INSTALL_DIR
curl -L "${ZIP_URL}" -o "${ZIP_PATH}"
unzip -o "${ZIP_PATH}" -d "${TMP_INSTALL_DIR}"

# Checksum
curl -L "${CHECKSUM_URL}" -o "${CHECKSUM_PATH}"
sha256sum -c "${CHECKSUM_PATH}"

if [ $? -eq 0 ]; then
echo "Checksum verification succeeded."
else
echo "Checksum verification failed."
exit 1
fi

# Only need sudo to copy to install dir
if [ "$(id -u)" -eq 0 ]; then
mv "${NOVOPS_BIN_TMP_PATH}" "${INSTALL_DIR}"
else
sudo mv "${NOVOPS_BIN_TMP_PATH}" "${INSTALL_DIR}"
fi

rm "${ZIP_PATH}"
rm "${CHECKSUM_PATH}"

# Check if /usr/local/bin is in the PATH
# Use case statement for POSIX-compliant pattern matching
case ":${PATH}:" in
*:/usr/local/bin:*)
echo "Novops installed successfully."
;;
*)
echo "${YELLOW}Warning: /usr/local/bin is not in your PATH, novops commands may not work.${RESET}" >&2
;;
esac


28 changes: 28 additions & 0 deletions tests/install/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env sh

set -x

#
# Manual script to test Novops installation script with various shells
#

# bash dash zsh fish ksh tcsh csh curl unzip


function test_novops_install() {
local image=$1
shift # Shift the first argument to get rid of the image name, leaving only commands

# Run the docker container with the specified image and commands
if docker run -it --rm -v "$PWD:/local" -w /local "$image" /bin/sh -c "$*"; then
echo "OK: $image"
else
echo "NOT OK: $image"
exit 1
fi
}

test_novops_install alpine:3.19.1 "apk update && apk add curl unzip && ./install.sh && novops --version"
test_novops_install debian:12.5-slim "apt update && apt install curl unzip -y && ./install.sh && novops --version"
test_novops_install ubuntu:22.04 "apt update && apt install curl unzip -y && ./install.sh && novops --version"

2 changes: 1 addition & 1 deletion tests/shells/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env sh

#
# Manual script to test various shells
Expand Down

0 comments on commit e73b023

Please sign in to comment.