From 1389c44bb93d80fa493e1b99ce391b3a72a87712 Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Sat, 18 May 2024 11:41:39 +0800 Subject: [PATCH] feat: add shell of startup install mage. --- bootstrap_install_mage.bat | 31 +++++++++++++++++++++++++++++++ bootstrap_install_mage.sh | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 bootstrap_install_mage.bat create mode 100644 bootstrap_install_mage.sh diff --git a/bootstrap_install_mage.bat b/bootstrap_install_mage.bat new file mode 100644 index 0000000..819f19c --- /dev/null +++ b/bootstrap_install_mage.bat @@ -0,0 +1,31 @@ +@echo off +SETLOCAL + +mage -version >nul 2>&1 +IF %ERRORLEVEL% EQU 0 ( + echo Mage is already installed. + GOTO DOWNLOAD +) + +go version >nul 2>&1 +IF NOT %ERRORLEVEL% EQU 0 ( + echo Go is not installed. Please install Go and try again. + exit /b 1 +) + +echo Installing Mage... +go install github.com/magefile/mage@latest + +mage -version >nul 2>&1 +IF NOT %ERRORLEVEL% EQU 0 ( + echo Mage installation failed. + echo Please ensure that %GOPATH%/bin is in your PATH. + exit /b 1 +) + +echo Mage installed successfully. + +:DOWNLOAD +go mod download + +ENDLOCAL diff --git a/bootstrap_install_mage.sh b/bootstrap_install_mage.sh new file mode 100644 index 0000000..f79cd1f --- /dev/null +++ b/bootstrap_install_mage.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then + TARGET_DIR="$HOME/.local/bin" +else + TARGET_DIR="/usr/local/bin" + echo "Using /usr/local/bin as the installation directory. Might require sudo permissions." +fi + +if ! command -v mage &> /dev/null; then + echo "Installing Mage to $TARGET_DIR ..." + GOBIN=$TARGET_DIR go install github.com/magefile/mage@latest +fi + +if ! command -v mage &> /dev/null; then + echo "Mage installation failed." + echo "Please ensure that $TARGET_DIR is in your \$PATH." + exit 1 +fi + +echo "Mage installed successfully." + +go mod download