diff --git a/scripts/nica-init.sh b/scripts/nica-init.sh new file mode 100755 index 0000000000000000000000000000000000000000..203c9e9d62ef682824233e05b8e4a3307abba836 --- /dev/null +++ b/scripts/nica-init.sh @@ -0,0 +1,242 @@ +#!/bin/bash + +# Script to initialize Unified Development/Use Environment for MPDRoot +# Written for MPDRoot @JINR Dubna +# Authors: Slavomir Hnatic, Martin Vala +# First commit: Martin Vala 12.2021 +# Support: create a "new issue" on https://git.jinr.ru/nica/nicadist/-/issues + +####################################################################################################################### +################################################ Functionality ######################################################## +### ### +### ### +### 1. Detects OS version, to choose appropriate method to install toolbox ### +### ### +### Tested/supported OS: ### +### a) Red Hat based: Fedora 35 (should work on any Fedora version), CentOS 7, CentOS 8 ### +### b) Debian based : Debian 11, Ubuntu 21.10, Ubuntu 20.04, Ubuntu 18.04, Mint 20.2, Pop!_os 20.04 ### +### ### +### ### +### 2. If you have different distribution which is based on any of the of the supported from above, you can ### +### select appropriate installation method by passing distribution name (-d) and version (-v) ### +### ### +### Example: ### +### ### +### nica-init.sh -d Ubuntu -v 20.04 ### +### ### +### will attempt to install using the method for Ubuntu 20.04 ### +### (tested to work with Mint 20.2, Pop!_os 20.04 LTS) ### +### ### +### ### +### 3. Installs cvmfs, then starts cvmfs service and enables autostart cvmfs service on boot. ### +### ### +### If you do not want to enable start cvmfs service on boot: ### +### ### +### nica-init.sh -a no ### +### ### +### ### +### 4. Creates toolbox container ### +### ### +### ### +### 5. Writes out the installation summary (success) & short how to ### +### ### +### ### +####################################################################################################################### + +main () { + + # exit when any command fails + set -e + + identify_os + + # overwrite default input parameters if passed into the script + AUTOSTART=yes + TOOLBOX_OS_VER="7" + while getopts d:v:a:t: flag + do + case "${flag}" in + d) OS=${OPTARG};; + v) OS_VERSION=${OPTARG};; + a) AUTOSTART=${OPTARG};; + t) TOOLBOX_OS_VER=${OPTARG};; + esac + done + + install_toolbox + + install_cvmfs + + # start cvmfs now and choose whether to enable autostart + [[ $AUTOSTART = no ]] && sudo systemctl start cvmfs || sudo systemctl enable --now cvmfs + + # create toolbox container (unless you are CentOS 7 user - there is no need to do it there) + if [[ "$OS" != "CentOS" || "$OS_VERSION" != "7" ]]; then + toolbox create -c c${TOOLBOX_OS_VER}-alibuild-dev -i registry.gitlab.com/ndmspc/user/c${TOOLBOX_OS_VER}:alibuild-dev -y + fi + + # write out init summary & short how to + generate_summary + +} + + +function identify_os() { + + OS=$(cat /etc/os-release | grep NAME= | head -n 1 | cut -d '=' -f2 | tr -d '"' | cut -d ' ' -f1) + OS_VERSION=$(cat /etc/os-release | grep VERSION_ID= | head -n 1 | cut -d '=' -f2 | tr -d '"') + OS_VARIANT_ID=$(cat /etc/os-release | grep VARIANT_ID= | head -n 1 | cut -d '=' -f2 | tr -d '"') + +} + + +function install_toolbox() { + + case $OS in + + Fedora) + if [ $OS_VARIANT_ID = "silverblue" ];then + echo "Toolbox installed by default on Fedora Silverblue" + else + echo "Installing toolbox on Fedora $OS_VERSION" + sudo dnf install toolbox -y + fi + ;; + + CentOS) + if [ "$OS_VERSION" = "8" ];then + echo "Installing toolbox on CentOS $OS_VERSION" + sudo dnf install toolbox -y + elif [ "$OS_VERSION" = "7" ];then + echo "Installing native support (no toolbox needed) on CentOS 7" + sudo yum install podman environment-modules -y + sudo ln -sfn /var/cvmfs /cvmfs + create_nica_script_for_centos7 + fi + ;; + + Ubuntu) + echo "Installing toolbox on Ubuntu $OS_VERSION" + sudo apt install curl -y && . /etc/os-release + if [[ "$OS_VERSION" = "20.04" || "$OS_VERSION" = "18.04" ]];then + install_suse_podman_package + install_debian_toolbox_package + else + sudo apt install podman flatpak -y -qq + install_debian_toolbox_package + fi + ;; + + Debian) + echo "Installing toolbox on Debian $OS_VERSION" + sudo apt install podman flatpak curl -y + install_debian_toolbox_package + ;; + + *) + generate_unsupported_message + exit 1 + ;; + esac + +} + +function create_nica_script_for_centos7() { + + echo '#!/bin/bash +export ALIBUILD_WORK_DIR=$HOME/nica/sw +NICA_MODULES="/cvmfs/nica.jinr.ru/sw/MODULES/slc7_x86-64" +[ -d $NICA_MODULES ] && export MODULEPATH="$NICA_MODULES:$MODULEPATH"' | sudo tee -a /etc/profile.d/nica.sh + +} + +function install_suse_podman_package() { + + sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${OS_VERSION}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list" + wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${OS_VERSION}/Release.key -O- | sudo apt-key add - + sudo apt-get update -qq && sudo apt-get -qq -y install podman flatpak + +} + +function install_debian_toolbox_package() { + + rm -f ./podman-toolbox.deb + curl -o podman-toolbox.deb http://ftp.br.debian.org/debian/pool/main/g/golang-github-containers-toolbox/podman-toolbox_0.0.99.2-2_amd64.deb + sudo apt install ./podman-toolbox.deb -y -qq + rm -f ./podman-toolbox.deb + +} + +function generate_unsupported_message() { + + echo + echo " YOUR LINUX DISTRIBUTION MIGHT BE UNSUPPORTED BY THIS SCRIPT." + echo + echo " If your Linux distribution is based on any of the supported OS," + echo " then run the script according to the following example:" + echo + echo " nica-init.sh -d Ubuntu -v 21.10 " + echo + echo " In this example, your Linux distribution would be based on Ubuntu 21.10." + echo " Otherwise create a new issue at https://git.jinr.ru/nica/nicadist/-/issues" + echo " and request to support your distribution." + echo + echo " \"I Know Now Why You Cry, But It’s Something I Can Never Do.\"" + echo " T-800 (Terminator)" + echo + echo " YOU ARE TERMINATED..." + echo + +} + + +function install_cvmfs() { + + rm -f /tmp/cvmfs_install + curl -o /tmp/cvmfs_install https://gitlab.com/ndmspc/user/-/raw/master/services/cvmfs/cvmfs_install + chmod +x /tmp/cvmfs_install + sudo /tmp/cvmfs_install + +} + + +function generate_summary() { + + echo "================================================" + echo + echo "INSTALLATION SUCCESSFUL" + echo + echo "How to use:" + echo + COUNTER=1 + if [[ $AUTOSTART = no ]]; then + echo "1. Start cvmfs service by:" + echo " sudo systemctl start cvmfs" + echo " (to enable autostart at boot - run once and forget: sudo systemctl enable cvmfs" + let COUNTER++ + echo + fi + if [[ "$OS" != "CentOS" || "$OS_VERSION" != "7" ]]; then + echo "$((COUNTER++)). Enter toolbox container by:" + echo " toolbox enter c${TOOLBOX_OS_VER}-alibuild-dev" + echo + MACHINE="toolbox" + else + echo "$((COUNTER++)). Your distribution is CentOS 7." + echo " You must first logout and then login again" + echo " before you will be able to load MPDRoot environment." + echo + MACHINE="centos7" + fi + echo "$COUNTER. Load MPDRoot environment as a user by:" + echo " [user@$MACHINE ]$ module add mpdroot/latest" + echo + echo " or MPDRoot environment as a developer by:" + echo " [user@$MACHINE ]$ module add mpddev/latest" + echo + echo "================================================" + +} + + +main "$@"