Give sysadm a proper mkport.sh script

This commit is contained in:
Kris Moore
2016-08-27 17:13:54 -04:00
parent 7f76acb950
commit c24bc90769
5 changed files with 37 additions and 88 deletions

125
mkport.sh
View File

@@ -2,23 +2,9 @@
# Helper script which will create the port / distfiles
# from a checked out git repo
get_last_rev_git()
{
oPWD=`pwd`
cd "${1}"
rev=0
rev=`git log -n 1 --date=raw . | grep 'Date:' | awk '{print $2}'`
cd "$oPWD"
if [ -n "$rev" ] ; then
echo "$rev"
return 0
else
rev=`git log -n 1 --date=raw . | grep 'Date:' | awk '{print $2}'`
echo $rev
return 0
fi
return 1
}
# Set the port
port="sysutils/sysadm"
dfile="sysadm"
massage_subdir() {
cd "$1"
@@ -27,6 +13,8 @@ massage_subdir() {
continue
fi
comment="`cat Makefile | grep 'COMMENT ='`"
echo "# \$FreeBSD\$
#
@@ -48,7 +36,7 @@ $comment
}
if [ -z "$1" ] ; then
echo "Usage: ./mkports.sh <portstree> <distfiles>"
echo "Usage: ./mkport.sh <portstree> <distfiles>"
exit 1
fi
@@ -58,8 +46,12 @@ if [ ! -d "${1}/Mk" ] ; then
fi
portsdir="${1}"
if [ -z "$portsdir" -o "${portsdir}" = "/" ] ; then
portsdir="/usr/ports"
fi
if [ -z "$2" ] ; then
distdir="${1}/distfiles"
distdir="${portsdir}/distfiles"
else
distdir="${2}"
fi
@@ -67,80 +59,37 @@ if [ ! -d "$distdir" ] ; then
mkdir -p ${distdir}
fi
ODIR=`pwd`
# Get this jail version
export UNAME_r="`freebsd-version`"
# Get the GIT tag
ghtag=`git log -n 1 . | grep '^commit ' | awk '{print $2}'`
# Get the version
if [ -e "version" ] ; then
verTag=$(cat version)
else
verTag=$(date '+%Y%m%d%H%M')
fi
# Read the list of ports and build them now
while read pline
do
# Cleanup old distfiles
rm ${distdir}/${dfile}-* 2>/dev/null
cd "$ODIR"
ldir=`echo $pline | awk '{print $1}'`
# Copy ports files
if [ -d "${portsdir}/${port}" ] ; then
rm -rf ${portsdir}/${port} 2>/dev/null
fi
cp -r port-files ${portsdir}/${port}
# Check for sub-dir
echo "$ldir" | grep -q '/'
if [ $? -eq 0 ] ; then
lsubdir=`echo $ldir | cut -d '/' -f 1`
ltopdir=`echo $ldir | cut -d '/' -f 2`
tOps="-C $lsubdir $ltopdir"
else
unset lsubdir ltopdir
tOps="$ldir"
fi
# Set the version numbers
sed -i '' "s|%%CHGVERSION%%|${verTag}|g" ${portsdir}/${port}/Makefile
sed -i '' "s|%%GHTAG%%|${ghtag}|g" ${portsdir}/${port}/Makefile
tdir=`echo $pline | awk '{print $2}'`
tcat=`echo $tdir | cut -d '/' -f 1`
dfile=`echo $pline | awk '{print $3}'`
# Create the makesums / distinfo file
cd "${portsdir}/${port}"
make makesum
if [ $? -ne 0 ] ; then
echo "Failed makesum"
exit 1
fi
# Get git revision number
REV=`get_last_rev_git "./$ldir"`
port=`echo $pline | awk '{print $2}'`
tverfile="/tmp/.pcbsd-tests/`echo $port | sed 's|/|_|g'`"
if [ -e "$tverfile" -a -n "$PCBSD_MKTESTS" ] ; then
# If this file exists, we did a previous build of this port
oVer=`cat $tverfile`
echo "$port - $REV - $oVer -"
if [ "$REV" = "$oVer" ] ; then
echo "No changes to port: $port"
continue
fi
fi
# Make the dist files
rm ${distdir}/${dfile}-* 2>/dev/null
echo "Creating $tdir dist file for version: $REV"
tar cvJf ${distdir}/${dfile}-${REV}.tar.xz --exclude .git $tOps 2>/dev/null >/dev/null
if [ $? -ne 0 ] ; then
echo "Error creating distfile..."
exit 1
fi
# Copy ports files
if [ -d "${portsdir}/$tdir" ] ; then
rm -rf ${portsdir}/$tdir 2>/dev/null
fi
cp -r ${ldir}/port-files ${portsdir}/$tdir
# Set the version numbers
sed -i '' "s|%%CHGVERSION%%|${REV}|g" ${portsdir}/$tdir/Makefile
sed -i '' "s|%%GHTAG%%|${ghtag}|g" ${portsdir}/$tdir/Makefile
# Create the makesums / distinfo file
cd "${portsdir}/$tdir"
make makesum PORTSDIR=${portsdir}
if [ $? -ne 0 ] ; then
echo "Failed makesum"
exit 1
fi
# Now make sure subdir Makefile is correct
massage_subdir "${portsdir}/$tcat"
done < mkports-list
# Update port cat Makefile
tcat=$(echo $port | cut -d '/' -f 1)
massage_subdir ${portsdir}/${tcat}