Last active
August 29, 2015 14:26
-
-
Save drm00/7b0fea93f67e0cdbc156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# update_check.sh | |
# | |
# check for new -stable code and update installed packages if nececcary. | |
# read http://www.openbsd.org/faq/faq15.html#PkgSig to self-sign your | |
# newly built packages. | |
# -- config | |
RECIPIENT="$(/bin/cat /etc/notifyme)" # you have to create this file | |
SUBJECT="[$(/bin/cat /etc/myname)] new -stable updates found" | |
[email protected]:/cvs | |
# -- end config | |
LOG=$(mktemp /tmp/$(basename $0).XXXXXX) | |
PORTS=${LOG}.ports | |
V=$(uname -r | tr . _) | |
PKG_PATH=$(sed '/installpath/s/ *installpath *= *\(.*\)/\1/g' /etc/pkg.conf) | |
CVS_UP=1 | |
usage() { | |
echo "USAGE:\t$(basename $0) [-h] [skip]" | |
echo "\t-h:\tshow this help" | |
echo "\tskip:\tskip updating sources via cvs" | |
} | |
if [ $# -gt 0 ]; then | |
if [ "$1" = "-h" ]; then | |
usage | |
exit 0 | |
elif [ "$1" = "skip" ]; then | |
CVS_UP=0 | |
else | |
usage | |
exit 1 | |
fi | |
fi | |
if [ $CVS_UP -eq 1 ]; then | |
GET="" | |
for dir in src xenocara ports; do | |
if [ -d /usr/${dir} ]; then | |
# update sources | |
cd /usr/${dir} | |
/usr/bin/cvs -d ${CVSROOT} -q up -rOPENBSD_${V} -Pd \ | |
| /usr/bin/tee ${LOG} | |
else | |
GET="${GET} ${dir}" | |
fi | |
done | |
if [ -n "${GET}" ]; then | |
# checkout missing sources | |
cd /usr | |
/usr/bin/cvs -d ${CVSROOT} checkout -rOPENBSD_${V} -P ${GET} | |
fi | |
if [ -s ${LOG} ]; then | |
echo "# The following source files are out of date:" \ | |
| /bin/cat - ${LOG} >${LOG}.tmp | |
/bin/mv ${LOG}.tmp ${LOG} | |
fi | |
fi | |
cd /tmp | |
# check for outdated ports | |
/usr/ports/infrastructure/bin/out-of-date -x 2>/dev/null \ | |
| /usr/bin/tee ${PORTS} \ | |
| /usr/bin/grep '#' \ | |
| /usr/bin/grep -v 'always-update' >${PORTS}.user | |
if [ -s ${PORTS}.user ]; then | |
# rebuild out of date ports | |
<${PORTS}.user /usr/bin/awk '{print $1}' \ | |
| while read port; do | |
PORTPATH=$(echo ${port} | /usr/bin/cut -d, -f1) | |
cd /usr/ports/${PORTPATH} | |
# extract flavors/subpackages | |
PORT_NAME=$(echo ${PORTPATH} | /usr/bin/cut -d/ -f2) | |
SUB=$(/usr/sbin/pkg_info -Pq ${PORT_NAME} | /usr/bin/sed 's/[^,][^,]*,\(.*\)/\1/g') | |
ARGS="" | |
if [ "${SUB}" != "${port}" -a "${SUB}" != "-main" ]; then | |
ARGS="SUBPACKAGE=\"${SUB}\"" | |
fi | |
/usr/bin/make clean=all # remove package | |
/usr/bin/make FETCH_PACKAGES=Yes ${ARGS} prepare | |
/usr/bin/make package | |
/usr/bin/make clean="depends work" # don't remove the new package! | |
done | |
cd /tmp | |
# install updated packages | |
PKG_PATH=/usr/ports/packages/$(uname -m)/all /usr/sbin/pkg_add -u | |
# delete unused dependencies | |
/usr/sbin/pkg_delete -a | |
echo "# Updated ports:" \ | |
| /bin/cat - ${PORTS}.user >>${LOG} | |
# check if there are still some out of date ports | |
/usr/ports/infrastructure/bin/out-of-date -x 2>/dev/null \ | |
| /usr/bin/grep '#' \ | |
| /usr/bin/grep -v 'always-update' \ | |
| /usr/bin/tee ${PORTS}.check | |
if [ -s ${PORTS}.check ]; then | |
echo "# Ports still out of date:" \ | |
| /bin/cat - ${PORTS}.check \ | |
| /usr/bin/tee -a ${LOG} | |
fi | |
# restart running services that were affected by the update | |
<${PORTS}.user /usr/bin/awk '{print $1}' \ | |
| /usr/bin/cut -d/ -f2 \ | |
| while read PKG; do \ | |
if [ -f /etc/rc.d/${PKG} -a -x /etc/rc.d/${PKG} ]; then | |
/etc/rc.d/${PKG} check >/dev/null && /etc/rc.d/${PKG} restart | |
fi | |
done \ | |
| /usr/bin/tee ${PORTS}.daemons | |
if [ -s ${PORTS}.daemons ]; then | |
echo "# Restarted daemons:" \ | |
| /bin/cat - ${PORTS}.daemons | |
else | |
echo "# No daemons had to be restarted." | |
fi \ | |
| /usr/bin/tee -a ${LOG} | |
fi | |
if [ -s ${LOG} ]; then | |
/usr/bin/mail -s "${SUBJECT}" "${RECIPIENT}" <${LOG} | |
fi | |
/bin/rm ${LOG} ${PORTS}* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment