BootStrap: library
From: library://library/default/centos:7

%post
    # set hostname
    echo "md" >> /etc/hostname

    # verify new hostname
    # cat /etc/hostname

    # enable DNS
    echo "nameserver 8.8.8.8" > /etc/resolv.conf

#------------------------------------------------------------------------
#   yum
#------------------------------------------------------------------------

    # update system
    yum -y update && yum -y upgrade

    # install packages
    yum -y install gcc glibc libglvnd-glx libXi libXi-devel libXinerama \
                   libXinerama-devel make openmpi openmpi-devel \
                   openssh-server openssh-clients python3 sudo tcl wget

#------------------------------------------------------------------------
#   SSH
#------------------------------------------------------------------------

    # start SSH service
    systemctl start sshd

    # check SSH daemon status
    systemctl status sshd

    # enable SSH service
    systemctl enable sshd

#------------------------------------------------------------------------
#   Perl
#------------------------------------------------------------------------

    # create Perl directory
    mkdir -p ~/install/perl && cd ~/install/perl

    # obtain Perl source code
    wget https://www.cpan.org/src/5.0/perl-5.34.0.tar.gz

    # extract Perl source code
    tar -xzvf perl-5.34.0.tar.gz

    # change to Perl directory
    cd perl-5.34.0

    # configure Perl installation
    ./Configure -des -Dprefix=/usr/local

    # compile, test and install Perl
    # make && make test && make install
    make && make install

#------------------------------------------------------------------------
#   VMD
#------------------------------------------------------------------------

    # create VMD directory
    mkdir -p ~/install/vmd && cd ~/install/vmd

    # download VMD source code
    export VMD_DISTRO=vmd-1.9.3.bin.LINUXAMD64-CUDA8-OptiX4-OSPRay111p1.opengl
    wget --no-check-certificate https://www.ks.uiuc.edu/Research/vmd/vmd-1.9.3/files/final/$VMD_DISTRO.tar.gz

    # extract VMD
    tar -xzvf $VMD_DISTRO.tar.gz

    # configure VMD installation
    cd vmd-1.9.3 && ./configure

    # install VMD
    cd src && make install

#------------------------------------------------------------------------
#   NAMD
#------------------------------------------------------------------------

    # create directories: install, namd
    mkdir -p ~/install/namd && cd ~/install/namd

    # download NAMD source code
    export NAMD_DISTRO=NAMD_2.13_Linux-x86_64-ibverbs-smp
    wget --no-check-certificate https://www.ks.uiuc.edu/Research/namd/2.13/download/412487/$NAMD_DISTRO.tar.gz

    # extract NAMD
    tar -xzvf $NAMD_DISTRO.tar.gz

    # prepare NAMD directory in /opt
    mkdir -p /opt/namd-2.13-ibverbs-smp
    ln -fs /opt/namd-2.13-ibverbs-smp /opt/namd
    mkdir -p /opt/namd/bin /opt/namd/doc /opt/namd/lib

    # setup NAMD in /opt directory
    cp -frv $NAMD_DISTRO/lib/* /opt/namd/lib
    cp -frv $NAMD_DISTRO/*.txt /opt/namd/doc
    find $NAMD_DISTRO -maxdepth 1 -executable -type f -exec cp -frv {} /opt/namd/bin \;

%environment

    # VMD
    export VMD_PATH=/usr/local/bin
    export PATH=$VMD_PATH:$PATH

    # NAMD
    export NAMD_PATH=/opt/namd/bin
    export PATH=$NAMD_PATH:$PATH

    # OpenMPI
    export OMPI_PATH=/usr/lib64/openmpi
    export PATH=$OMPI_PATH/bin:$PATH
    export LD_LIBRARY_PATH=$OMPI_PATH/lib:$LD_LIBRARY_PATH

%runscript

#------------------------------------------------------------------------
#   Verification
#------------------------------------------------------------------------

    # verify Perl version
    perl --version

    # verify OpenMPI version
    mpicc --version && mpiexec --version

    # verify VMD directory structure
    ls -l /usr/local/bin
    ls -l /usr/local/lib

    # verify NAMD directory structure
    ls -l /opt/namd/bin
    ls -l /opt/namd/lib
    ls -l /opt/namd/doc

#------------------------------------------------------------------------
#   System preparation
#------------------------------------------------------------------------

    # ...
