File checkin.sh of Package ceph-haproxy-image

#!/bin/bash
#
# checkin.sh
#
# This script automates generation of a new overlay tarball from a
# git clone for the "haproxy" image in OBS.
#

#set -x

BASEDIR=$(pwd)

EXISTING=""
REPO="https://github.com/docker-library/haproxy.git"
VERSION="2.3"
OVERLAY="root.tar.gz"

function usage {
    set +x
    echo "Usage:"
    echo "  ${0} [-h,--help] [-e,--existing CLONE]"
    echo "             [-r,--repo REPO] [-v,--version VERSION]"
    echo ""
    echo "Options:"
    echo "    --existing  Use existing git clone CLONE"
    echo "    --repo      Make a fresh clone of git repo REPO"
    echo "    --version   Use version VERSION directory from the git clone"
    echo ""
    echo "Notes:"
    echo "    If existing clone is given, repo is ignored."
    echo "    Repo defaults to $REPO"
    echo "    Version defaults to $VERSION"
    exit 1
}

function _error_exit {
    echo >&2 $1
    exit $2
}

GETOPT=$(getopt -o v:e:hr --long "version:,existing:,help,repo:" \
       -n 'checkin.sh' -- "$@")
test "$?" -eq 0 || _error_exit "Terminating..." 1
eval set -- "$GETOPT"

while true ; do
    case "$1" in
        -e|--existing) EXISTING="$2" ; shift 2 ;;
        -h|--help)     usage ;; # does not return
        -r|--repo)     REPO="$2"     ; shift 2 ;;
        -v|--version)  VERSION="$2"   ; shift 2 ;;
        --) shift ; break ;;
        *) echo "Internal error" ; exit 1 ;;
    esac
done

if [ -n "$EXISTING" ] ; then
    if [ ! -d "$EXISTING" ] ; then
        _error_exit "Alleged directory ->$EXISTING<- is not a directory" 1
    fi
    if [ ! -r "$EXISTING" ] ; then
        _error_exit "I cannot read directory ->$EXISTING<-" 1
    fi
    if [ ! -w "$EXISTING" ] ; then
        _error_exit "I cannot write to directory ->$EXISTING<-" 1
    fi
    if [ ! -x "$EXISTING" ] ; then
        _error_exit "I cannot cd to directory ->$EXISTING<-" 1
    fi
    CLONE="$EXISTING"
else
    echo "Will make fresh clone of repo ->$REPO<-"
    TMPDIR=$(mktemp -d --tmpdir=$BASEDIR)
    echo "Created temporary temporary $TMPDIR"
    git clone --progress $REPO $TMPDIR
    CLONE="$TMPDIR"
fi

echo "Creating new tarball from $CLONE"
tar -C $CLONE/$VERSION -czvf $OVERLAY docker-entrypoint.sh

if [ -n "$TMPDIR" ] ; then
    echo "Nuking the clone"
    rm -rf $TMPDIR
fi

echo "Done! Run \"osc ci --noservice\" to commit."
openSUSE Build Service is sponsored by