From 5b5c566f185602c1baa49d719043547f80ccb1cf Mon Sep 17 00:00:00 2001 From: S Anand Date: Wed, 11 Jan 2023 19:49:05 +0800 Subject: [PATCH 01/18] ENH: Add a base Linux setup instance --- pkg/setup.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 pkg/setup.sh diff --git a/pkg/setup.sh b/pkg/setup.sh new file mode 100644 index 00000000..f6873cfb --- /dev/null +++ b/pkg/setup.sh @@ -0,0 +1,117 @@ +# !/bin/bash + +# TODO: Anaconda version should be a variable +# TODO: Consider miniconda instead of Anaconda +# Set the repo URL for the anaconda download +repo_url="https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh" + +# Check if the user is the root user +if [ "$(id -u)" -ne 0 ]; then + # If the user is not the root user, set the prefix to "sudo" + # TODO: Prefer "doas" for alpine / Docker + prefix="sudo" +else + # If the user is the root user, set the prefix to an empty string + prefix="" +fi + +# TODO: Set up distro-specific scripts for Debian, CentOS, Alpine, etc. +# TODO: Based on the distro, call the relevant one +# Set the package manager to use +distro=$(awk -F= '/^NAME/{print $2}' /etc/os-release) +if [[ $distro =~ "Debian" ]]; then + echo "OS found is Debian" + package_manager=apt + package_type=deb + user=admin +elif [[ $distro =~ "CentOS" ]]; then + echo "OS found is CentOS" + package_manager=yum + package_type=rpm + user=centos +else + # Print an error message if the package manager is not recognized + echo "Error: Unable to determine package manager" + exit 1 +fi + +# Update the package manager listing +echo "Update the package registries list" +echo "$prefix $package_manager update -y" +$prefix $package_manager update -y + +# If curl is not installed, install it +if ! command -v curl > /dev/null 2>&1; then + echo "$prefix $package_manager install -y curl" + $prefix $package_manager install -y curl +fi +echo "curl ${repo_url} -o /tmp/conda.sh" +curl $repo_url -o /tmp/conda.sh + +# Run the Anaconda installer with the '-b' flag to run it in batch mode without prompts +echo "bash /tmp/conda.sh -b" +bash /tmp/conda.sh -b + +# TODO: You might be able to eliminate this via `/path/to/conda init && source .bashrc` +# Add Anaconda to the PATH +echo "Setting environment variable for anaconda" +$prefix echo 'export PATH="/home/${user}/anaconda3/bin:$PATH"' >> /home/$user/.bashrc +$prefix echo ". /home/${user}/anaconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc +$prefix echo "conda activate base" >> /home/$user/.bashrc +# Activate the base environment +echo "source /home/$user/.bashrc" +source /home/$user/.bashrc +if [ "$package_type" == "deb" ]; then + # Activating conda environment in debian + echo "Activating conda environment in debian" + source /home/$user/anaconda3/bin/activate base +fi + +echo "conda --version" +conda --version +echo "python --version" +python --version +echo "pip --version" +pip --version +echo "pip install --upgrade pip" +pip install --upgrade pip + +# remove installation file + +echo "$prefix rm -rf /tmp/conda.sh" +$prefix rm -rf /tmp/conda.sh + +# TODO: Allow the user to specify version of Gramex +# Install Gramex +GRAMEX_VERSION=1.86.1 +pip install gramex<="$GRAMEX_VERSION" gramexenterprise<="$GRAMEX_VERSION" +pip cache purge + +# Accept the Gramex Enterprise license +gramex license accept && \ + +# install Nodejs +echo "Installing Nodejs" +curl -sL | sudo bash - + +# TODO: Add the following dependencies +# # icu-data-full is required for comicgen -> fontkit to run TextDecoder('ascii') +# # https://build.alpinelinux.org/buildlogs/build-edge-x86/main/nodejs/nodejs-16.18.0-r1.log +# icu-data-full \ +# # Install dependencies for Chromium on Alpine +# chromium nss freetype harfbuzz ca-certificates ttf-freefont && +$prefix $package_manager install -y gcc g++ make nodejs + +echo "node --version" +node --version +echo "npm --version" +npm --version + +# Allow `npm install -g` to work without sudo by installing to ~/.npm-packages +mkdir -p ~/.npm-packages && \ +npm config set prefix "${HOME_DIR}/.npm-packages" && \ + +gramex setup --all + +# Clean up npm cache +npm cache clean --force From 85f6bc7793996cf9b487c9a872b2cc696870f3ed Mon Sep 17 00:00:00 2001 From: S Anand Date: Wed, 11 Jan 2023 19:51:32 +0800 Subject: [PATCH 02/18] TST: add test instructions --- pkg/testing.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pkg/testing.md diff --git a/pkg/testing.md b/pkg/testing.md new file mode 100644 index 00000000..0b2ebd39 --- /dev/null +++ b/pkg/testing.md @@ -0,0 +1,10 @@ +# Testing setup + +To test this on Ubuntu: + +```bash +docker run -it --rm -v $(pwd):/app -w /app ubuntu bash + +# add user +./pkg/setup.sh +``` From d9d92c57f535012a67374be3829867401ed90cfd Mon Sep 17 00:00:00 2001 From: Shraddheya Shrivastava Date: Wed, 11 Jan 2023 21:02:58 +0530 Subject: [PATCH 03/18] adding test runnign steps --- pkg/setup.sh | 80 +++++++++++++++++++++++++++++++------------------- pkg/testing.md | 35 ++++++++++++++++++---- 2 files changed, 80 insertions(+), 35 deletions(-) diff --git a/pkg/setup.sh b/pkg/setup.sh index f6873cfb..33026841 100644 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -1,5 +1,14 @@ # !/bin/bash +# Declare an associative array for OS-specific default users +declare -A users_map + +# Set the default users for each OS +users_map["ubuntu"]="ubuntu" +users_map["debian"]="admin" +users_map["centos"]="centos" +users_map["alpine"]="root" + # TODO: Anaconda version should be a variable # TODO: Consider miniconda instead of Anaconda # Set the repo URL for the anaconda download @@ -15,57 +24,67 @@ else prefix="" fi + # TODO: Set up distro-specific scripts for Debian, CentOS, Alpine, etc. # TODO: Based on the distro, call the relevant one # Set the package manager to use -distro=$(awk -F= '/^NAME/{print $2}' /etc/os-release) -if [[ $distro =~ "Debian" ]]; then - echo "OS found is Debian" - package_manager=apt +if command -v apt-get > /dev/null 2>&1; then + echo "The OS supports 'apt'." + echo "Updating the pakcage indices." package_type=deb - user=admin -elif [[ $distro =~ "CentOS" ]]; then - echo "OS found is CentOS" + package_manager=apt + $prefix apt update -qq -y +elif command -v yum > /dev/null 2>&1; then + echo "The OS supports 'yum'" + package_type=rpm package_manager=yum +elif command -v dnf > /dev/null 2>&1; then + echo "The OS supports 'dnf'" package_type=rpm - user=centos + package_manager=dnf else - # Print an error message if the package manager is not recognized echo "Error: Unable to determine package manager" exit 1 fi -# Update the package manager listing -echo "Update the package registries list" -echo "$prefix $package_manager update -y" -$prefix $package_manager update -y +# Read the ID field from /etc/os-release +os_id=$(grep ^ID= /etc/os-release | awk -F= '{ print $2 }') + +# Remove the surrounding quotes from the ID string +os_id="${os_id%\"}" +os_id="${os_id#\"}" + +# Set the user variable to the default user for the current OS +user=${users_map[$os_id]} +echo "The Os detected is '${os_id}', hence the default user is '${user}'" # If curl is not installed, install it if ! command -v curl > /dev/null 2>&1; then echo "$prefix $package_manager install -y curl" $prefix $package_manager install -y curl fi -echo "curl ${repo_url} -o /tmp/conda.sh" +echo "Download anaconda installer\ncurl ${repo_url} -o /tmp/conda.sh" curl $repo_url -o /tmp/conda.sh # Run the Anaconda installer with the '-b' flag to run it in batch mode without prompts -echo "bash /tmp/conda.sh -b" +echo "Install Anaconda\nbash /tmp/conda.sh -b" bash /tmp/conda.sh -b -# TODO: You might be able to eliminate this via `/path/to/conda init && source .bashrc` # Add Anaconda to the PATH -echo "Setting environment variable for anaconda" -$prefix echo 'export PATH="/home/${user}/anaconda3/bin:$PATH"' >> /home/$user/.bashrc -$prefix echo ". /home/${user}/anaconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc -$prefix echo "conda activate base" >> /home/$user/.bashrc -# Activate the base environment -echo "source /home/$user/.bashrc" +/home/${user}/anaconda3/bin/conda init bash source /home/$user/.bashrc -if [ "$package_type" == "deb" ]; then - # Activating conda environment in debian - echo "Activating conda environment in debian" - source /home/$user/anaconda3/bin/activate base -fi +# TODO: You might be able to eliminate this via `/path/to/conda init && source .bashrc` +# echo "Setting environment variable for anaconda" +# $prefix echo 'export PATH="/home/${user}/anaconda3/bin:$PATH"' >> /home/$user/.bashrc +# $prefix echo ". /home/${user}/anaconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc +# $prefix echo "conda activate base" >> /home/$user/.bashrc +# # Activate the base environment +# echo "source /home/$user/.bashrc" +# if [ "$package_type" == "deb" ]; then +# # Activating conda environment in debian +# echo "Activating conda environment in debian" +# source /home/$user/anaconda3/bin/activate base +# fi echo "conda --version" conda --version @@ -83,12 +102,13 @@ $prefix rm -rf /tmp/conda.sh # TODO: Allow the user to specify version of Gramex # Install Gramex -GRAMEX_VERSION=1.86.1 -pip install gramex<="$GRAMEX_VERSION" gramexenterprise<="$GRAMEX_VERSION" +echo "GRAMEX_VERSION=\"1.86.1\" pip install gramex<=\"${GRAMEX_VERSION}\" gramexenterprise<=\"${GRAMEX_VERSION}\"" +GRAMEX_VERSION="1.86.1" +pip install "gramex<=${GRAMEX_VERSION}" "gramexenterprise<=${GRAMEX_VERSION}" pip cache purge # Accept the Gramex Enterprise license -gramex license accept && \ +gramex license accept # install Nodejs echo "Installing Nodejs" diff --git a/pkg/testing.md b/pkg/testing.md index 0b2ebd39..4d76fd9b 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -2,9 +2,34 @@ To test this on Ubuntu: -```bash -docker run -it --rm -v $(pwd):/app -w /app ubuntu bash +- Disable path conversion in ***GIT BASH*** (only if using git bash) -# add user -./pkg/setup.sh -``` + ```sh + export MSYS_NO_PATHCONV=1 + ``` + +- Run docker ubuntu container + + ```sh + docker run --rm -itv $(pwd):/app -w /app ubuntu:latest bash + ``` + +- Create default user and activate that user in docker ubuntu shell + + ```sh + # Install sudo + apt update -y && apt install -y sudo + # Create user + export user=ubuntu + adduser --disabled-password --gecos "" ${user} + usermod -aG sudo ${user} + echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} + # Activate user + su - ubuntu + ``` + +- Test the installer script + + ```sh + /app/pkg/setup.sh + ``` From 51e75dbfc0167ea53e48cc7702b4260fb266f500 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 17:39:54 +0000 Subject: [PATCH 04/18] adding working script changes --- pkg/setup.sh | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) mode change 100644 => 100755 pkg/setup.sh diff --git a/pkg/setup.sh b/pkg/setup.sh old mode 100644 new mode 100755 index 33026841..a272c0c6 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -71,20 +71,16 @@ echo "Install Anaconda\nbash /tmp/conda.sh -b" bash /tmp/conda.sh -b # Add Anaconda to the PATH +echo "initiate anaconda \n/home/${user}/anaconda3/bin/conda init bash" /home/${user}/anaconda3/bin/conda init bash -source /home/$user/.bashrc -# TODO: You might be able to eliminate this via `/path/to/conda init && source .bashrc` -# echo "Setting environment variable for anaconda" +echo "Setting environment variable for anaconda" # $prefix echo 'export PATH="/home/${user}/anaconda3/bin:$PATH"' >> /home/$user/.bashrc # $prefix echo ". /home/${user}/anaconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc # $prefix echo "conda activate base" >> /home/$user/.bashrc -# # Activate the base environment -# echo "source /home/$user/.bashrc" -# if [ "$package_type" == "deb" ]; then -# # Activating conda environment in debian -# echo "Activating conda environment in debian" -# source /home/$user/anaconda3/bin/activate base -# fi +source /home/${user}/.bashrc +# Activate the base environment +echo "Activating conda environment in debian" +source /home/$user/anaconda3/bin/activate base echo "conda --version" conda --version @@ -112,7 +108,8 @@ gramex license accept # install Nodejs echo "Installing Nodejs" -curl -sL | sudo bash - +echo "package_type: ${package_type}" +curl -sL https://${package_type}.nodesource.com/setup_16.x | sudo bash - # TODO: Add the following dependencies # # icu-data-full is required for comicgen -> fontkit to run TextDecoder('ascii') From e5bcd3d3bb38bef49f9624c434fede52073b36e7 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 17:40:09 +0000 Subject: [PATCH 05/18] adding support for centos 7 --- pkg/testing.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pkg/testing.md b/pkg/testing.md index 4d76fd9b..f731fec6 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -1,6 +1,6 @@ # Testing setup -To test this on Ubuntu: +Tesing the installer script in multiple platforms using docker containers - Disable path conversion in ***GIT BASH*** (only if using git bash) @@ -8,6 +8,8 @@ To test this on Ubuntu: export MSYS_NO_PATHCONV=1 ``` +## Ubuntu: + - Run docker ubuntu container ```sh @@ -25,11 +27,41 @@ To test this on Ubuntu: usermod -aG sudo ${user} echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} # Activate user - su - ubuntu + su - ${user} + ``` + +- Test the installer script + + ```sh + chmod +x /app/pkg/setup.sh + /app/pkg/setup.sh + ``` + +## Centos 7: + +- Run docker ubuntu container + + ```sh + docker run --rm -itv $(pwd):/app -w /app centos:7 bash + ``` + +- Create default user and activate that user in docker ubuntu shell + + ```sh + # Install sudo + yum install -y sudo + # Create user + export user=centos + useradd -m -p '' ${user} + usermod -aG wheel ${user} + echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} + # Activate user + su - ${user} ``` - Test the installer script ```sh + chmod +x /app/pkg/setup.sh /app/pkg/setup.sh ``` From 83cc7238d300aaad8a7f80ac07ba3ddc4f49c2ac Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 18:01:07 +0000 Subject: [PATCH 06/18] adding support for amazon linux 2 --- pkg/setup.sh | 1 + pkg/testing.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkg/setup.sh b/pkg/setup.sh index a272c0c6..12774d62 100755 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -7,6 +7,7 @@ declare -A users_map users_map["ubuntu"]="ubuntu" users_map["debian"]="admin" users_map["centos"]="centos" +users_map["amzn"]="ec2-user" users_map["alpine"]="root" # TODO: Anaconda version should be a variable diff --git a/pkg/testing.md b/pkg/testing.md index f731fec6..0b80bac2 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -65,3 +65,33 @@ Tesing the installer script in multiple platforms using docker containers chmod +x /app/pkg/setup.sh /app/pkg/setup.sh ``` + +## amazonlinux 2: + +- Run docker ubuntu container + + ```sh + docker run --rm -itv $(pwd):/app -w /app amazonlinux:2 bash + ``` + +- Create default user and activate that user in docker ubuntu shell + + ```sh + # Install sudo + yum install -y sudo shadow-utils util-linux + + # Create user + export user=ec2-user + useradd -m -p '' ${user} + usermod -aG wheel ${user} + echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} + # Activate user + su - ${user} + ``` + +- Test the installer script + + ```sh + chmod +x /app/pkg/setup.sh + /app/pkg/setup.sh + ``` From 94f917852cf1a365763d959f8e5780463acc5008 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 18:04:03 +0000 Subject: [PATCH 07/18] grammar correction --- pkg/testing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/testing.md b/pkg/testing.md index 0b80bac2..bffd7f4f 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -39,7 +39,7 @@ Tesing the installer script in multiple platforms using docker containers ## Centos 7: -- Run docker ubuntu container +- Run docker Centos container ```sh docker run --rm -itv $(pwd):/app -w /app centos:7 bash @@ -68,7 +68,7 @@ Tesing the installer script in multiple platforms using docker containers ## amazonlinux 2: -- Run docker ubuntu container +- Run docker Amazon linux container ```sh docker run --rm -itv $(pwd):/app -w /app amazonlinux:2 bash From 869433f8c136bef6fc8ddafe56e286cba444dcda Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 18:14:25 +0000 Subject: [PATCH 08/18] exit script if not ran from bash --- pkg/setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/setup.sh b/pkg/setup.sh index 12774d62..db7b58ce 100755 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -1,5 +1,10 @@ # !/bin/bash +if [ -z "$BASH_VERSION" ]; then + echo "This script must be run in Bash. Exiting now." + exit 1 +fi + # Declare an associative array for OS-specific default users declare -A users_map @@ -8,7 +13,6 @@ users_map["ubuntu"]="ubuntu" users_map["debian"]="admin" users_map["centos"]="centos" users_map["amzn"]="ec2-user" -users_map["alpine"]="root" # TODO: Anaconda version should be a variable # TODO: Consider miniconda instead of Anaconda From cee0568726b3163dbdf6be7235aa9a9c2e8228f8 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Wed, 11 Jan 2023 18:16:13 +0000 Subject: [PATCH 09/18] adding template for alpine --- pkg/testing.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/testing.md b/pkg/testing.md index bffd7f4f..bf6dc55c 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -95,3 +95,20 @@ Tesing the installer script in multiple platforms using docker containers chmod +x /app/pkg/setup.sh /app/pkg/setup.sh ``` + +## Alpine: + +- Run docker Amazon linux container + + ```sh + docker run --rm -itv $(pwd):/app -w /app alpine:latest sh + ``` + +> TODO: Create a `sh` script that runs in `shell` not `bash` + +- Test the installer script + + ```sh + chmod +x /app/pkg/setup_sh.sh + /app/pkg/setup_sh.sh + ``` From 2775b89624c9010fb4dd7bcb3bca638d24858533 Mon Sep 17 00:00:00 2001 From: Shraddheya Shrivastava Date: Wed, 11 Jan 2023 23:49:41 +0530 Subject: [PATCH 10/18] lint correction --- pkg/testing.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/testing.md b/pkg/testing.md index bf6dc55c..000666f1 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -8,7 +8,7 @@ Tesing the installer script in multiple platforms using docker containers export MSYS_NO_PATHCONV=1 ``` -## Ubuntu: +## Ubuntu - Run docker ubuntu container @@ -37,7 +37,7 @@ Tesing the installer script in multiple platforms using docker containers /app/pkg/setup.sh ``` -## Centos 7: +## Centos 7 - Run docker Centos container @@ -66,7 +66,7 @@ Tesing the installer script in multiple platforms using docker containers /app/pkg/setup.sh ``` -## amazonlinux 2: +## amazonlinux 2 - Run docker Amazon linux container @@ -96,7 +96,7 @@ Tesing the installer script in multiple platforms using docker containers /app/pkg/setup.sh ``` -## Alpine: +## Alpine - Run docker Amazon linux container From d7256befb857951d55c2ebb75e0ae4c38e0431e1 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:20:34 +0000 Subject: [PATCH 11/18] converted the script to posix --- pkg/setup.sh | 126 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 85 insertions(+), 41 deletions(-) diff --git a/pkg/setup.sh b/pkg/setup.sh index db7b58ce..53c401a4 100755 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -1,23 +1,75 @@ -# !/bin/bash +#!/bin/sh if [ -z "$BASH_VERSION" ]; then echo "This script must be run in Bash. Exiting now." exit 1 fi -# Declare an associative array for OS-specific default users -declare -A users_map +# Use environment variable to emulate associative array +users_map_ubuntu="ubuntu" +users_map_debian="admin" +users_map_centos="centos" +users_map_amzn="ec2-user" + +ALLOWED_VERSIONS=("3.7" "3.9") +while [[ $# -gt 0 ]]; do + key="$1" + + case $key in + -d | --default) + VERSION=3.9 + GRAMEX_VERSION=1.86.1 + shift # past argument + ;; + -v | --version) + VERSION="$2" + if [[ ! " ${ALLOWED_VERSIONS[@]} " =~ " ${VERSION} " ]]; then + echo "Error: python versions must be set to one of the following values: ${ALLOWED_VERSIONS[*]}" + exit 1 + fi + + shift # past argument + shift # past value + ;; + -g | --gramex) + GRAMEX_VERSION="$2" + shift # past argument + shift # past value + ;; + *) # unknown option + echo "Unknown option: $key" + ;; + esac +done + +# Check if Python VERSION variable is empty or unset +if [ -z "$VERSION" ]; then + # Prompt user to enter the version of python to be installed + echo -n "Specify a version of python to be installed 3.7/3.9 [3.9]: " + # Read the input from user + read VERSION + # Set default value for VERSION if it's unset or empty + VERSION=${VERSION:-3.9} +fi -# Set the default users for each OS -users_map["ubuntu"]="ubuntu" -users_map["debian"]="admin" -users_map["centos"]="centos" -users_map["amzn"]="ec2-user" +# Check if Gramex VERSION variable is empty or unset +if [ -z "$GRAMEX_VERSION" ]; then + # Prompt user to enter the version of python to be installed + echo -n "Specify a version of python to be installed 3.7/3.9 [3.9]: " + # Read the input from user + read GRAMEX_VERSION + # Set default value for GRAMEX_VERSION if it's unset or empty + GRAMEX_VERSION=${GRAMEX_VERSION:-1.86.1} +fi -# TODO: Anaconda version should be a variable -# TODO: Consider miniconda instead of Anaconda -# Set the repo URL for the anaconda download -repo_url="https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh" +# Set the default repo URL for the Miniconda download + repo_url="https://repo.anaconda.com/miniconda/Miniconda3-py39_22.11.1-1-Linux-x86_64.sh" + +# Check if the VERSION is 3.9 +if [ "$VERSION" = "3.7" ]; then + # Reassign the repo URL with the URL for version 3.7 + repo_url="https://repo.anaconda.com/miniconda/Miniconda3-py37_22.11.1-1-Linux-x86_64.sh" +fi # Check if the user is the root user if [ "$(id -u)" -ne 0 ]; then @@ -29,21 +81,20 @@ else prefix="" fi - # TODO: Set up distro-specific scripts for Debian, CentOS, Alpine, etc. # TODO: Based on the distro, call the relevant one # Set the package manager to use -if command -v apt-get > /dev/null 2>&1; then +if command -v apt-get >/dev/null 2>&1; then echo "The OS supports 'apt'." echo "Updating the pakcage indices." package_type=deb package_manager=apt $prefix apt update -qq -y -elif command -v yum > /dev/null 2>&1; then +elif command -v yum >/dev/null 2>&1; then echo "The OS supports 'yum'" package_type=rpm package_manager=yum -elif command -v dnf > /dev/null 2>&1; then +elif command -v dnf >/dev/null 2>&1; then echo "The OS supports 'dnf'" package_type=rpm package_manager=dnf @@ -52,40 +103,37 @@ else exit 1 fi -# Read the ID field from /etc/os-release -os_id=$(grep ^ID= /etc/os-release | awk -F= '{ print $2 }') -# Remove the surrounding quotes from the ID string -os_id="${os_id%\"}" -os_id="${os_id#\"}" +# Read the ID field from /etc/os-release +os_id=$(grep ^ID= /etc/os-release | awk -F= '{ print $2 }' | tr -d '"') # Set the user variable to the default user for the current OS -user=${users_map[$os_id]} -echo "The Os detected is '${os_id}', hence the default user is '${user}'" +eval "user=\$users_map_$os_id" +echo "The Os detected is '$os_id', hence the default user is '$user'" # If curl is not installed, install it -if ! command -v curl > /dev/null 2>&1; then +if ! command -v curl >/dev/null 2>&1; then echo "$prefix $package_manager install -y curl" $prefix $package_manager install -y curl fi -echo "Download anaconda installer\ncurl ${repo_url} -o /tmp/conda.sh" +echo "Download miniconda installer\ncurl ${repo_url} -o /tmp/conda.sh" curl $repo_url -o /tmp/conda.sh - -# Run the Anaconda installer with the '-b' flag to run it in batch mode without prompts -echo "Install Anaconda\nbash /tmp/conda.sh -b" +# TODO: veryfy checksum of the downloaded file +# Run the miniconda installer with the '-b' flag to run it in batch mode without prompts +echo "Install miniconda\nbash /tmp/conda.sh -b" bash /tmp/conda.sh -b -# Add Anaconda to the PATH -echo "initiate anaconda \n/home/${user}/anaconda3/bin/conda init bash" -/home/${user}/anaconda3/bin/conda init bash +# Add miniconda to the PATH +echo "initiate miniconda \n/home/${user}/miniconda3/bin/conda init bash" +/home/${user}/miniconda3/bin/conda init bash echo "Setting environment variable for anaconda" -# $prefix echo 'export PATH="/home/${user}/anaconda3/bin:$PATH"' >> /home/$user/.bashrc -# $prefix echo ". /home/${user}/anaconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc +# $prefix echo 'export PATH="/home/${user}/miniconda3/bin:$PATH"' >> /home/$user/.bashrc +# $prefix echo ". /home/${user}/miniconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc # $prefix echo "conda activate base" >> /home/$user/.bashrc source /home/${user}/.bashrc # Activate the base environment echo "Activating conda environment in debian" -source /home/$user/anaconda3/bin/activate base +source /home/$user/miniconda3/bin/activate base echo "conda --version" conda --version @@ -101,10 +149,7 @@ pip install --upgrade pip echo "$prefix rm -rf /tmp/conda.sh" $prefix rm -rf /tmp/conda.sh -# TODO: Allow the user to specify version of Gramex # Install Gramex -echo "GRAMEX_VERSION=\"1.86.1\" pip install gramex<=\"${GRAMEX_VERSION}\" gramexenterprise<=\"${GRAMEX_VERSION}\"" -GRAMEX_VERSION="1.86.1" pip install "gramex<=${GRAMEX_VERSION}" "gramexenterprise<=${GRAMEX_VERSION}" pip cache purge @@ -130,10 +175,9 @@ echo "npm --version" npm --version # Allow `npm install -g` to work without sudo by installing to ~/.npm-packages -mkdir -p ~/.npm-packages && \ -npm config set prefix "${HOME_DIR}/.npm-packages" && \ - -gramex setup --all +mkdir -p ~/.npm-packages && + npm config set prefix "${HOME_DIR}/.npm-packages" && + gramex setup --all # Clean up npm cache npm cache clean --force From 19a4e7ba57731c6a2a9c3db13767e7b0580535e1 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:21:08 +0000 Subject: [PATCH 12/18] added automated testing for amazon linux 2 --- pkg/testing.md | 27 ++------------------------- pkg/tests/amazon_linux_2.sh | 22 ++++++++++++++++++++++ pkg/tests/test_amazon_linux.sh | 7 +++++++ 3 files changed, 31 insertions(+), 25 deletions(-) create mode 100755 pkg/tests/amazon_linux_2.sh create mode 100755 pkg/tests/test_amazon_linux.sh diff --git a/pkg/testing.md b/pkg/testing.md index bf6dc55c..6b7b5721 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -68,32 +68,9 @@ Tesing the installer script in multiple platforms using docker containers ## amazonlinux 2: -- Run docker Amazon linux container - - ```sh - docker run --rm -itv $(pwd):/app -w /app amazonlinux:2 bash - ``` - -- Create default user and activate that user in docker ubuntu shell - - ```sh - # Install sudo - yum install -y sudo shadow-utils util-linux - - # Create user - export user=ec2-user - useradd -m -p '' ${user} - usermod -aG wheel ${user} - echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} - # Activate user - su - ${user} - ``` - -- Test the installer script - ```sh - chmod +x /app/pkg/setup.sh - /app/pkg/setup.sh + cd tests + ./test_amazon_linux_2.sh ``` ## Alpine: diff --git a/pkg/tests/amazon_linux_2.sh b/pkg/tests/amazon_linux_2.sh new file mode 100755 index 00000000..64fb6a2f --- /dev/null +++ b/pkg/tests/amazon_linux_2.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +chmod +x /app/setup.sh +# Install sudo +yum install -y sudo shadow-utils util-linux + +# Create user +export user=ec2-user +useradd -m -p '' ${user} +usermod -aG wheel ${user} +echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} + +# Run the command as the switched user +su - ${user} -c "/app/setup.sh -d" + +su - ${user} -c "source ~/.bashrc" +su - ${user} -c "conda --version" +su - ${user} -c "python --version" +su - ${user} -c "gramex --version" +su - ${user} -c "node --version" +# Exit the user session +exit diff --git a/pkg/tests/test_amazon_linux.sh b/pkg/tests/test_amazon_linux.sh new file mode 100755 index 00000000..4c5cf12d --- /dev/null +++ b/pkg/tests/test_amazon_linux.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --rm -it \ + -v $(pwd)/../setup.sh:/app/setup.sh \ + -v $(pwd)/amazon_linux_2.sh:/test/amazon_linux_2.sh \ + -w /test amazonlinux:2 \ + sh /test/amazon_linux_2.sh From 8b30c353a392e13324dc693c22a06d5e0c70b1d3 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:47:46 +0000 Subject: [PATCH 13/18] removed sh support as it is not working properly --- pkg/setup.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/setup.sh b/pkg/setup.sh index 53c401a4..36736f8f 100755 --- a/pkg/setup.sh +++ b/pkg/setup.sh @@ -1,5 +1,5 @@ -#!/bin/sh - +#!/bin/bash +# FIXME: The script still does nto work for sh if [ -z "$BASH_VERSION" ]; then echo "This script must be run in Bash. Exiting now." exit 1 @@ -126,6 +126,10 @@ bash /tmp/conda.sh -b # Add miniconda to the PATH echo "initiate miniconda \n/home/${user}/miniconda3/bin/conda init bash" /home/${user}/miniconda3/bin/conda init bash +# if command -v bash >/dev/null 2>&1; then +# echo "Bash is installed." +# echo "initiate miniconda \n/home/${user}/miniconda3/bin/conda init bash" +# /home/${user}/miniconda3/bin/conda init bash echo "Setting environment variable for anaconda" # $prefix echo 'export PATH="/home/${user}/miniconda3/bin:$PATH"' >> /home/$user/.bashrc # $prefix echo ". /home/${user}/miniconda3/etc/profile.d/conda.sh" >> /home/$user/.bashrc From 82c7998304a90bf9b4f701b16928dc8d5fcc1f4d Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:48:06 +0000 Subject: [PATCH 14/18] restoring the amazon linux test to bash --- pkg/tests/test_amazon_linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tests/test_amazon_linux.sh b/pkg/tests/test_amazon_linux.sh index 4c5cf12d..9eb434b2 100755 --- a/pkg/tests/test_amazon_linux.sh +++ b/pkg/tests/test_amazon_linux.sh @@ -4,4 +4,4 @@ docker run --rm -it \ -v $(pwd)/../setup.sh:/app/setup.sh \ -v $(pwd)/amazon_linux_2.sh:/test/amazon_linux_2.sh \ -w /test amazonlinux:2 \ - sh /test/amazon_linux_2.sh + bash /test/amazon_linux_2.sh From 5a4ac0904c154b866b34170470a7e08ea8b4ae1b Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:50:06 +0000 Subject: [PATCH 15/18] adding ubuntu automated test support --- pkg/testing.md | 26 ++------------------------ pkg/tests/test_ubuntu.sh | 7 +++++++ pkg/tests/ubuntu.sh | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 24 deletions(-) create mode 100755 pkg/tests/test_ubuntu.sh create mode 100755 pkg/tests/ubuntu.sh diff --git a/pkg/testing.md b/pkg/testing.md index a1503e38..efdc293d 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -10,31 +10,9 @@ Tesing the installer script in multiple platforms using docker containers ## Ubuntu -- Run docker ubuntu container - - ```sh - docker run --rm -itv $(pwd):/app -w /app ubuntu:latest bash - ``` - -- Create default user and activate that user in docker ubuntu shell - ```sh - # Install sudo - apt update -y && apt install -y sudo - # Create user - export user=ubuntu - adduser --disabled-password --gecos "" ${user} - usermod -aG sudo ${user} - echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} - # Activate user - su - ${user} - ``` - -- Test the installer script - - ```sh - chmod +x /app/pkg/setup.sh - /app/pkg/setup.sh + cd tests + ./test_ubuntu.sh ``` ## Centos 7 diff --git a/pkg/tests/test_ubuntu.sh b/pkg/tests/test_ubuntu.sh new file mode 100755 index 00000000..7bdf4428 --- /dev/null +++ b/pkg/tests/test_ubuntu.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --rm -it \ + -v $(pwd)/../setup.sh:/app/setup.sh \ + -v $(pwd)/ubuntu.sh:/test/ubuntu.sh \ + -w /test ubuntu:latest \ + bash /test/ubuntu.sh diff --git a/pkg/tests/ubuntu.sh b/pkg/tests/ubuntu.sh new file mode 100755 index 00000000..43e484c4 --- /dev/null +++ b/pkg/tests/ubuntu.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +cat /etc/os-release +whoami + +chmod +x /app/setup.sh +# install sudo +apt update -y && apt install -y sudo + +# Create user +export user=ubuntu +adduser --disabled-password --gecos "" ${user} +usermod -aG sudo ${user} +echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} +# Run the command as the switched user +su - ${user} -c "/app/setup.sh -d" +# Exit the user session +exit From ccfef4e6b09f3ca1545f09f23641c3ed7bd24b3f Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:51:34 +0000 Subject: [PATCH 16/18] renaming for better readability --- pkg/tests/{test_amazon_linux.sh => test_amazon_linux_2.sh} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pkg/tests/{test_amazon_linux.sh => test_amazon_linux_2.sh} (100%) diff --git a/pkg/tests/test_amazon_linux.sh b/pkg/tests/test_amazon_linux_2.sh similarity index 100% rename from pkg/tests/test_amazon_linux.sh rename to pkg/tests/test_amazon_linux_2.sh From b2a7b3f40a6db9b5a6b8c32281bde6d0aaceb446 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:56:51 +0000 Subject: [PATCH 17/18] adding centos7 automated test --- pkg/testing.md | 26 ++------------------------ pkg/tests/centos7.sh | 22 ++++++++++++++++++++++ pkg/tests/test_centos7.sh | 7 +++++++ 3 files changed, 31 insertions(+), 24 deletions(-) create mode 100755 pkg/tests/centos7.sh create mode 100755 pkg/tests/test_centos7.sh diff --git a/pkg/testing.md b/pkg/testing.md index efdc293d..bbfe33af 100644 --- a/pkg/testing.md +++ b/pkg/testing.md @@ -17,31 +17,9 @@ Tesing the installer script in multiple platforms using docker containers ## Centos 7 -- Run docker Centos container - - ```sh - docker run --rm -itv $(pwd):/app -w /app centos:7 bash - ``` - -- Create default user and activate that user in docker ubuntu shell - ```sh - # Install sudo - yum install -y sudo - # Create user - export user=centos - useradd -m -p '' ${user} - usermod -aG wheel ${user} - echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} - # Activate user - su - ${user} - ``` - -- Test the installer script - - ```sh - chmod +x /app/pkg/setup.sh - /app/pkg/setup.sh + cd tests + ./test_centos7.sh ``` ## amazonlinux 2 diff --git a/pkg/tests/centos7.sh b/pkg/tests/centos7.sh new file mode 100755 index 00000000..be60b48f --- /dev/null +++ b/pkg/tests/centos7.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +chmod +x /app/setup.sh +# Install sudo +yum install -y sudo + +# Create user +export user=centos +useradd -m -p '' ${user} +usermod -aG wheel ${user} +echo "${user} ALL=(ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/${user} + +# Run the command as the switched user +su - ${user} -c "/app/setup.sh -d" + +su - ${user} -c "source ~/.bashrc" +su - ${user} -c "conda --version" +su - ${user} -c "python --version" +su - ${user} -c "gramex --version" +su - ${user} -c "node --version" +# Exit the user session +exit diff --git a/pkg/tests/test_centos7.sh b/pkg/tests/test_centos7.sh new file mode 100755 index 00000000..1927bb6f --- /dev/null +++ b/pkg/tests/test_centos7.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +docker run --rm -it \ + -v $(pwd)/../setup.sh:/app/setup.sh \ + -v $(pwd)/centos7.sh:/test/centos7.sh \ + -w /test centos:7 \ + bash /test/centos7.sh From b620f7a2632ef007786ca777c99f71f1dc9c6f52 Mon Sep 17 00:00:00 2001 From: Shraddheya Date: Thu, 12 Jan 2023 06:58:14 +0000 Subject: [PATCH 18/18] currecting bash shell to use for tests --- pkg/tests/amazon_linux_2.sh | 2 +- pkg/tests/centos7.sh | 2 +- pkg/tests/ubuntu.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/tests/amazon_linux_2.sh b/pkg/tests/amazon_linux_2.sh index 64fb6a2f..57d73652 100755 --- a/pkg/tests/amazon_linux_2.sh +++ b/pkg/tests/amazon_linux_2.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash chmod +x /app/setup.sh # Install sudo diff --git a/pkg/tests/centos7.sh b/pkg/tests/centos7.sh index be60b48f..f4197543 100755 --- a/pkg/tests/centos7.sh +++ b/pkg/tests/centos7.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash chmod +x /app/setup.sh # Install sudo diff --git a/pkg/tests/ubuntu.sh b/pkg/tests/ubuntu.sh index 43e484c4..ee08423a 100755 --- a/pkg/tests/ubuntu.sh +++ b/pkg/tests/ubuntu.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash cat /etc/os-release whoami