diff --git a/scripts/prepare-maint-update b/scripts/prepare-maint-update index a80944d..7439b40 100755 --- a/scripts/prepare-maint-update +++ b/scripts/prepare-maint-update @@ -8,34 +8,76 @@ blu=$(tput setaf 4) nrm=$(tput sgr0) sn="${0##*/}" -if [ $# -lt 1 ]; then - printf "${Red}usage:${nrm} %s [branch] [kgraft_prj]\n" "$sn" >&2 +usage() { + printf "${Red}usage:${nrm} %s [-h] [-g ] [-t tbranch] branch\n" "$sn" + #rintf "usage: " + printf " Arg Example\n" + printf " kgraft_prj SLE15-SP5_Update_9\n" + printf " tbranch SLE15-SP5 (specify target when branch is a user branch)\n" + printf " branch SLE15-SP5\n" +} + +OPTS=$(getopt -o g:t:h -n "$sn" -- "$@") +eval set -- "$OPTS" +unset OPTS + +while true ; do + case "$1" in + '-g') + lp_proj="$2" + shift 2 + ;; + '-t') + tbranch="$2" + shift 2 + ;; + '-h') + usage >&2 + exit 0 + ;; + '--') + shift + break + ;; + *) + printf "${Red}Args parsing error${nrm}\n" >&2 + exit 1 + ;; + esac + continue +done +if [ $# -ne 1 ]; then + usage >&2 + exit 1 +fi + +branch="$1" +tbranch="${tbranch:-${branch}}" +if [[ "${tbranch}" =~ / ]] ; then + printf "${Red}Specify target branch explicitly without user prefix${nrm}\n" >&2 exit 1 fi -tbranch="$1" -prod="${1%-LTSS}" -branch="${2:-$tbranch}" -lp_proj="${3}" OSC_DIR="${OSC_DIR:-/tmp}" OSC="osc -A https://api.suse.de/" -target="SUSE:SLE-${prod#SLE}:Update" +prod="${tbranch%-LTSS}" +target="SUSE:SLE-${prod#SLE}:Update" # this may be a parameter in future prj="Devel:Kernel:${tbranch}:Submit" kgraft_dir="Devel:kGraft:patches" if [ ! -d "$KSOURCE_GIT" ]; then - printf "${Red}Error: directory '%s' does not exist${nrm}\n" "$KSOURCE_GIT" - echo "Please set KSOURCE_GIT to the location of local kernel-source repository." + printf "${Red}Error: directory '%s' does not exist${nrm}\n" "$KSOURCE_GIT" >&2 + echo "Please set KSOURCE_GIT to the location of local kernel-source repository." >&2 exit 1 fi if [ ! -d "$OSC_DIR" ]; then - printf "${Red}Error: directory '%s' does not exist${nrm}\n" "$OSC_DIR" - echo "Please set OSC_DIR to a directory to use for OBS/IBS checkouts." + printf "${Red}Error: directory '%s' does not exist${nrm}\n" "$OSC_DIR" >&2 + echo "Please set OSC_DIR to a directory to use for OBS/IBS checkouts." >&2 exit 1 fi if ! $OSC api /about >/dev/null ; then - echo "${Red}Error: Cannot login to OBS${nrm}" - printf "Check your SSH key setup in .oscrc for '%s'\n" "$OSC" + echo "${Red}Error: Cannot login to OBS${nrm}" >&2 + printf "Check your SSH key setup in .oscrc for '%s'\n" "$OSC" >&2 exit 1 fi @@ -57,8 +99,8 @@ printf "Target branch: ${blu}%s${nrm}\n" "$tbranch" printf "Submission branch: ${blu}%s${nrm}\n" "$branch" printf "Commit: ${grn}%s${nrm}\n" \ $(git --no-pager show -s --pretty='%h' "$branch") -printf "Version: ${blu}%s${nrm}\n" "$version" -printf "Update: ${blu}%u${nrm}\n" "$upd" +printf "Version: ${blu}%s${nrm}\n" "$version" +printf "Kgraft prj: ${blu}%s${nrm}\n" "$lp_proj" echo if ! git merge-base --is-ancestor "$branch" "$tbranch"; then