Skip to content
Snippets Groups Projects
Commit 199760b6 authored by Marty Kandes's avatar Marty Kandes
Browse files

Created new naked-singularity.sh helper script

Created the initial version of the new naked-singularity.sh helper
script. At present, the script only supports a first iteration of the
'install' command, which can be used to install Singularity from source
on a Linux system running either a CentOS or Ubuntu operating system.
parent c6e08058
No related branches found
No related tags found
No related merge requests found
...@@ -53,8 +53,8 @@ University of California, San Diego ...@@ -53,8 +53,8 @@ University of California, San Diego
## Version ## Version
1.1.0 1.2.3
## Last Updated ## Last Updated
Sunday, December 27th, 2020 Thursday, December 31st, 2020
log.sh 0 → 100644
#!/usr/bin/env bash
# ======================================================================
#
# NAME
#
# log.sh
#
# DESCRIPTION
#
# A library of bash functions for writing formatted log messages to
# standard output and standard error.
#
# USAGE
#
# If you would like to use this library in your bash script, then
# source it at the beginning of your bash script.
#
# source log.sh
#
# Once the library has been sourced, you can call functions from the
# library in your bash script.
#
# AUTHOR
#
# Marty Kandes, Ph.D.
# Computational & Data Science Research Specialist
# High-Performance Computing User Services Group
# San Diego Supercomputer Center
# University of California, San Diego
#
# LAST UPDATED
#
# Monday, December 28th, 2020
#
# ----------------------------------------------------------------------
log::output() {
echo "${@}" >&1
}
log::error() {
echo "ERROR :: ${@}" >&2
}
log::warning() {
echo "WARNING :: ${@}" >&2
}
# ======================================================================
#!/usr/bin/env bash
# ======================================================================
# NAME
#
# naked-singularity.sh
#
# DESCRIPTION
#
# A bash script to help users work with Singularity on their Linux
# desktop, laptop, or virtual machine.
#
# USAGE
#
# Install Singularity from source.
#
# ./naked-singularity.sh install
#
# LAST UPDATED
#
# Thursday, December 31st, 2020
#
# ----------------------------------------------------------------------
source log.sh
# ----------------------------------------------------------------------
# naked::install
#
# Install Singularity (from source).
#
# Globals:
#
# N/A
#
# Arguments:
#
# @
#
# Returns:
#
# True (0) if Singularity is installed sucessfully. False (1)
# if the installation fails.
#
# ----------------------------------------------------------------------
naked::install() {
local singularity_version='3.5.2'
local go_version='1.15.6'
local -i use_rpm=1
local os_release_id=''
local os_release_version_id=''
while (("${#}" > 0)); do
case "${1}" in
-g | --go )
go_version="${2}"
shift 2
;;
-r | --rpm )
use_rpm=0
shift 1
;;
-s | --singularity )
singularity_version="${2}"
shift 2
;;
*)
log::error "Command-line option ${1} not recognized or not supported."
return 1
esac
done
log::output 'Checking if Singularity is already installed ...'
singularity --version > /dev/null 2>&1
if [[ "${?}" -eq 0 ]]; then
log:error "Singularity is installed: $(singularity --version)"
return 1
else
log::output 'Singularity is not installed.'
fi
log::output 'Parsing /etc/os-release to identify operating system ...'
if [[ -f '/etc/os-release' ]]; then
grep '^ID=' /etc/os-release > /dev/null 2>&1
if [[ "${?}" -eq 0 ]]; then
grep '^ID=' /etc/os-release | grep '"' > /dev/null 2>&1
if [[ "${?}" -eq 0 ]]; then
os_release_id="$(grep '^ID=' /etc/os-release | cut -d '"' -f 2)"
else
os_release_id="$(grep '^ID=' /etc/os-release | cut -d '=' -f 2)"
fi
log::output "Operating system identified as ${os_release_id}."
else
log::error '/etc/os-release does not contain ID parameter.'
return 1
fi
grep '^VERSION_ID=' /etc/os-release > /dev/null 2>&1
if [[ "${?}" -eq 0 ]]; then
grep '^VERSION_ID=' /etc/os-release | grep '"' > /dev/null 2>&1
if [[ "${?}" -eq 0 ]]; then
os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '"' -f 2)"
else
os_release_version_id="$(grep '^VERSION_ID=' /etc/os-release | cut -d '=' -f 2)"
fi
log::output "Operating system version identified as ${os_release_version_id}."
else
log::error '/etc/os-release does not contain VERSION_ID parameter.'
return 1
fi
else
log::error '/etc/os-release does not exist.'
return 1
fi
if [[ "${os_release_id}" = 'centos' ]]; then
log::output 'Running yum update ...'
sudo yum -y update
log::output 'Installing Singularity dependencies ...'
sudo yum -y groupinstall 'Development Tools'
sudo yum -y install epel-release
sudo yum -y install openssl-devel
sudo yum -y install libuuid-devel
sudo yum -y install libseccomp-devel
sudo yum -y install wget
sudo yum -y install squashfs-tools
sudo yum -y install cryptsetup
elif [[ "${os_release_id}" = 'ubuntu' ]]; then
log::output 'Running apt-get update ...'
sudo apt-get -y update
log::output 'Installing Singularity dependencies ...'
sudo apt-get -y install build-essential
sudo apt-get -y install libssl-dev
sudo apt-get -y install uuid-dev
sudo apt-get -y install libgpgme-dev
sudo apt-get -y install squashfs-tools
sudo apt-get -y install libseccomp-dev
sudo apt-get -y install wget
sudo apt-get -y install pkg-config
sudo apt-get -y install git
sudo apt-get -y install cryptsetup-bin
else
log::error 'Operating system not recognized or not supported.'
return 1
fi
mkdir -p /tmp/go
cd /tmp/go
log::output 'Installing Go ...'
export CGO_ENABLED=0
wget https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz
tar -xf go1.4-bootstrap-20171003.tar.gz
mv go 1.4
cd 1.4/src
./make.bash
export GOROOT_BOOTSTRAP='/tmp/go/1.4'
cd /tmp/go
export CGO_ENABLED=1
git clone https://go.googlesource.com/go "${go_version}"
cd "${go_version}"
git checkout "go${go_version}"
cd src
./all.bash
export GOROOT="/tmp/go/${go_version}"
export PATH="${GOROOT}/bin:${PATH}"
cd /tmp
log::output 'Installing Singularity ...'
wget "https://github.com/hpcng/singularity/releases/download/v${singularity_version}/singularity-${singularity_version}.tar.gz"
tar -xf "singularity-${singularity_version}.tar.gz"
cd singularity
./mconfig #--prefix=/opt/singularity
make -C ./builddir
sudo make -C ./builddir install
log::output 'Checking if Singularity was installed successully ...'
singularity --version
if [[ "${?}" -ne 0 ]]; then
log::error 'Singularity installation failed!'
return 1
fi
log::output 'Singularity was installed successfully!'
return 0
}
# ----------------------------------------------------------------------
# naked::help
#
# Prints information on how to use this script to standard output.
#
# Globals:
#
# N/A
#
# Arguments:
#
# N/A
#
# Returns:
#
# True (0) always.
#
# ----------------------------------------------------------------------
naked::help() {
log::output 'USAGE: naked-singularity.sh <command> [options] {value}'
log::output ''
return 0
}
# ----------------------------------------------------------------------
# naked::main
#
# Controls the execution of the script.
#
# Globals:
#
# @
#
# Arguments:
#
# @
#
# Returns:
#
# True (0) if the script executes without issue. False (1) if the
# script fails to executre properly.
#
# ----------------------------------------------------------------------
naked::main() {
local naked_command=''
# If at least one command-line argument was provided by the user,
# then start parsing the command-line arguments. Otherwise, throw
# an error.
if (( "${#}" > 0 )); then
naked_command="${1}"
shift 1
if [[ "${naked_command}" = 'install' ]]; then
naked::install "${@}"
if [[ "${?}" -ne 0 ]]; then
log::error 'Failed to run install command.'
exit 1
fi
elif [[ "${naked_command}" = 'help' || \
"${naked_command}" = '-h' || \
"${naked_command}" = '--help' ]]; then
naked::help
if [[ "${?}" -ne 0 ]]; then
log::error 'Failed to run help command.'
exit 1
fi
else
log::error 'Command not recognized or not supported.'
exit 1
fi
else
log::error 'No command-line arguments were provided.'
exit 1
fi
exit 0
}
# ----------------------------------------------------------------------
naked::main "${@}"
# ======================================================================
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment