From 02839fdd69f037f7c01c59e5fe553528d0030b4e Mon Sep 17 00:00:00 2001 From: Pierre beucher Date: Mon, 15 Apr 2024 16:59:05 +0200 Subject: [PATCH] feat: added plain install script --- docs/src/install.md | 48 +++++++++++++-------- install.sh | 93 ++++++++++++++++++++++++++++++++++++++++ tests/install/install.sh | 28 ++++++++++++ tests/shells/run.sh | 2 +- 4 files changed, 153 insertions(+), 18 deletions(-) create mode 100755 install.sh create mode 100755 tests/install/install.sh diff --git a/docs/src/install.md b/docs/src/install.md index 7876c06..8b1ea07 100644 --- a/docs/src/install.md +++ b/docs/src/install.md @@ -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: @@ -48,7 +62,7 @@ Check it works: novops --version ``` -## MacOS (Darwin) +### MacOS (Darwin) Download latest Novops binary latest version: @@ -85,11 +99,11 @@ 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) @@ -97,7 +111,7 @@ Available in the AUR (Arch User Repository) yay -S novops-git ``` -## Nix +### Nix Use a `flake.nix` such as: @@ -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. diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..ca4f4da --- /dev/null +++ b/install.sh @@ -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 + + diff --git a/tests/install/install.sh b/tests/install/install.sh new file mode 100755 index 0000000..b360882 --- /dev/null +++ b/tests/install/install.sh @@ -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" + diff --git a/tests/shells/run.sh b/tests/shells/run.sh index 4e7f2e1..9ef6e88 100755 --- a/tests/shells/run.sh +++ b/tests/shells/run.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env sh # # Manual script to test various shells