mirror of
https://github.com/codex-storage/get-codex.git
synced 2025-02-23 06:28:16 +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
|
||||||
|
```
|
148
install.sh
148
install.sh
@ -1,81 +1,116 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# Install Codex on Linux, macOS, and Windows(msys2)
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
VERSION=${VERSION:-latest}
|
VERSION=${VERSION:-latest}
|
||||||
INSTALL_CIRDL=${INSTALL_CIRDL:-false}
|
INSTALL_CIRDL=${INSTALL_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"
|
||||||
|
CODEX_BINARY_PREFIX="codex"
|
||||||
|
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="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"
|
||||||
|
PASS_MARK="\033[0;32m\u2714\033[0m"
|
||||||
|
FAIL_MARK="\033[0;31m\u2718\033[0m"
|
||||||
|
|
||||||
# Help
|
# Help
|
||||||
if [[ $1 == *"h"* ]] ; then
|
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` | bash
|
||||||
curl https://get.codex.storage/`basename $0` | VERSION=0.1.7 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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Banners
|
# Show
|
||||||
start_banner() {
|
show_start() {
|
||||||
echo -e "\n This script will download and install ${ARCHIVES[@]} ${VERSION} to ${INSTALL_DIR}\n"
|
echo -e "\n \e[4m${1}\e[0m\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
end_banner() {
|
show_progress() {
|
||||||
echo -e "\n Setup completed successfully!\n"
|
echo -e " ${PROGRESS_MARK} ${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Error
|
show_pass() {
|
||||||
error() {
|
echo -e "\r\e[1A\e[0K ${PASS_MARK} ${1}"
|
||||||
echo -e "\033[31m \n Error: $1"
|
}
|
||||||
echo -e "\033[0m"
|
|
||||||
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Archives and binaries
|
show_end() {
|
||||||
[[ "${INSTALL_CIRDL}" == "true" ]] && ARCHIVES=("codex" "cirdl") || ARCHIVES=("codex")
|
echo -e "\n\e[32m ${1}\e[0m\n"
|
||||||
[[ "${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}"
|
|
||||||
|
|
||||||
# Start
|
# 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
|
# Get the current OS
|
||||||
echo " - Checking the current OS"
|
message="Checking the current OS"
|
||||||
|
show_progress "${message}"
|
||||||
case "$(uname -s)" in
|
case "$(uname -s)" in
|
||||||
Linux*) OS="linux" ;;
|
Linux*) OS="linux" ;;
|
||||||
Darwin*) OS="darwin" ;;
|
Darwin*) OS="darwin" ;;
|
||||||
CYGWIN*|MINGW*|MSYS*) OS="windows" ;;
|
CYGWIN*|MINGW*|MSYS*) OS="windows" ;;
|
||||||
*) error "Unsupported OS $(uname -s)" ;;
|
*) show_fail "${message}" "Unsupported OS $(uname -s)" ;;
|
||||||
esac
|
esac
|
||||||
|
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||||
|
|
||||||
# Get the current architecture
|
# Get the current architecture
|
||||||
echo " - Checking the current architecture"
|
message="Checking the current architecture"
|
||||||
|
show_progress "${message}"
|
||||||
case "$(uname -m)" in
|
case "$(uname -m)" in
|
||||||
x86_64|amd64) ARCHITECTURE="amd64" ;;
|
x86_64|amd64) ARCHITECTURE="amd64" ;;
|
||||||
arm64|aarch64) ARCHITECTURE="arm64" ;;
|
arm64|aarch64) ARCHITECTURE="arm64" ;;
|
||||||
*) error "Unsupported architecture: $(uname -m)" ;;
|
*) show_fail "${message}" "Unsupported architecture: $(uname -m)" ;;
|
||||||
esac
|
esac
|
||||||
|
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||||
|
|
||||||
# Not supported
|
# Not supported
|
||||||
if [[ "${OS}" == "windows" && "${ARCHITECTURE}" == "arm64" ]]; then
|
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
|
fi
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
echo " - Checking installed prerequisites"
|
message="Checking prerequisites"
|
||||||
if [[ "${OS}" != "windows" && $(command -v tar &> /dev/null) ]]; then
|
show_progress "${message}"
|
||||||
error "Please install tar to continue installation"
|
if [[ ("${OS}" != "windows") ]]; then
|
||||||
|
$(command -v tar &> /dev/null) || show_fail "${message}" "Please install tar to continue installation"
|
||||||
fi
|
fi
|
||||||
|
show_pass "${message}"
|
||||||
|
|
||||||
# Archive and binaries names
|
# Archive and binaries names
|
||||||
if [[ "$OS" == "windows" ]]; then
|
if [[ "$OS" == "windows" ]]; then
|
||||||
@ -93,15 +128,19 @@ for ARCHIVE in "${ARCHIVES[@]}"; do
|
|||||||
for FILE in "${FILE_NAME}" "${FILE_NAME}.sha256"; do
|
for FILE in "${FILE_NAME}" "${FILE_NAME}.sha256"; do
|
||||||
DOWNLOAD_URL="${BASE_URL}/releases/download/${VERSION}/${FILE}"
|
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=$(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
|
||||||
done
|
done
|
||||||
|
|
||||||
# Checksum
|
# Checksum
|
||||||
for ARCHIVE in "${ARCHIVES[@]}"; do
|
for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||||
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
|
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)
|
EXPECTED_SHA256=$(cat "${TEMP_DIR}/${FILE_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}/${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)
|
ACTUAL_SHA256=$(sha256sum "${TEMP_DIR}/${FILE_NAME}" | cut -d ' ' -f 1)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]; then
|
if [[ "$ACTUAL_SHA256" == "$EXPECTED_SHA256" ]]; then
|
||||||
echo " - Verifying checksum for ${FILE_NAME}"
|
show_pass "${message}"
|
||||||
else
|
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
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Extract
|
# Extract
|
||||||
for ARCHIVE in "${ARCHIVES[@]}"; do
|
for ARCHIVE in "${ARCHIVES[@]}"; do
|
||||||
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
|
FILE_NAME="${ARCHIVE}-${ARCHIVE_SUFFIX}"
|
||||||
echo " - Extracting ${FILE_NAME}"
|
|
||||||
|
|
||||||
|
message="Extracting ${FILE_NAME}"
|
||||||
|
show_progress "${message}"
|
||||||
|
|
||||||
if [[ "${OS}" == "windows" ]]; then
|
if [[ "${OS}" == "windows" ]]; then
|
||||||
if unzip -v &> /dev/null; then
|
if unzip -v &> /dev/null; then
|
||||||
unzip -o "${TEMP_DIR}/${FILE_NAME}" -d "${TEMP_DIR}"
|
unzip -o "${TEMP_DIR}/${FILE_NAME}" -d "${TEMP_DIR}"
|
||||||
|
[[ $? -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}/${FILE_NAME}" -C "${TEMP_DIR}"
|
||||||
|
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
tar -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}"
|
tar -xzf "${TEMP_DIR}/${FILE_NAME}" -C "${TEMP_DIR}"
|
||||||
|
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||||
fi
|
fi
|
||||||
|
show_pass "${message}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
@ -138,32 +182,38 @@ for BINARY in "${BINARIES[@]}"; do
|
|||||||
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
||||||
INSTALL_PATH="${INSTALL_DIR}/${BINARY}"
|
INSTALL_PATH="${INSTALL_DIR}/${BINARY}"
|
||||||
|
|
||||||
# Create the install directory
|
|
||||||
[[ -d "${INSTALL_DIR}" ]] || mkdir -p "${INSTALL_DIR}"
|
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
echo " - Installing ${FILE_NAME} to ${INSTALL_PATH}"
|
message="Installing ${FILE_NAME} to ${INSTALL_PATH}"
|
||||||
if ! install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}" 2> /dev/null; then
|
show_progress "${message}"
|
||||||
sudo install -m 755 "${TEMP_DIR}/${FILE_NAME}" "${INSTALL_PATH}"
|
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
|
fi
|
||||||
|
show_pass "${message}"
|
||||||
|
done
|
||||||
|
|
||||||
# Windows libs
|
# Windows libs
|
||||||
if [[ "${OS}" == "windows" && "${WINDOWS_LIBS}" == "true" ]]; then
|
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
|
for LIB in ${WINDOWS_LIBS_LIST}; do
|
||||||
mv "${TEMP_DIR}/${LIB}" "${MINGW_PREFIX}/bin"
|
mv "${TEMP_DIR}/${LIB}" "${MINGW_PREFIX}/bin"
|
||||||
done
|
done
|
||||||
fi
|
[[ $? -eq 0 ]] && show_pass "${message}" || show_fail "${message}"
|
||||||
done
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
message="Cleanup"
|
||||||
|
show_progress "${message}"
|
||||||
for BINARY in "${BINARIES[@]}"; do
|
for BINARY in "${BINARIES[@]}"; do
|
||||||
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
FILE_NAME="${BINARY}-${BINARY_SUFFIX}"
|
||||||
rm -f "${TEMP_DIR}/${FILE_NAME}"*
|
rm -f "${TEMP_DIR}/${FILE_NAME}"*
|
||||||
|
[[ $? -ne 0 ]] && show_fail "${message}"
|
||||||
done
|
done
|
||||||
|
show_pass "${message}"
|
||||||
|
|
||||||
# End
|
# End
|
||||||
end_banner
|
show_end "Setup completed successfully!"
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
dependencies=()
|
dependencies=()
|
||||||
@ -176,6 +226,12 @@ for BINARY in "${BINARIES[@]}"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#dependencies[@]} -ne 0 ]]; then
|
if [[ ${#dependencies[@]} -ne 0 ]]; then
|
||||||
echo -e "Please inatall the following dpependencies:
|
echo -e " Please inatall the following dpependencies:
|
||||||
${dependencies[@]}\n"
|
${dependencies[@]}\n"
|
||||||
fi
|
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