Skip to content
Snippets Groups Projects
image-load 1.92 KiB
Newer Older
  • Learn to ignore specific revisions
  • Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    # !/bin/bash
    
    if [ -z "IMAGE_ROOT" ] || [ -z "IMAGE_OS" ] || [ -z "IMAGE_VERSION" ]; then
        echo -e "\e[31mAn error occured, exiting...\e[0m"
        exit 1
    fi
    
    
    VERSION=$(ls -t $IMAGE_ROOT | grep .simg | head -1)
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
    
    if [ ! -d "$HOME/.singularity/images" ]; then
       mkdir -p $HOME/.singularity/images
    fi
    
    LOCAL=$(ls $HOME/.singularity/images | grep $IMAGE_OS-$IMAGE_VERSION* | head -1)
    
    if [[ -z "$LOCAL" ]]; then
       echo -ne "\e[33mPreparing image \e[0m"
       rsync --progress -h $IMAGE_ROOT/$VERSION $HOME/.singularity/images/$VERSION
       LOCAL=$VERSION
    fi
    
    if [ "$LOCAL" \< "$VERSION" ]; then
       if [ "$1" == "shell" ]; then
          echo -ne "\e[33mNew version of $IMAGE_OS image was found.\e[0m (New: $VERSION Old: $LOCAL)\nDo you want to update local copy? (\e[31mWARNING all user modifications will be deleted\e[0m) [y/N]: "
          read CONTINUE
          if [ "$CONTINUE" == "y" ] || [ "$CONTINUE" == "Y" ]; then
            echo -ne "\e[32mUpdating image\e[0m "
            rsync --progress -h $IMAGE_ROOT/$VERSION $HOME/.singularity/images/$VERSION
            echo -e "\e[32mNew version is ready.\e[0m ($HOME/.singularity/images/$VERSION)"
            [ -f $HOME/.singularity/images/$LOCAL ] && rm $HOME/.singularity/images/$LOCAL
            LOCAL=$VERSION
          else
            echo -e "\e[31mIgnoring new version...\e[0m ($VERSION)."
          fi
       else
          echo -e "\e[33mNew version of $IMAGE_OS image was found.\e[0m (\e[33mNew:\e[0m $VERSION \e[33mOld:\e[0m $LOCAL)\nFor updating image use: \e[32mimage-update\e[0m"
       fi
    fi
    
    if [ "$1" == "shell" ]; then
      export IMAGE_PATH_LOCAL="$HOME/.singularity/images/$LOCAL"
    
      singularity shell --bind /scratch --bind /apps $HOME/.singularity/images/$LOCAL
    
    Lukáš Krupčík's avatar
    Lukáš Krupčík committed
      SYS=`/bin/cat /etc/centos-release`
      echo -e "\e[33mWelcome to the normal operating system ($SYS)\e[0m"
    else
      export IMAGE_PATH_LOCAL="$HOME/.singularity/images/$LOCAL"
      echo -e "\e[33mYour image of $IMAGE_OS/$IMAGE_VERSION is at location:\e[0m $HOME/.singularity/images/$LOCAL"
    fi