From 22b9d10552b184bbb4072bb36852c13a4cdd0d67 Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Thu, 30 Oct 2014 15:41:59 +0100 Subject: [PATCH] Simplify, and move around. While here, fix a stall PID file when running with -cS --- openup | 87 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 42 insertions(+), 45 deletions(-) diff --git a/openup b/openup index e2ac46a..9993719 100755 --- a/openup +++ b/openup @@ -19,10 +19,6 @@ # ChangeLog # http://cgit.mtier.org:8000/cgit/openup/log/ -# regex taken from fw_update(1) -set -A _REL -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q') -_REL_INT="$(echo ${_REL[0]} | tr -d '.')" - ######################################################################## ### DO NOT EDIT THIS FILE!!! ### ### User defined variables: overrides are read from /etc/openup.conf ### @@ -45,17 +41,13 @@ EXCLUDE_PKG="" ### End of user defined variables ### ######################################################################## - -_OPENUP_VERSION=17 -_OPENUP_MINREL=55 - usage() { echo echo "Usage: ${0##*/} [-K][-S|c]" >&2 echo echo "Options:" echo " -K do not check for kernel binpatches (when running non GENERIC)" - echo " -S do not check for package signatures" + echo " -S ignore binpatch/package signatures" echo " -c check/cron mode, report only (cannot be used with -S)" echo exit 1 @@ -65,39 +57,6 @@ pr_err() { echo "!!! ${@}" } -if [ "$(id -u)" -ne 0 ]; then - pr_err "Need root privileges to run this script" - usage -fi - -if [ -f /etc/openup.conf ]; then - if [ $(stat -f "%SMp%SLp" /etc/openup.conf) != "------" ]; then - pr_err "Unsecure permissions on /etc/openup.conf; please run:" - pr_err "chmod 0600 /etc/openup.conf" - exit 1 - fi - . /etc/openup.conf -fi - -if [ -n "${_REL[1]}" -a "${_REL[1]}" != "-stable" ]; then _badrel=1; fi -if [ "${_REL_INT}" -lt "${_OPENUP_MINREL}" ]; then _badrel=1; fi - -if [ -n "${_badrel}" ]; then - pr_err "${_REL[0]}${_REL[1]} is not a supported release" - exit 1 -fi - -_ARCH=$(arch -s) -_TMP="${TMPDIR:=/tmp}" -_TMPDIR=$(mktemp -dp ${_TMP} .openup-XXXXXXXXXX) || exit 1 -_TMPKEY="${_TMPDIR}/key" -_TMPVUXML="${_TMPDIR}/vuxml" -_PID="/var/run/${0##*/}.pid" - -export PKG_PATH=${PKG_PATH_UPDATE_LTS}:${PKG_PATH_UPDATE}:${PKG_PATH_MAIN} - -trap "bye_bye" 1 2 3 13 15 - bye_bye() { rm -rf ${_TMPDIR} ${_PID} exit 1 @@ -250,6 +209,32 @@ do_i_need_to_reboot() { fi } +trap "bye_bye" 1 2 3 13 15 + +if [ "$(id -u)" -ne 0 ]; then + pr_err "Need root privileges to run this script" + usage +fi + +if [ -f /etc/openup.conf ]; then + if [ $(stat -f "%SMp%SLp" /etc/openup.conf) != "------" ]; then + pr_err "Unsecure permissions on /etc/openup.conf; please run:" + pr_err "chmod 0600 /etc/openup.conf" + exit 1 + fi + . /etc/openup.conf +fi + +# regex taken from fw_update(1) +set -A _REL -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q') +_REL_INT="$(echo ${_REL[0]} | tr -d '.')" +if [ -n "${_REL[1]}" -a "${_REL[1]}" != "-stable" ]; then _badrel=1; fi +if [ "${_REL_INT}" -lt "${_OPENUP_MINREL}" ]; then _badrel=1; fi +if [ -n "${_badrel}" ]; then + pr_err "${_REL[0]}${_REL[1]} is not a supported release" + exit 1 +fi + while getopts 'KSc' arg; do case ${arg} in K) nokrn=1 ;; @@ -260,6 +245,19 @@ while getopts 'KSc' arg; do done [ $# = $(($OPTIND-1)) ] || usage +[ -n "${checkrun}" -a -n "${nosig}" ] && usage + +_ARCH=$(arch -s) +_OPENUP_MINREL=55 +_OPENUP_VERSION=17 +_PID="/var/run/${0##*/}.pid" +_TMP="${TMPDIR:=/tmp}" +_TMPDIR=$(mktemp -dp ${_TMP} .openup-XXXXXXXXXX) || exit 1 +_TMPKEY="${_TMPDIR}/key" +_TMPVUXML="${_TMPDIR}/vuxml" + +export PKG_PATH=${PKG_PATH_UPDATE_LTS}:${PKG_PATH_UPDATE}:${PKG_PATH_MAIN} + if [ -f ${_PID} ]; then pr_err "openup is already running ($(cat ${_PID})):" pr_err "${_PID}" @@ -267,9 +265,6 @@ if [ -f ${_PID} ]; then fi echo $$ >${_PID} -[ -n "${checkrun}" -a -n "${nosig}" ] && usage -check_openupd - if [ -n "${nokrn}" ]; then EXCLUDE_PKG="binpatch${_REL_INT}-${_ARCH}-kernel ${EXCLUDE_PKG}" fi @@ -277,6 +272,8 @@ if [ -n "${EXCLUDE_PKG}" ]; then pr "Excluded package(s)/binpatch(es): ${EXCLUDE_PKG}" fi +check_openupd + if [ "${checkrun}" ]; then check_vuxml else