1
0
Fork 0
forked from mirrors/openup

Move some stuffs around: we want all sanity checks to run first before creating any temp files or anything.

Simplify some stuffs and rename a temp file.
This commit is contained in:
Antoine Jacoutot 2013-08-07 17:18:55 +02:00
commit 824106a288

60
openup
View file

@ -30,34 +30,38 @@ PKG_CERT_REGEX='M:Tier Ltd. OpenBSD Stable Updates'
# DO NOT MODIFY ANYTHING BELOW THIS LINE!!! # DO NOT MODIFY ANYTHING BELOW THIS LINE!!!
OPENUP_VERSION=1
OPENUP_MINREL=53
MEESA=$(readlink -f $0)
TMPDIR="${TMPDIR:=/tmp}"
# magic taken from fw_update(1)
set -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q')
version=$1
tag=$2
error() {
echo -n "*** ERROR: $@"
}
usage() { usage() {
echo "usage: ${0##*/} [-SUn]" >&2 echo "usage: ${0##*/} [-SUn]" >&2
exit 1 exit 1
} }
check_unsup() { if [ "$(id -u)" -ne 0 ]; then
if [ "${tag}" == -!(stable) ]; then error "need root privileges to run this script"
error "XXX -current is a no-no" usage
exit 1 fi
fi
if [ "$(echo ${version} | tr -d '.')" -lt "${OPENUP_MINREL}" ]; then # magic taken from fw_update(1)
error "XXX release ${version} is a no-no (non-fatal)" set -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q')
fi release=$1
tag=$2
release_int="$(echo ${release} | tr -d '.')"
if [ "${tag}" == -!(stable) ]; then
error "XXX -current is a no-no"
exit 1
fi
if [ "${release_int}" -lt "${OPENUP_MINREL}" ]; then
error "XXX release ${release} is a no-no (non-fatal)"
fi
OPENUP_VERSION=1
OPENUP_MINREL=53
MEESA=$(readlink -f $0)
TMPDIR="${TMPDIR:=/tmp}"
error() {
echo -n "*** ERROR: $@"
} }
get_cert() { get_cert() {
@ -69,7 +73,7 @@ get_cert() {
fi fi
echo "===> Downloading certificate" echo "===> Downloading certificate"
_CERT=$(mktemp -p ${TMPDIR} pkg_cert.XXXXXXXXXX) || exit 1 _CERT=$(mktemp -p ${TMPDIR} openup-pkg_cert.XXXXXXXXXX) || exit 1
_CMD="ftp -Vo ${_CERT} ${PKG_CERT_URL}" _CMD="ftp -Vo ${_CERT} ${PKG_CERT_URL}"
if [ -z "${DRYRUN}" ]; then if [ -z "${DRYRUN}" ]; then
${_CMD} ${_CMD}
@ -99,7 +103,7 @@ update_self() {
local _CMD _F _N local _CMD _F _N
echo "===> Checking for openup(8) update" echo "===> Checking for openup(8) update"
_F=$(mktemp -p ${TMPDIR} pkg_cert.XXXXXXXXXX) || exit 1 _F=$(mktemp -p ${TMPDIR} openup-update.XXXXXXXXXX) || exit 1
_CMD="ftp -Vo ${_F} ${OPENUP_URL}" _CMD="ftp -Vo ${_F} ${OPENUP_URL}"
if [ -z "${DRYRUN}" ]; then if [ -z "${DRYRUN}" ]; then
${_CMD} ${_CMD}
@ -127,7 +131,7 @@ update_self() {
} }
update_binpatches() { update_binpatches() {
local _BP=$(pkg_info -Q binpatch$(echo $version | tr -d '.')-$(arch -s) | sed 's/.[^-]*$//' | sort -u) local _BP=$(pkg_info -Q binpatch${release_int}-$(arch -s) | sed 's/.[^-]*$//' | sort -u)
if [ -n "$_BP" ]; then if [ -n "$_BP" ]; then
echo "===> Updating binpatch(es)" echo "===> Updating binpatch(es)"
@ -155,13 +159,7 @@ while getopts 'SUn' arg; do
done done
[ $# = $(($OPTIND-1)) ] || usage [ $# = $(($OPTIND-1)) ] || usage
if [ "$(id -u)" -ne 0 ]; then
error "need root privileges to run this script"
usage
fi
[[ -z $NOSELFUPDATE ]] && update_self [[ -z $NOSELFUPDATE ]] && update_self
check_unsup
[[ -z $NOSIG ]] && get_cert [[ -z $NOSIG ]] && get_cert
update_binpatches update_binpatches
update_pkg update_pkg