From: Mike Frysinger Date: Sun, 5 Jan 2014 15:14:35 +0000 (-0500) Subject: mkrelease: clean up bash style X-Git-Tag: v2.2.8~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=122cb5a9d81f799f48267535298d7eb011309135;p=portage.git mkrelease: clean up bash style --- diff --git a/mkrelease.sh b/mkrelease.sh index a2b5c3677..50bdb3cd0 100755 --- a/mkrelease.sh +++ b/mkrelease.sh @@ -1,4 +1,6 @@ #!/bin/bash +# Copyright 2008-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 RELEASE_BUILDDIR=${RELEASE_BUILDDIR:-/var/tmp/portage-release} SOURCE_DIR=${RELEASE_BUILDDIR}/checkout @@ -7,20 +9,24 @@ USE_TAG=false CHANGELOG_REVISION= UPLOAD_LOCATION= -die() { - echo $@ +usage() { echo "Usage: ${0##*/} [--changelog-rev ] [-t|--tag] [-u|--upload ] " - exit 1 + exit ${1:-0} } -ARGS=$(getopt -o tu: --long changelog-rev:,tag,upload: \ - -n ${0##*/} -- "$@") +die() { + printf 'error: %s\n' "$*" + usage 1 +} + +ARGS=$(getopt -o htu: --long help,changelog-rev:,tag,upload: \ + -n "${0##*/}" -- "$@") [ $? != 0 ] && die "initialization error" eval set -- "${ARGS}" while true; do - case "$1" in + case $1 in --changelog-rev) CHANGELOG_REVISION=$2 shift 2 @@ -30,9 +36,12 @@ while true; do shift ;; -u|--upload) - UPLOAD_LOCATION=${2} + UPLOAD_LOCATION=$2 shift 2 ;; + -h|--help) + usage + ;; --) shift break @@ -43,33 +52,33 @@ while true; do esac done -[ -z "$1" ] && die "Need version argument" -[ -n "${1/[0-9]*}" ] && die "Invalid version argument" +[ $# != 1 ] && die "Need version argument" +[[ -n ${1/[0-9]*} ]] && die "Invalid version argument" -VERSION=${1} +VERSION=$1 RELEASE=portage-${VERSION} RELEASE_DIR=${RELEASE_BUILDDIR}/${RELEASE} RELEASE_TARBALL="${RELEASE_BUILDDIR}/${RELEASE}.tar.bz2" -TREE_ISH=$BRANCH -if [[ $USE_TAG = true ]] ; then - TREE_ISH=v$VERSION +TREE_ISH=${BRANCH} +if [[ ${USE_TAG} == "true" ]] ; then + TREE_ISH="v${VERSION}" fi echo ">>> Cleaning working directories ${RELEASE_DIR} ${SOURCE_DIR}" rm -rf "${RELEASE_DIR}" "${SOURCE_DIR}" || die "directory cleanup failed" mkdir -p "${RELEASE_DIR}" || die "directory creation failed" -mkdir -p "$SOURCE_DIR" || die "mkdir failed" +mkdir -p "${SOURCE_DIR}" || die "mkdir failed" echo ">>> Starting GIT archive" -git archive --format=tar $TREE_ISH | \ - tar -xf - -C "$SOURCE_DIR" || die "git archive failed" +git archive --format=tar ${TREE_ISH} | \ + tar -xf - -C "${SOURCE_DIR}" || die "git archive failed" echo ">>> Building release tree" cp -a "${SOURCE_DIR}/"{bin,cnf,doc,man,misc,pym} "${RELEASE_DIR}/" || die "directory copy failed" cp "${SOURCE_DIR}/"{DEVELOPING,LICENSE,Makefile,NEWS,README,RELEASE-NOTES,TEST-NOTES} \ "${RELEASE_DIR}/" || die "file copy failed" -rm -rf "$SOURCE_DIR" || die "directory cleanup failed" +rm -rf "${SOURCE_DIR}" || die "directory cleanup failed" echo ">>> Setting portage.VERSION" sed -e "s/^VERSION=.*/VERSION=\"${VERSION}\"/" \ @@ -78,21 +87,21 @@ sed -e "s/^VERSION=.*/VERSION=\"${VERSION}\"/" \ echo ">>> Creating Changelog" git_log_opts="" -if [ -n "$CHANGELOG_REVISION" ] ; then - git_log_opts+=" $CHANGELOG_REVISION^..$TREE_ISH" +if [[ -n ${CHANGELOG_REVISION} ]] ; then + git_log_opts+=" ${CHANGELOG_REVISION}^..${TREE_ISH}" else - git_log_opts+=" $TREE_ISH" + git_log_opts+=" ${TREE_ISH}" fi skip_next=false -git log $git_log_opts | fmt -w 80 -p " " | while read -r ; do - if [[ $skip_next = true ]] ; then +git log ${git_log_opts} | fmt -w 80 -p " " | while read -r ; do + if [[ ${skip_next} == "true" ]] ; then skip_next=false - elif [[ $REPLY = " svn path="* ]] ; then + elif [[ ${REPLY} == " svn path="* ]] ; then skip_next=true else - echo "$REPLY" + echo "${REPLY}" fi -done > "$RELEASE_DIR/ChangeLog" || die "ChangeLog creation failed" +done > "${RELEASE_DIR}/ChangeLog" || die "ChangeLog creation failed" cd "${RELEASE_BUILDDIR}" @@ -101,16 +110,16 @@ tar --owner portage --group portage -cjf "${RELEASE_TARBALL}" "${RELEASE}" || \ die "tarball creation failed" DISTDIR=$(portageq distdir) -if [ -n "${DISTDIR}" -a -d "${DISTDIR}" -a -w "${DISTDIR}" ]; then +if [[ -n ${DISTDIR} && -d ${DISTDIR} && -w ${DISTDIR} ]] ; then echo ">>> Copying release tarball into ${DISTDIR}" cp "${RELEASE_TARBALL}" "${DISTDIR}"/ || echo "!!! tarball copy failed" fi -if [ -n "${UPLOAD_LOCATION}" ]; then +if [[ -n ${UPLOAD_LOCATION} ]] ; then echo ">>> Uploading ${RELEASE_TARBALL} to ${UPLOAD_LOCATION}" scp "${RELEASE_TARBALL}" "dev.gentoo.org:${UPLOAD_LOCATION}" || die "upload failed" else - echo "${RELEASE_TARBALL} created" + du -h "${RELEASE_TARBALL}" fi exit 0