|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script automates the installation of the lamver tool. |
| 4 | +# It checks for the specified version (or fetches the latest one), |
| 5 | +# downloads the binary, and installs it on the system. |
| 6 | + |
| 7 | +# Check for required tools: curl and tar. |
| 8 | +# These tools are necessary for downloading and extracting the lamver binary. |
| 9 | +if ! command -v curl &>/dev/null; then |
| 10 | + echo "curl could not be found" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +if ! command -v tar &>/dev/null; then |
| 15 | + echo "tar could not be found" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Determine the version of lamver to install. |
| 20 | +# If no version is specified as a command line argument, fetch the latest version. |
| 21 | +if [ -z "$1" ]; then |
| 22 | + VERSION=$(curl -s https://api.github.com/repos/go-to-k/lamver/releases/latest | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') |
| 23 | + if [ -z "$VERSION" ]; then |
| 24 | + echo "Failed to fetch the latest version" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | +else |
| 28 | + VERSION=$1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Normalize the version string by removing any leading 'v'. |
| 32 | +VERSION=${VERSION#v} |
| 33 | + |
| 34 | +# Detect the architecture of the current system. |
| 35 | +# This script supports x86_64, arm64, and i386 architectures. |
| 36 | +ARCH=$(uname -m) |
| 37 | +case $ARCH in |
| 38 | +x86_64 | amd64) ARCH="x86_64" ;; |
| 39 | +arm64 | aarch64) ARCH="arm64" ;; |
| 40 | +i386 | i686) ARCH="i386" ;; |
| 41 | +*) |
| 42 | + echo "Unsupported architecture: $ARCH" |
| 43 | + exit 1 |
| 44 | + ;; |
| 45 | +esac |
| 46 | + |
| 47 | +# Detect the operating system (OS) of the current system. |
| 48 | +# This script supports Linux, Darwin (macOS) and Windows operating systems. |
| 49 | +OS=$(uname -s) |
| 50 | +case $OS in |
| 51 | +Linux) OS="Linux" ;; |
| 52 | +Darwin) OS="Darwin" ;; |
| 53 | +MINGW* | MSYS* | CYGWIN*) OS="Windows" ;; |
| 54 | +*) |
| 55 | + echo "Unsupported OS: $OS" |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | +esac |
| 59 | + |
| 60 | +# Construct the download URL for the lamver binary based on the version, OS, and architecture. |
| 61 | +FILE_NAME="lamver_${VERSION}_${OS}_${ARCH}.tar.gz" |
| 62 | +URL="https://github.com/go-to-k/lamver/releases/download/v${VERSION}/${FILE_NAME}" |
| 63 | + |
| 64 | +# Download the lamver binary. |
| 65 | +echo "Downloading lamver..." |
| 66 | +if ! curl -L -o "$FILE_NAME" "$URL"; then |
| 67 | + echo "Failed to download lamver" |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +# Install lamver. |
| 72 | +# This involves extracting the binary and moving it to /usr/local/bin. |
| 73 | +echo "Installing lamver..." |
| 74 | +if ! tar -xzf "$FILE_NAME"; then |
| 75 | + echo "Failed to extract lamver" |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | +if ! sudo mv lamver /usr/local/bin/lamver; then |
| 79 | + echo "Failed to install lamver" |
| 80 | + exit 1 |
| 81 | +fi |
| 82 | + |
| 83 | +# Clean up by removing the downloaded tar file. |
| 84 | +rm "$FILE_NAME" |
| 85 | + |
| 86 | +echo "lamver installation complete." |
| 87 | +echo "Run 'lamver -h' to see how to use lamver." |
0 commit comments