#!/bin/bash #emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- #ex: set sts=4 ts=4 sw=4 noet: # # A helper to freeze (and possibly downgrade) versions of specified containers. # # Example invocation: # # freeze_versions bids-mriqc=0.15.0 bids-fmriprep=1.4.1 bids-aa # # COPYRIGHT: Yaroslav Halchenko 2019 # # LICENSE: MIT # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # PS4=+ set -eu # from repronim/simple_workflow Simple_Prep_docker # a little helper since sed on OSX does not have sed -i # for in-place modifications. Note that filename here comes first # just to ease scripting sed-i () { filename=$1 tfilename=$(mktemp -t sed_replace.XXXXXXXXX) shift sed "$@" "$filename" >| "$tfilename" mv "$tfilename" "$filename" } cd "$(dirname "$0")/.." save_ds= frozen= for arg in "$@"; do case "$arg" in --save-dataset=*) save_ds="${arg#*=}"; continue;; esac frozen="$frozen $arg" img=${arg%%=*} if [ "$img" != "$arg" ]; then ver=${arg#*=} echo "I: $img -> $ver" imgpath="images/${img%%-*}/${img}--${ver}.sing" # Check if exists! we cannot freeze to unknown. There is no easy # check if file exists as a symlink or not if ! /bin/ls -d "$imgpath" &>/dev/null ; then echo "E: there is no $imgpath . Available images for the app are:" /bin/ls -1 "images/${img%%-*}/${img}--"* | sed -e 's,^, ,g' exit 1 fi git config -f .datalad/config --replace-all "datalad.containers.$img.image" "$imgpath" else # freeze to current imgpath=$(git config -f .datalad/config "datalad.containers.$img.image") fi # and we would add the comment so that upon upgrade there for sure would be # a conflict needed to be consciousely resolved (or -S ours used) sed-i .datalad/config -e "s,$imgpath\([ \\t].*\)*$,$imgpath # frozen,g" done if [[ -n "$save_ds" ]]; then datalad save -d"$save_ds" -m "Freeze container versions $frozen" .datalad/config fi