mirror of
https://github.com/codex-storage/get-codex.git
synced 2025-02-22 14:08:09 +00:00
Refactoring installation script for Linux/macOS (#6)
* Add .gitignore * Add install commands to the Readme Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com> * Refactor installation script for Linux/macOS --------- Signed-off-by: Slava <20563034+veaceslavdoina@users.noreply.github.com>
This commit is contained in:
parent
9a10965f1d
commit
25dcb87d78
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# Archives
|
||||
*.tar.gz
|
||||
*.zip
|
||||
|
||||
# Checksums
|
||||
*.sha256
|
||||
|
||||
# Binaries
|
||||
codex-v*
|
||||
codex
|
||||
cirdl
|
28
README.md
28
README.md
@ -0,0 +1,28 @@
|
||||
# Get Codex
|
||||
|
||||
### Linux and macOS
|
||||
|
||||
```shell
|
||||
# latest version
|
||||
curl -s https://get.codex.storage/install.sh | bash
|
||||
```
|
||||
|
||||
```shell
|
||||
# specific version
|
||||
curl -s https://get.codex.storage/install.sh | VERSION=0.1.7 bash
|
||||
```
|
||||
|
||||
```shell
|
||||
# latest codex and cirdl
|
||||
curl -s https://get.codex.storage/install.sh | INSTALL_CIRDL=true bash
|
||||
```
|
||||
|
||||
```shell
|
||||
# codex and cirdl with required libraries on Windows with msys2
|
||||
curl -s https://get.codex.storage/install.sh | WINDOWS_LIBS=true INSTALL_CIRDL=true bash
|
||||
```
|
||||
|
||||
```shell
|
||||
# help
|
||||
curl -s https://get.codex.storage/install.sh | bash -s help
|
||||
```
|
140
install.sh
140
install.sh
@ -1,81 +1,116 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Install Codex on Linux, macOS, and Windows(msys2)
|
||||
|
||||
# Variables
|
||||
VERSION=${VERSION:-latest}
|
||||
INSTALL_CIRDL=${INSTALL_CIRDL:-false}
|
||||
INSTALL_DIR=${INSTALL_DIR:-/usr/local/bin}
|
||||
CODEX_ARCHIVE_PREFIX="codex"
|
||||
CIRDL_ARCHIVE_PREFIX="cirdl"
|
||||
CODEX_BINARY_PREFIX="codex"
|
||||
CIRDL_BINARY_PREFIX="cirdl"
|
||||
WINDOWS_LIBS=${WINDOWS_LIBS:-false}
|
||||
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"
|
||||
API_BASE_URL="https://api.github.com/repos/codex-storage/nim-codex"
|
||||
TEMP_DIR="${TEMP_DIR:-.}"
|
||||
|
||||
PROGRESS_MARK="\033[0;36m\u2022\033[0m"
|
||||
PASS_MARK="\033[0;32m\u2714\033[0m"
|
||||
FAIL_MARK="\033[0;31m\u2718\033[0m"
|
||||
|
||||
# Help
|
||||
if [[ $1 == *"h"* ]] ; then
|
||||
echo "Usage:
|
||||
echo -e "
|
||||
\e[33mUsage:\e[0m
|
||||
curl https://get.codex.storage/`basename $0` | bash
|
||||
curl https://get.codex.storage/`basename $0` | VERSION=0.1.7 bash
|
||||
curl https://get.codex.storage/`basename $0` | VERSION=0.1.7 INSTALL_CIRDL=true bash"
|
||||
curl https://get.codex.storage/`basename $0` | VERSION=0.1.7 INSTALL_CIRDL=true bash
|
||||
curl https://get.codex.storage/`basename $0` | bash -s help
|
||||
|
||||
\e[33mOptions:\e[0m
|
||||
- help - show this help
|
||||
- VERSION=0.1.7 - codex and cird version to install
|
||||
- INSTALL_CIRDL=true - install cirdl
|
||||
- INSTALL_DIR=/usr/local/bin - directory to install binaries
|
||||
- WINDOWS_LIBS=true - download and install archive with libs for windows
|
||||
"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Banners
|
||||
start_banner() {
|
||||
echo -e "\n This script will download and install ${ARCHIVES[@]} ${VERSION} to ${INSTALL_DIR}\n"
|
||||
# Show
|
||||
show_start() {
|
||||
echo -e "\n \e[4m${1}\e[0m\n"
|
||||
}
|
||||
|
||||
end_banner() {
|
||||
echo -e "\n Setup completed successfully!\n"
|
||||
show_progress() {
|
||||
echo -e " ${PROGRESS_MARK} ${1}"
|
||||
}
|
||||
|
||||
# Error
|
||||
error() {
|
||||
echo -e "\033[31m \n Error: $1"
|
||||
echo -e "\033[0m"
|
||||
show_pass() {
|
||||
echo -e "\r\e[1A\e[0K ${PASS_MARK} ${1}"
|
||||
}
|
||||
|
||||
show_fail() {
|
||||
echo -e "\r\e[1A\e[0K ${FAIL_MARK} ${1}"
|
||||
[[ -n "${2}" ]] && echo -e "\e[31m \n Error: ${2}\e[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Archives and binaries
|
||||
[[ "${INSTALL_CIRDL}" == "true" ]] && ARCHIVES=("codex" "cirdl") || ARCHIVES=("codex")
|
||||
[[ "${INSTALL_CIRDL}" == "true" ]] && BINARIES=("codex" "cirdl") || BINARIES=("codex")
|
||||
|
||||
# Version
|
||||
[[ "${VERSION}" == "latest" ]] && VERSION=$(curl -s ${API_BASE_URL}/releases/latest | grep tag_name | cut -d '"' -f 4) || VERSION="v${VERSION}"
|
||||
show_end() {
|
||||
echo -e "\n\e[32m ${1}\e[0m\n"
|
||||
}
|
||||
|
||||
# Start
|
||||
start_banner "${ARCHIVES[@]}" "${VERSION}" "${INSTALL_DIR}"
|
||||
show_start "Installing Codex..."
|
||||
|
||||
# Version
|
||||
message="Compute version"
|
||||
show_progress "${message}"
|
||||
[[ "${VERSION}" == "latest" ]] && VERSION=$(curl -s ${API_BASE_URL}/releases/latest | grep tag_name | cut -d '"' -f 4) || VERSION="v${VERSION}"
|
||||
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||
|
||||
# Archives and binaries
|
||||
message="Compute archives and binaries names"
|
||||
show_progress "${message}"
|
||||
[[ "${INSTALL_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}")
|
||||
show_pass "${message}"
|
||||
|
||||
# Get the current OS
|
||||
echo " - Checking the current OS"
|
||||
message="Checking the current OS"
|
||||
show_progress "${message}"
|
||||
case "$(uname -s)" in
|
||||
Linux*) OS="linux" ;;
|
||||
Darwin*) OS="darwin" ;;
|
||||
CYGWIN*|MINGW*|MSYS*) OS="windows" ;;
|
||||
*) error "Unsupported OS $(uname -s)" ;;
|
||||
*) show_fail "${message}" "Unsupported OS $(uname -s)" ;;
|
||||
esac
|
||||
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||
|
||||
# Get the current architecture
|
||||
echo " - Checking the current architecture"
|
||||
message="Checking the current architecture"
|
||||
show_progress "${message}"
|
||||
case "$(uname -m)" in
|
||||
x86_64|amd64) ARCHITECTURE="amd64" ;;
|
||||
arm64|aarch64) ARCHITECTURE="arm64" ;;
|
||||
*) error "Unsupported architecture: $(uname -m)" ;;
|
||||
*) show_fail "${message}" "Unsupported architecture: $(uname -m)" ;;
|
||||
esac
|
||||
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||
|
||||
# Not supported
|
||||
if [[ "${OS}" == "windows" && "${ARCHITECTURE}" == "arm64" ]]; then
|
||||
error "Windows ${ARCHITECTURE} is not supported at the moment"
|
||||
show_fail "${message}" "Windows ${ARCHITECTURE} is not supported at the moment"
|
||||
fi
|
||||
|
||||
# Prerequisites
|
||||
echo " - Checking installed prerequisites"
|
||||
if [[ "${OS}" != "windows" && $(command -v tar &> /dev/null) ]]; then
|
||||
error "Please install tar to continue installation"
|
||||
message="Checking prerequisites"
|
||||
show_progress "${message}"
|
||||
if [[ ("${OS}" != "windows") ]]; then
|
||||
$(command -v tar &> /dev/null) || show_fail "${message}" "Please install tar to continue installation"
|
||||
fi
|
||||
show_pass "${message}"
|
||||
|
||||
# Archive and binaries names
|
||||
if [[ "$OS" == "windows" ]]; then
|
||||
@ -93,15 +128,19 @@ for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||
for FILE in "${FILE_NAME}" "${FILE_NAME}.sha256"; do
|
||||
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${FILE}"
|
||||
|
||||
echo " - Downloading ${FILE}"
|
||||
message="Downloading ${FILE}"
|
||||
show_progress "${message}"
|
||||
http_code=$(curl --write-out "%{http_code}" --connect-timeout 5 --retry 5 -sL "${DOWNLOAD_URL}" -o "${TEMP_DIR}/${FILE}")
|
||||
[[ "${http_code}" -ne 200 ]] && error "Failed to download ${FILE}"
|
||||
[[ "${http_code}" -eq 200 ]] && show_pass "${message}" || show_fail "${message}" "Failed to download ${DOWNLOAD_URL}"
|
||||
done
|
||||
done
|
||||
|
||||
# Checksum
|
||||
for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
|
||||
message="Verifying checksum for ${FILE_NAME}"
|
||||
show_progress "${message}"
|
||||
|
||||
EXPECTED_SHA256=$(cat "${TEMP_DIR}/${FILE_NAME}.sha256" | cut -d' ' -f1)
|
||||
if [[ "${OS}" == "darwin" ]]; then
|
||||
ACTUAL_SHA256=$(shasum -a 256 "${TEMP_DIR}/${FILE_NAME}" | cut -d ' ' -f 1)
|
||||
@ -109,28 +148,33 @@ for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||
ACTUAL_SHA256=$(sha256sum "${TEMP_DIR}/${FILE_NAME}" | cut -d ' ' -f 1)
|
||||
fi
|
||||
|
||||
if [ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]; then
|
||||
echo " - Verifying checksum for ${FILE_NAME}"
|
||||
if [[ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]]; then
|
||||
show_pass "${message}"
|
||||
else
|
||||
error " - Checksum verification failed for ${TEMP_DIR}/${FILE_NAME}. Expected: $EXPECTED_SHA256, Got: $ACTUAL_SHA256"
|
||||
show_fail "${message}" "Checksum verification failed for ${FILE_NAME}. Expected: $EXPECTED_SHA256, Got: $ACTUAL_SHA256"
|
||||
fi
|
||||
done
|
||||
|
||||
# Extract
|
||||
for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
|
||||
echo " - Extracting ${FILE_NAME}"
|
||||
|
||||
message="Extracting ${FILE_NAME}"
|
||||
show_progress "${message}"
|
||||
|
||||
if [[ "${OS}" == "windows" ]]; then
|
||||
if unzip -v &> /dev/null; then
|
||||
unzip -o "${TEMP_DIR}/${FILE_NAME}" -d "${TEMP_DIR}"
|
||||
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||
else
|
||||
C:/Windows/system32/tar.exe -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}"
|
||||
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||
fi
|
||||
else
|
||||
tar -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}"
|
||||
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||
fi
|
||||
show_pass "${message}"
|
||||
done
|
||||
|
||||
# Install
|
||||
@ -138,32 +182,38 @@ for BINARY in "${BINARIES[@]}"; do
|
||||
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
||||
INSTALL_PATH="${INSTALL_DIR}/${BINARY}"
|
||||
|
||||
# Create the install directory
|
||||
[[ -d "${INSTALL_DIR}" ]] || mkdir -p "${INSTALL_DIR}"
|
||||
|
||||
# Install
|
||||
echo " - Installing ${FILE_NAME} to ${INSTALL_PATH}"
|
||||
if ! install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}" 2> /dev/null; then
|
||||
sudo install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}"
|
||||
message="Installing ${FILE_NAME} to ${INSTALL_PATH}"
|
||||
show_progress "${message}"
|
||||
if ! (mkdir -p "${INSTALL_DIR}" && install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}") 2> /dev/null; then
|
||||
sudo mkdir -p "${INSTALL_DIR}" && sudo install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}"
|
||||
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||
fi
|
||||
show_pass "${message}"
|
||||
done
|
||||
|
||||
# Windows libs
|
||||
if [[ "${OS}" == "windows" && "${WINDOWS_LIBS}" == "true" ]]; then
|
||||
echo " - Copy libs to ${MINGW_PREFIX}/bin"
|
||||
message="Copy libs to ${MINGW_PREFIX}/bin"
|
||||
show_progress "${message}"
|
||||
for LIB in ${WINDOWS_LIBS_LIST}; do
|
||||
mv "${TEMP_DIR}/${LIB}" "${MINGW_PREFIX}/bin"
|
||||
done
|
||||
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||
fi
|
||||
done
|
||||
|
||||
# Cleanup
|
||||
message="Cleanup"
|
||||
show_progress "${message}"
|
||||
for BINARY in "${BINARIES[@]}"; do
|
||||
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
||||
rm -f "${TEMP_DIR}/${FILE_NAME}"*
|
||||
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||
done
|
||||
show_pass "${message}"
|
||||
|
||||
# End
|
||||
end_banner
|
||||
show_end "Setup completed successfully!"
|
||||
|
||||
# Dependencies
|
||||
dependencies=()
|
||||
@ -179,3 +229,9 @@ if [[ ${#dependencies[@]} -ne 0 ]]; then
|
||||
echo -e " Please inatall the following dpependencies:
|
||||
${dependencies[@]}\n"
|
||||
fi
|
||||
|
||||
# Path
|
||||
[[ "${INSTALL_DIR}" == "." ]] && INSTALL_DIR=$(pwd)
|
||||
if [[ $PATH != *"${INSTALL_DIR}"* ]]; then
|
||||
echo -e " Note: Please add install directory '"${INSTALL_DIR}"' to your PATH\n"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user