Скрипт для автоматизации создания бинарных пакетов для FreeBSD |
[исправить] |
#!/bin/sh
#
# Create all packages with sym-links for FreeBSD 5.x+
#
# Version: 1.2.2
# Copyright (c) 2006 Alexey Tsvetnov, vorakl@fbsd.kiev.ua
#
# All error in /var/log/<script_name>.err
#
# 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
#-------------------------------------------------------------------------------
err="\033[0;40;31mError\033[0m"
ok="\033[1;40;33mOk\033[0m"
checkPackagesPath ()
{
[ -d $packagespath ] || { /usr/bin/printf " *** $err: $packagespath doesn't exist.\n";
/bin/echo " *** Error: $packagespath doesn't exist." > /var/log/`basename $0`.log;
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 ()
{
echo -n "Geting full version package list..."
pkglist=`$pkgvercmd | /usr/bin/awk '{print $1}'`
/usr/bin/printf "$ok\n"
}
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 /usr/bin/printf "$ok\n"
else /usr/bin/printf "$err\n"
fi
/bin/echo -n " ==> Create Latest sym-link..."
if createPkgLatest; then /usr/bin/printf "$ok\n"
else /usr/bin/printf "$err\n"
fi
/bin/echo -n " ==> Create Category sym-link..."
if createPkgCat; then /usr/bin/printf "$ok\n"
else /usr/bin/printf "$err\n"
fi
continue
fi
if ! checkPkgLatest; then
/bin/echo -n " ==> Create Latest sym-link..."
if createPkgLatest; then /usr/bin/printf "$ok\n"
else /usr/bin/printf "$err\n"
fi
fi
if ! checkPkgCat; then
/bin/echo -n " ==> Create Category sym-link..."
if createPkgCat; then /usr/bin/printf "$ok\n"
else /usr/bin/printf "$err\n"
fi
fi
done
}
main ()
{
exec 2>/var/log/`basename $0`.log
checkPackagesPath
getPkgFullVersion
work
exec 2>&-
}
main
exit 0
|
|
|
|
Раздел: Корень / Программисту и web-разработчику / Shell / Готовые скрипты |