326 lines
6.2 KiB
Bash
Executable File
326 lines
6.2 KiB
Bash
Executable File
#!/bin/sh
|
|
#$Id$
|
|
#Copyright (c) 2012-2020 Pierre Pronchery <khorben@defora.org>
|
|
#This file is part of DeforaOS Devel scripts
|
|
#
|
|
#Redistribution and use in source and binary forms, with or without
|
|
#modification, are permitted provided that the following conditions
|
|
#are met:
|
|
#1. Redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer.
|
|
#2. Redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution.
|
|
#
|
|
#THIS SOFTWARE IS PROVIDED BY THE EDGEBSD PROJECT AND CONTRIBUTORS
|
|
#``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
#TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
#PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
#BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
#CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
#SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
#INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
#CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
#ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
#POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#environment
|
|
#executables
|
|
CONFIGURE="configure"
|
|
CONFIGURE_UPDATE="configure-update"
|
|
CVS="cvs"
|
|
GIT="git"
|
|
GREP="grep"
|
|
MAKE="make"
|
|
RM="rm -f"
|
|
TAR="tar"
|
|
TR="tr"
|
|
WC="wc"
|
|
#settings
|
|
DEBUG=
|
|
DEVNULL="/dev/null"
|
|
DESKTOPEXT=".desktop"
|
|
DISTEXT=".tar.gz"
|
|
DRYRUN=0
|
|
FORCE=0
|
|
GIT_BRANCH="master"
|
|
HOMEPAGE="https://www.defora.org"
|
|
PACKAGE=
|
|
POEXT=".po"
|
|
POTEXT=".pot"
|
|
PREFIX="/usr/local"
|
|
PROGNAME="deforaos-release"
|
|
PROJECTCONF="project.conf"
|
|
SYSCONFDIR="$PREFIX/etc"
|
|
VENDOR="deforaos"
|
|
VERBOSE=0
|
|
VERSION=
|
|
#load local settings
|
|
[ -f "$SYSCONFDIR/DeforaOS/$PROGNAME.conf" ] &&
|
|
. "$SYSCONFDIR/DeforaOS/$PROGNAME.conf"
|
|
[ -f "$HOME/.config/DeforaOS/$PROGNAME.conf" ] &&
|
|
. "$HOME/.config/DeforaOS/$PROGNAME.conf"
|
|
|
|
|
|
#functions
|
|
#deforaos_release
|
|
_deforaos_release()
|
|
{
|
|
version="$1"
|
|
|
|
while read line; do
|
|
case "$line" in
|
|
"package="*)
|
|
PACKAGE="${line#package=}"
|
|
;;
|
|
"version="*)
|
|
VERSION="${line#version=}"
|
|
;;
|
|
esac
|
|
done < "$PROJECTCONF"
|
|
if [ -z "$PACKAGE" -o -z "$VERSION" ]; then
|
|
_error "Could not determine the package name or version"
|
|
return $?
|
|
fi
|
|
_info "Releasing $PACKAGE $VERSION"
|
|
|
|
if [ "$version" != "$VERSION" ]; then
|
|
_error "The version does not match"
|
|
return $?
|
|
fi
|
|
|
|
_info "Obtaining latest version..."
|
|
_release_fetch
|
|
if [ $? -ne 0 ]; then
|
|
_error "Could not update the sources"
|
|
return $?
|
|
fi
|
|
|
|
#checking the desktop files
|
|
for i in data/*$DESKTOPEXT; do
|
|
[ ! -e "$i" ] && break
|
|
basename="${i#data/}"
|
|
if [ "$basename" = "${basename#$VENDOR-}" ]; then
|
|
_error "data/$basename has no vendor prefix"
|
|
return $?
|
|
fi
|
|
done
|
|
|
|
if [ -f "po/$PACKAGE$POTEXT" ]; then
|
|
_info "Checking the translations..."
|
|
$RM -- "po/$PACKAGE$POTEXT" || return 2
|
|
(cd "po" && $MAKE) || return 2
|
|
$GREP -q "fuzzy" -- po/*$POEXT
|
|
if [ $? -eq 0 ]; then
|
|
_error "Some translations are fuzzy"
|
|
return $?
|
|
fi
|
|
fi
|
|
|
|
#run configure again
|
|
_release_configure
|
|
|
|
#check for changes
|
|
_info "Checking for changes..."
|
|
_release_diff
|
|
if [ $? -ne 0 ]; then
|
|
_error "The sources were modified"
|
|
return $?
|
|
fi
|
|
|
|
#create the archive
|
|
_info "Creating the archive..."
|
|
archive="$PACKAGE-$VERSION$DISTEXT"
|
|
target="distcheck"
|
|
[ $FORCE -ne 0 ] && target="dist"
|
|
$DEBUG $MAKE "$target"
|
|
if [ $? -ne 0 -o ! -f "$archive" ]; then
|
|
_error "Could not create the archive"
|
|
return $?
|
|
fi
|
|
|
|
#tagging the release
|
|
tag="${PACKAGE}_$(echo "$version" | $TR . -)"
|
|
_info "Tagging the sources as $tag..."
|
|
_release_tag "$tag"
|
|
if [ $? -ne 0 ]; then
|
|
_error "Could not tag the sources"
|
|
return $?
|
|
fi
|
|
|
|
#all tests passed
|
|
_info "$PACKAGE version $VERSION is ready for release in"
|
|
_info "$archive."
|
|
_info "The following steps are:"
|
|
_info " * upload to $HOMEPAGE/os/project/submit/@ID@/$PACKAGE?type=release"
|
|
_info " * publish a news on $HOMEPAGE/os/news/submit"
|
|
_info " * tweet (possibly via freecode)"
|
|
_info " * package where appropriate (see deforaos-package.sh)"
|
|
}
|
|
|
|
_release_configure()
|
|
{
|
|
if [ -f "$PROJECTCONF" ]; then
|
|
$DEBUG $CONFIGURE_UPDATE &&
|
|
$DEBUG $CONFIGURE
|
|
return $?
|
|
fi
|
|
return 0
|
|
}
|
|
|
|
_release_diff()
|
|
{
|
|
if [ -d "CVS" ]; then
|
|
_release_diff_cvs
|
|
return $?
|
|
elif [ -d ".git" ]; then
|
|
_release_diff_git
|
|
return $?
|
|
else
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
_release_diff_cvs()
|
|
{
|
|
#XXX this method may be obsoleted in a future version of CVS
|
|
$DEBUG $CVS diff > "$DEVNULL"
|
|
}
|
|
|
|
_release_diff_git()
|
|
{
|
|
$DEBUG $GIT status > "$DEVNULL"
|
|
$DEBUG $GIT diff --quiet
|
|
}
|
|
|
|
_release_fetch()
|
|
{
|
|
if [ -d "CVS" ]; then
|
|
_release_fetch_cvs
|
|
return $?
|
|
elif [ -d ".git" ]; then
|
|
_release_fetch_git
|
|
return $?
|
|
else
|
|
return 2
|
|
fi
|
|
}
|
|
|
|
_release_fetch_cvs()
|
|
{
|
|
$DEBUG $CVS up -A
|
|
}
|
|
|
|
_release_fetch_git()
|
|
{
|
|
if [ -n "$GIT_BRANCH" ]; then
|
|
$DEBUG $GIT checkout "$GIT_BRANCH" || return 2
|
|
fi
|
|
$DEBUG $GIT pull
|
|
}
|
|
|
|
_release_tag()
|
|
{
|
|
tag="$1"
|
|
|
|
if [ $DRYRUN -ne 0 ]; then
|
|
return 0
|
|
elif [ -d "CVS" ]; then
|
|
_release_tag_cvs "$tag"
|
|
return $?
|
|
elif [ -d ".git" ]; then
|
|
_release_tag_git "$tag"
|
|
return $?
|
|
fi
|
|
return 2
|
|
}
|
|
|
|
_release_tag_cvs()
|
|
{
|
|
tag="$1"
|
|
|
|
$DEBUG $CVS tag "$tag"
|
|
}
|
|
|
|
_release_tag_git()
|
|
{
|
|
tag="$1"
|
|
|
|
$DEBUG $GIT tag -m "$PACKAGE $VERSION" "$tag" || return 2
|
|
$DEBUG $GIT push --tags || return 2
|
|
}
|
|
|
|
|
|
#debug
|
|
_debug()
|
|
{
|
|
echo "$@" 1>&2
|
|
"$@"
|
|
}
|
|
|
|
|
|
#error
|
|
_error()
|
|
{
|
|
echo "$PROGNAME: error: $@" 1>&2
|
|
return 2
|
|
}
|
|
|
|
|
|
#info
|
|
_info()
|
|
{
|
|
[ "$VERBOSE" -ne 0 ] && echo "$PROGNAME: $@" 1>&2
|
|
return 0
|
|
}
|
|
|
|
|
|
#usage
|
|
_usage()
|
|
{
|
|
echo "Usage: $PROGNAME [-Dfnv] version" 1>&2
|
|
echo " -D Run in debugging mode" 1>&2
|
|
echo " -f Do not perform tests" 1>&2
|
|
echo " -n Do not actually publish changes (dry-run)" 1>&2
|
|
echo " -v Verbose mode" 1>&2
|
|
return 1
|
|
}
|
|
|
|
|
|
#main
|
|
#parse options
|
|
while getopts "DfnvO:" name; do
|
|
case "$name" in
|
|
D)
|
|
DEBUG="_debug"
|
|
;;
|
|
O)
|
|
export "${OPTARG%%=*}"="${OPTARG#*=}"
|
|
;;
|
|
f)
|
|
FORCE=1
|
|
;;
|
|
n)
|
|
DRYRUN=1
|
|
;;
|
|
v)
|
|
VERBOSE=1
|
|
;;
|
|
?)
|
|
_usage
|
|
exit $?
|
|
;;
|
|
esac
|
|
done
|
|
shift $((OPTIND - 1))
|
|
#parse arguments
|
|
if [ $# -ne 1 ]; then
|
|
_usage
|
|
exit $?
|
|
fi
|
|
version="$1"
|
|
|
|
_deforaos_release "$version"
|