#!/bin/sh
#
# Create all packages with sym-links for FreeBSD 5.x+
#
# Version: 1.1
# Copyright (c) 2006 Alexey Tsvetnov, vorakl@fbsd.kiev.ua
#
# Path to packages directory
packagespath="/usr/ports/packages"
# Command for get package's version
pkgvercmd="/usr/sbin/pkg_version -v"
#pkgvercmd="/usr/local/sbin/portversion -v" # more faster than pkg_version
checkPackagesPath ()
{
[ -d $packagespath ] || { /bin/echo " <li> Error: $packagespath doesn't exist."; exit 1; }
[ -d $packagespath/All ] || { /bin/mkdir $packagespath/All || exit 1; }
[ -d $packagespath/Latest ] || { /bin/mkdir $packagespath/Latest || exit 1; }
return 0
}
checkPkgAll ()
{
[ -f $packagespath/All/$fullname.tbz ] && return 0
return 1
}
checkPkgLatest ()
{
[ -L $packagespath/Latest/$shortname.tbz ] && [ -r $packagespath/Latest/$shortname.tbz ] && return 0
return 1
}
checkPkgCat ()
{
[ -L $packagespath/$subdir/$fullname.tbz ] && [ -r $packagespath/$subdir/$fullname.tbz ] && return 0
return 1
}
createPkgAll ()
{
/usr/sbin/pkg_create -jb $fullname $packagespath/All/$fullname.tbz && return 0
return 1
}
createPkgLatest ()
{
/bin/rm -f $packagespath/Latest/$shortname.tbz
cd $packagespath/Latest && /bin/ln -s ../All/$fullname.tbz $shortname.tbz && return 0
return 1
}
createPkgCat ()
{
if [ -d $packagespath/$subdir ]; then
/bin/rm -f $packagespath/$subdir/$fullname.tbz
else
/bin/mkdir -p $packagespath/$subdir
fi
cd $packagespath/$subdir && /bin/ln -s ../All/$fullname.tbz $fullname.tbz && return 0
return 1
}
getPkgFullVersion ()
{
pkglist=`$pkgvercmd | /usr/bin/awk '{print $1}'`
}
work ()
{
for fullname in $pkglist; do
/bin/echo "Check $fullname"
shortname=`/bin/echo $fullname | /usr/bin/sed 's/\-[^-]*$//'`
subdir=`/usr/sbin/pkg_info -o $fullname | /usr/bin/sed -e '1,3d' -e '$d' | /usr/bin/awk -F/ '{print $1}'`
if ! checkPkgAll; then
/bin/echo -n " ==> Create package..."
if createPkgAll; then /bin/echo "Ok"
else /bin/echo "Err"
fi
/bin/echo -n " ==> Create Latest sym-link..."
if createPkgLatest; then /bin/echo "Ok"
else /bin/echo "Err"
fi
/bin/echo -n " ==> Create Category sym-link..."
if createPkgCat; then /bin/echo "Ok"
else /bin/echo "Err"
fi
continue
fi
if ! checkPkgLatest; then
/bin/echo -n " ==> Create Latest sym-link..."
if createPkgLatest; then /bin/echo "Ok"
else /bin/echo "Err"
fi
fi
if ! checkPkgCat; then
/bin/echo -n " ==> Create Category sym-link..."
if createPkgCat; then /bin/echo "Ok"
else /bin/echo "Err"
fi
fi
done
}
main ()
{
checkPackagesPath
getPkgFullVersion
work
}
main
exit 0
URL:
Обсуждается: http://www.opennet.dev/tips/info/992.shtml