#!/bin/sh
### the list of the ports that shall be updated from sources
portslist="\
security/cyrus-sasl2 \
devel/subversion \
devel/git \
graphics/drm-fbsd12.0-kmod \
net/netatalk3 \
net/samba48 \
www/closure-compiler \
www/yuicompressor \
"
### fetching FreeBSD system updates
/usr/bin/printf "Fetching FreeBSD system updates...\n"
PAGER=/bin/cat
/usr/sbin/freebsd-update fetch
### fetching updates of the FreeBSD ports tree
/usr/bin/printf "\nFetching updates of the FreeBSD ports tree...\n"
/usr/sbin/portsnap fetch update
/usr/sbin/pkg version -v
/usr/sbin/pkg updating -d `date -v-2w +%Y%m%d`
### ask and in case of y|Y run the updating processes
/usr/bin/printf "\nDo you want to continue (y/n)? "
save_stty_state=$(stty -g); stty raw -echo; answer=$(head -c 1); stty $save_stty_state
if echo "$answer" | grep -iq "^y" ; then
/usr/bin/printf "\n\n"
/usr/sbin/pkg update
portmake=""
pkgslist="`/usr/sbin/pkg query %o`"
for port in $portslist ; do
for pkg in $pkgslist ; do
if [ "$pkg" == "$port" ] ; then
continue 2
fi
done
portmake="$portmake $port"
done
pkgslist=""
outdated=`/usr/sbin/pkg version -l\< | /usr/bin/cut -f1 -w`
for outd in $outdated ; do
for port in $portslist ; do
if [ "$port" == "`/usr/sbin/pkg query %o $outd`" ] ; then
portmake="$portmake $port"
continue 2
fi
done
pkgslist="$pkgslist `/usr/sbin/pkg query %n $outd`"
done
pkgupgrd=""
outdated=`/usr/sbin/pkg version -RU -l\< | /usr/bin/cut -f1 -w`
for outd in $outdated ; do
outd=`/usr/sbin/pkg query %n $outd`
for pkg in $pkgslist ; do
if [ "$pkg" == "$outd" ] ; then
pkgupgrd="$pkgupgrd $outd"
continue 2
fi
done
done
/usr/bin/printf "\nUpdating binary packages...\n"
if [ "$pkgupgrd" != "" ] ; then
/usr/sbin/pkg upgrade -U $pkgupgrd
else
echo "All installed packages are up-to-date."
fi
/usr/bin/printf "\nUpdating ports...\n"
if [ "$portmake" != "" ] ; then
for port in $portmake ; do
echo "$port"
done
### ask and in case of y|Y run the updating processes
/usr/bin/printf "\nDo you want to continue (y/n)? "
save_stty_state=$(stty -g); stty raw -echo; answer=$(head -c 1); stty $save_stty_state
/usr/bin/printf "\n\n"
if echo "$answer" | grep -iq "^y" ; then
cwd=$PWD
py="py36-"
for port in $portmake ; do
cd "/usr/ports/$port"
/usr/bin/make deinstall clean
if [ "${port#$py}" != "$port" ]; then
/usr/bin/make FLAVOR=py36 install clean
else
/usr/bin/make install clean
fi
done
cd "$cwd"
fi
else
echo "All installed ports are up-to-date."
fi
/usr/bin/printf "\nCleaning up...\n"
/usr/sbin/pkg clean -ay
/usr/bin/find /usr/ports/distfiles -type f -mtime +4w -delete
/usr/bin/find /usr/ports/distfiles -type d -depth +0 -and -empty -delete
else
/usr/bin/printf "\n\n"
fi