Update installation scripts (#21)

* Rename variable INSTALL_CIRDL to CIRDL

* Add BASE_URL variable for local download
This commit is contained in:
Slava 2024-11-18 16:19:14 +02:00 committed by GitHub
parent fc00519885
commit 9178041011
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 94 additions and 54 deletions

View File

@ -14,12 +14,12 @@ curl -s https://get.codex.storage/install.sh | VERSION=0.1.7 bash
```shell ```shell
# latest codex and cirdl # latest codex and cirdl
curl -s https://get.codex.storage/install.sh | INSTALL_CIRDL=true bash curl -s https://get.codex.storage/install.sh | CIRDL=true bash
``` ```
```shell ```shell
# codex and cirdl with required libraries on Windows with msys2 # codex and cirdl with required libraries on Windows with msys2
curl -s https://get.codex.storage/install.sh | INSTALL_CIRDL=true WINDOWS_LIBS=true bash curl -s https://get.codex.storage/install.sh | CIRDL=true WINDOWS_LIBS=true bash
``` ```
```shell ```shell
@ -41,12 +41,12 @@ curl -sO https://get.codex.storage/install.cmd && set VERSION=0.1.7 & install.cm
```batch ```batch
:: latest codex and cirdl :: latest codex and cirdl
curl -sO https://get.codex.storage/install.cmd && set INSTALL_CIRDL=true & install.cmd curl -sO https://get.codex.storage/install.cmd && set CIRDL=true & install.cmd
``` ```
```batch ```batch
:: codex and cirdl without libraries :: codex and cirdl without libraries
curl -sO https://get.codex.storage/install.cmd && set INSTALL_CIRDL=true & set WINDOWS_LIBS=true & install.cmd curl -sO https://get.codex.storage/install.cmd && set CIRDL=true & set WINDOWS_LIBS=true & install.cmd
``` ```
```batch ```batch

View File

@ -38,7 +38,7 @@
# latest codex and cirdl # latest codex and cirdl
</span> </span>
<br> <br>
curl -s https://get.codex.storage/install.sh | INSTALL_CIRDL=true bash curl -s https://get.codex.storage/install.sh | CIRDL=true bash
</p> </p>
<p> <p>
@ -46,7 +46,7 @@
# codex and cirdl with required libraries on Windows with msys2 # codex and cirdl with required libraries on Windows with msys2
</span> </span>
<br> <br>
curl -s https://get.codex.storage/install.sh | INSTALL_CIRDL=true WINDOWS_LIBS=true bash curl -s https://get.codex.storage/install.sh | CIRDL=true WINDOWS_LIBS=true bash
</p> </p>
<br> <br>
@ -76,7 +76,7 @@
:: latest codex and cirdl :: latest codex and cirdl
</span> </span>
<br> <br>
curl -sO https://get.codex.storage/install.cmd && set INSTALL_CIRDL=true install.cmd curl -sO https://get.codex.storage/install.cmd && set CIRDL=true install.cmd
</p> </p>
<p> <p>
@ -84,7 +84,7 @@
:: codex and cirdl without libraries :: codex and cirdl without libraries
</span> </span>
<br> <br>
curl -sO https://get.codex.storage/install.cmd && set INSTALL_CIRDL=true & set WINDOWS_LIBS=false & install.cmd curl -sO https://get.codex.storage/install.cmd && set CIRDL=true & set WINDOWS_LIBS=false & install.cmd
</p> </p>
</body> </body>
</html> </html>

View File

@ -4,17 +4,49 @@ setlocal enabledelayedexpansion
:: Install Codex on Windows :: Install Codex on Windows
:: Variables :: Variables
if not defined VERSION set VERSION=latest if defined VERSION (
if not defined INSTALL_CIRDL set INSTALL_CIRDL=false :: Remove trailing spaces
if not defined INSTALL_DIR set "INSTALL_DIR=%LOCALAPPDATA%\Codex" for /l %%v in (1,1,100) do if "!VERSION:~-1!"==" " set VERSION=v!VERSION:~0,-1!
) else (
set VERSION=latest
)
if defined CIRDL (
for /l %%v in (1,1,100) do if "!CIRDL:~-1!"==" " set CIRDL=!CIRDL:~0,-1!
) else (
set CIRDL=false
)
if defined INSTALL_DIR (
for /l %%v in (1,1,100) do if "!INSTALL_DIR:~-1!"==" " set INSTALL_DIR=!INSTALL_DIR:~0,-1!
) else (
set "INSTALL_DIR=%LOCALAPPDATA%\Codex"
)
set CODEX_ARCHIVE_PREFIX=codex set CODEX_ARCHIVE_PREFIX=codex
set CIRDL_ARCHIVE_PREFIX=cirdl set CIRDL_ARCHIVE_PREFIX=cirdl
set CODEX_BINARY_PREFIX=codex set CODEX_BINARY_PREFIX=codex
set CIRDL_BINARY_PREFIX=cirdl set CIRDL_BINARY_PREFIX=cirdl
if not defined WINDOWS_LIBS set WINDOWS_LIBS=true
set BASE_URL=https://github.com/codex-storage/nim-codex if defined WINDOWS_LIBS (
for /l %%v in (1,1,100) do if "!WINDOWS_LIBS:~-1!"==" " set WINDOWS_LIBS=!WINDOWS_LIBS:~0,-1!
) else (
set WINDOWS_LIBS=true
)
if defined BASE_URL (
for /l %%v in (1,1,100) do if "!BASE_URL:~-1!"==" " set BASE_URL=!BASE_URL:~0,-1!
) else (
set BASE_URL=https://github.com/codex-storage/nim-codex
)
set API_BASE_URL=https://api.github.com/repos/codex-storage/nim-codex set API_BASE_URL=https://api.github.com/repos/codex-storage/nim-codex
if not defined TEMP_DIR set TEMP_DIR=.
if defined TEMP_DIR (
for /l %%v in (1,1,100) do if "!TEMP_DIR:~-1!"==" " set TEMP_DIR=!TEMP_DIR:~0,-1!
) else (
set TEMP_DIR=.
)
:: Colors :: Colors
for /f %%a in ('echo prompt $E^| cmd') do set "ESC=%%a" for /f %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
@ -26,16 +58,17 @@ if "%1" == "help" (
set URL=https://get.codex.storage/!SCRIPT_NAME! set URL=https://get.codex.storage/!SCRIPT_NAME!
set "COMMAND=curl -sO !URL!" set "COMMAND=curl -sO !URL!"
echo !COMMAND! ^&^& !SCRIPT_NAME! echo !COMMAND! ^&^& !SCRIPT_NAME!
echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set INSTALL_CIRDL=true ^& !SCRIPT_NAME! echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set CIRDL=true ^& !SCRIPT_NAME!
echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set WINDOWS_LIBS=false ^& !SCRIPT_NAME! echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set WINDOWS_LIBS=false ^& !SCRIPT_NAME!
echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set "INSTALL_DIR=C:\Program Files\Codex" ^& !SCRIPT_NAME! echo !COMMAND! ^&^& set VERSION=0.1.7 ^& set "INSTALL_DIR=C:\Program Files\Codex" ^& !SCRIPT_NAME!
echo. echo.
echo %ESC%[93mOptions:%ESC%[%m echo %ESC%[93mOptions:%ESC%[%m
echo - help - show this help echo - help - show this help
echo - VERSION=0.1.7 - codex and cird version to install echo - VERSION=0.1.7 - codex and cird version to install
echo - INSTALL_CIRDL=true - install cirdl echo - CIRDL=true - install cirdl
echo - "INSTALL_DIR=C:\Program Files\Codex" - directory to install binaries echo - "INSTALL_DIR=C:\Program Files\Codex" - directory to install binaries
echo - WINDOWS_LIBS=false - download and install archive without the libs echo - WINDOWS_LIBS=false - download and install archive without the libs
echo - BASE_URL=http://localhost:8080 - custom base URL for binaries downloading
exit /b 0 exit /b 0
) )
@ -80,18 +113,13 @@ set message="Computing version"
call :show_progress %message% call :show_progress %message%
if "%VERSION%" == "latest" ( if "%VERSION%" == "latest" (
for /f delims^=^"^ tokens^=4 %%v in ('curl -Ls %API_BASE_URL%/releases/latest ^| find "tag_name"') do set VERSION=%%v for /f delims^=^"^ tokens^=4 %%v in ('curl -Ls %API_BASE_URL%/releases/latest ^| find "tag_name"') do set VERSION=%%v
) else (
::: Remove trailing spaces
for /l %%v in (1,1,100) do if "!VERSION:~-1!"==" " set VERSION=v!VERSION:~0,-1!
) )
:: Archives and binaries :: Archives and binaries
set message="Computing archives and binaries names" set message="Computing archives and binaries names"
call :show_progress %message% call :show_progress %message%
::: Remove trailing spaces
for /l %%v in (1,1,100) do if "!INSTALL_CIRDL:~-1!"==" " set INSTALL_CIRDL=!INSTALL_CIRDL:~0,-1!
::: Set variables ::: Set variables
if "%INSTALL_CIRDL%" == "true" ( if "%CIRDL%" == "true" (
set "ARCHIVES=%CODEX_ARCHIVE_PREFIX% %CIRDL_ARCHIVE_PREFIX%" set "ARCHIVES=%CODEX_ARCHIVE_PREFIX% %CIRDL_ARCHIVE_PREFIX%"
set "BINARIES=%CODEX_BINARY_PREFIX% %CIRDL_BINARY_PREFIX%" set "BINARIES=%CODEX_BINARY_PREFIX% %CIRDL_BINARY_PREFIX%"
) else ( ) else (
@ -139,7 +167,13 @@ for %%f in (%ARCHIVES%) do (
for %%f in (!ARCHIVE_NAME! !ARCHIVE_NAME!.sha256) do ( for %%f in (!ARCHIVE_NAME! !ARCHIVE_NAME!.sha256) do (
set ARCHIVE=%%f set ARCHIVE=%%f
set DOWNLOAD_URL=!BASE_URL!/releases/download/!VERSION!/!ARCHIVE! echo %BASE_URL% | find /i "https://github.com/" >nul
if !errorlevel! equ 0 (
set DOWNLOAD_URL=%BASE_URL%/releases/download/%VERSION%/!ARCHIVE!
) else (
set DOWNLOAD_URL=%BASE_URL%/%VERSION%/!ARCHIVE!
)
set message="Downloading !ARCHIVE!" set message="Downloading !ARCHIVE!"
call :show_progress !message! call :show_progress !message!
@rem we can't rely on http_code - https://github.com/curl/curl/issues/13845 @rem we can't rely on http_code - https://github.com/curl/curl/issues/13845
@ -169,6 +203,7 @@ for %%f in (%ARCHIVES%) do (
:: Create directory :: Create directory
set message="Creating installation directory %INSTALL_DIR%" set message="Creating installation directory %INSTALL_DIR%"
call :show_progress !message! call :show_progress !message!
echo "INSTALL_DIR - %INSTALL_DIR%"
if not exist %INSTALL_DIR% mkdir %INSTALL_DIR% if not exist %INSTALL_DIR% mkdir %INSTALL_DIR%
if not !errorlevel! == 0 ( if not !errorlevel! == 0 (
call :show_fail !message! "Failed to create %INSTALL_DIR%" call :show_fail !message! "Failed to create %INSTALL_DIR%"
@ -230,6 +265,6 @@ if not %errorlevel% equ 0 (
@rem setx PATH "%PATH%%INSTALL_DIR;" >nul 2>&1 @rem setx PATH "%PATH%%INSTALL_DIR;" >nul 2>&1
) )
:: Delete :: Self delete
:delete :delete
goto 2>nul & del "%~f0" goto 2>nul & del "%~f0"

View File

@ -5,7 +5,7 @@ set -e
# Variables # Variables
VERSION=${VERSION:-latest} VERSION=${VERSION:-latest}
INSTALL_CIRDL=${INSTALL_CIRDL:-false} CIRDL=${CIRDL:-false}
INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin} INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
CODEX_ARCHIVE_PREFIX="codex" CODEX_ARCHIVE_PREFIX="codex"
CIRDL_ARCHIVE_PREFIX="cirdl" CIRDL_ARCHIVE_PREFIX="cirdl"
@ -13,7 +13,7 @@ CODEX_BINARY_PREFIX="codex"
CIRDL_BINARY_PREFIX="cirdl" CIRDL_BINARY_PREFIX="cirdl"
WINDOWS_LIBS=${WINDOWS_LIBS:-false} WINDOWS_LIBS=${WINDOWS_LIBS:-false}
WINDOWS_LIBS_LIST="libstdc++-6.dll libgomp-1.dll libgcc_s_seh-1.dll libwinpthread-1.dll" WINDOWS_LIBS_LIST="libstdc++-6.dll libgomp-1.dll libgcc_s_seh-1.dll libwinpthread-1.dll"
BASE_URL="https://github.com/codex-storage/nim-codex" BASE_URL=${BASE_URL:-https://github.com/codex-storage/nim-codex}
API_BASE_URL="https://api.github.com/repos/codex-storage/nim-codex" API_BASE_URL="https://api.github.com/repos/codex-storage/nim-codex"
TEMP_DIR="${TEMP_DIR:-.}" TEMP_DIR="${TEMP_DIR:-.}"
PROGRESS_MARK="\033[0;36m\u2022\033[0m" PROGRESS_MARK="\033[0;36m\u2022\033[0m"
@ -28,15 +28,16 @@ if [[ $1 == *"h"* ]] ; then
\e[33mUsage:\e[0m \e[33mUsage:\e[0m
${COMMAND} | bash ${COMMAND} | bash
${COMMAND} | VERSION=0.1.7 bash ${COMMAND} | VERSION=0.1.7 bash
${COMMAND} | VERSION=0.1.7 INSTALL_CIRDL=true bash ${COMMAND} | VERSION=0.1.7 CIRDL=true bash
${COMMAND} | bash -s help ${COMMAND} | bash -s help
\e[33mOptions:\e[0m \e[33mOptions:\e[0m
- help - show this help - help - show this help
- VERSION=0.1.7 - codex and cird version to install - VERSION=0.1.7 - codex and cird version to install
- INSTALL_CIRDL=true - install cirdl - CIRDL=true - install cirdl
- INSTALL_DIR=/usr/local/bin - directory to install binaries - INSTALL_DIR=/usr/local/bin - directory to install binaries
- WINDOWS_LIBS=true - download and install archive with libs for windows - WINDOWS_LIBS=true - download and install archive with libs for windows
- BASE_URL=http://localhost:8080 - custom base URL for binaries downloading
" "
exit 0 exit 0
fi fi
@ -77,8 +78,8 @@ show_progress "${message}"
# Archives and binaries # Archives and binaries
message="Compute archives and binaries names" message="Compute archives and binaries names"
show_progress "${message}" show_progress "${message}"
[[ "${INSTALL_CIRDL}" == "true" ]] && ARCHIVES=("${CODEX_ARCHIVE_PREFIX}" "${CIRDL_ARCHIVE_PREFIX}") || ARCHIVES=("${CODEX_ARCHIVE_PREFIX}") [[ "${CIRDL}" == "true" ]] && ARCHIVES=("${CODEX_ARCHIVE_PREFIX}" "${CIRDL_ARCHIVE_PREFIX}") || ARCHIVES=("${CODEX_ARCHIVE_PREFIX}")
[[ "${INSTALL_CIRDL}" == "true" ]] && BINARIES=("${CODEX_BINARY_PREFIX}" "${CIRDL_BINARY_PREFIX}") || BINARIES=("${CODEX_BINARY_PREFIX}") [[ "${CIRDL}" == "true" ]] && BINARIES=("${CODEX_BINARY_PREFIX}" "${CIRDL_BINARY_PREFIX}") || BINARIES=("${CODEX_BINARY_PREFIX}")
show_pass "${message}" show_pass "${message}"
# Get the current OS # Get the current OS
@ -126,10 +127,14 @@ fi
# Download # Download
for ARCHIVE in "${ARCHIVES[@]}"; do for ARCHIVE in "${ARCHIVES[@]}"; do
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}" ARCHIVE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
for FILE in "${FILE_NAME}" "${FILE_NAME}.sha256"; do for FILE in "${ARCHIVE_NAME}" "${ARCHIVE_NAME}.sha256"; do
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${FILE}" if [[ "${BASE_URL}" == *"https://github.com/"* ]]; then
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${FILE}"
else
DOWNLOAD_URL="${BASE_URL}/${VERSION}/${FILE}"
fi
message="Downloading ${FILE}" message="Downloading ${FILE}"
show_progress "${message}" show_progress "${message}"
@ -140,41 +145,41 @@ done
# Checksum # Checksum
for ARCHIVE in "${ARCHIVES[@]}"; do for ARCHIVE in "${ARCHIVES[@]}"; do
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}" ARCHIVE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
message="Verifying checksum for ${FILE_NAME}" message="Verifying checksum for ${ARCHIVE_NAME}"
show_progress "${message}" show_progress "${message}"
EXPECTED_SHA256=$(cat "${TEMP_DIR}/${FILE_NAME}.sha256" | cut -d' ' -f1) EXPECTED_SHA256=$(cat "${TEMP_DIR}/${ARCHIVE_NAME}.sha256" | cut -d' ' -f1)
if [[ "${OS}" == "darwin" ]]; then if [[ "${OS}" == "darwin" ]]; then
ACTUAL_SHA256=$(shasum -a 256 "${TEMP_DIR}/${FILE_NAME}" | cut -d ' ' -f 1) ACTUAL_SHA256=$(shasum -a 256 "${TEMP_DIR}/${ARCHIVE_NAME}" | cut -d ' ' -f 1)
else else
ACTUAL_SHA256=$(sha256sum "${TEMP_DIR}/${FILE_NAME}" | cut -d ' ' -f 1) ACTUAL_SHA256=$(sha256sum "${TEMP_DIR}/${ARCHIVE_NAME}" | cut -d ' ' -f 1)
fi fi
if [[ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]]; then if [[ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]]; then
show_pass "${message}" show_pass "${message}"
else else
show_fail "${message}" "Checksum verification failed for ${FILE_NAME}. Expected: $EXPECTED_SHA256, Got: $ACTUAL_SHA256" show_fail "${message}" "Checksum verification failed for ${ARCHIVE_NAME}. Expected: $EXPECTED_SHA256, Got: $ACTUAL_SHA256"
fi fi
done done
# Extract # Extract
for ARCHIVE in "${ARCHIVES[@]}"; do for ARCHIVE in "${ARCHIVES[@]}"; do
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}" ARCHIVE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
message="Extracting ${FILE_NAME}" message="Extracting ${ARCHIVE_NAME}"
show_progress "${message}" show_progress "${message}"
if [[ "${OS}" == "windows" ]]; then if [[ "${OS}" == "windows" ]]; then
if unzip -v &> /dev/null; then if unzip -v &> /dev/null; then
unzip -q -o "${TEMP_DIR}/${FILE_NAME}" -d "${TEMP_DIR}" unzip -q -o "${TEMP_DIR}/${ARCHIVE_NAME}" -d "${TEMP_DIR}"
[[ $? -ne 0 ]] && show_fail "${message}" [[ $? -ne 0 ]] && show_fail "${message}"
else else
C:/Windows/system32/tar.exe -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}" C:/Windows/system32/tar.exe -xzf "${TEMP_DIR}/${ARCHIVE_NAME}" -C "${TEMP_DIR}"
[[ $? -ne 0 ]] && show_fail "${message}" [[ $? -ne 0 ]] && show_fail "${message}"
fi fi
else else
tar -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}" tar -xzf "${TEMP_DIR}/${ARCHIVE_NAME}" -C "${TEMP_DIR}"
[[ $? -ne 0 ]] && show_fail "${message}" [[ $? -ne 0 ]] && show_fail "${message}"
fi fi
show_pass "${message}" show_pass "${message}"
@ -182,15 +187,15 @@ done
# Install # Install
for BINARY in "${BINARIES[@]}"; do for BINARY in "${BINARIES[@]}"; do
FILE_NAME="${BINARY}-${BINARY_SUFFIX}" BINARY_NAME="${BINARY}-${BINARY_SUFFIX}"
INSTALL_PATH="${INSTALL_DIR}/${BINARY}" INSTALL_PATH="${INSTALL_DIR}/${BINARY}"
# Install # Install
message="Installing ${FILE_NAME} to ${INSTALL_PATH}" message="Installing ${BINARY_NAME} to ${INSTALL_PATH}"
show_progress "${message}" show_progress "${message}"
if ! (mkdir -p "${INSTALL_DIR}" && install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}") 2> /dev/null; then if ! (mkdir -p "${INSTALL_DIR}" && install -m 755 "${TEMP_DIR}/${BINARY_NAME}" "${INSTALL_PATH}") 2> /dev/null; then
$(sudo -n true 2>/dev/null) || TRIM=2 $(sudo -n true 2>/dev/null) || TRIM=2
sudo mkdir -p "${INSTALL_DIR}" && sudo install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}" sudo mkdir -p "${INSTALL_DIR}" && sudo install -m 755 "${TEMP_DIR}/${BINARY_NAME}" "${INSTALL_PATH}"
[[ $? -ne 0 ]] && show_fail "${message}" [[ $? -ne 0 ]] && show_fail "${message}"
fi fi
show_pass "${message}" show_pass "${message}"
@ -210,8 +215,8 @@ fi
message="Cleanup" message="Cleanup"
show_progress "${message}" show_progress "${message}"
for BINARY in "${BINARIES[@]}"; do for BINARY in "${BINARIES[@]}"; do
FILE_NAME="${BINARY}-${BINARY_SUFFIX}" ARCHIVE_NAME="${BINARY}-${BINARY_SUFFIX}"
rm -f "${TEMP_DIR}/${FILE_NAME}"* rm -f "${TEMP_DIR}/${ARCHIVE_NAME}"*
[[ $? -ne 0 ]] && show_fail "${message}" [[ $? -ne 0 ]] && show_fail "${message}"
done done
show_pass "${message}" show_pass "${message}"