1
0
Fork 0
forked from mirrors/openup

Simplify, and move around.

While here, fix a stall PID file when running with -cS
This commit is contained in:
Antoine Jacoutot 2014-10-30 15:41:59 +01:00
commit 22b9d10552

87
openup
View file

@ -19,10 +19,6 @@
# ChangeLog # ChangeLog
# http://cgit.mtier.org:8000/cgit/openup/log/ # 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!!! ### ### DO NOT EDIT THIS FILE!!! ###
### User defined variables: overrides are read from /etc/openup.conf ### ### User defined variables: overrides are read from /etc/openup.conf ###
@ -45,17 +41,13 @@ EXCLUDE_PKG=""
### End of user defined variables ### ### End of user defined variables ###
######################################################################## ########################################################################
_OPENUP_VERSION=17
_OPENUP_MINREL=55
usage() { usage() {
echo echo
echo "Usage: ${0##*/} [-K][-S|c]" >&2 echo "Usage: ${0##*/} [-K][-S|c]" >&2
echo echo
echo "Options:" echo "Options:"
echo " -K do not check for kernel binpatches (when running non GENERIC)" 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 " -c check/cron mode, report only (cannot be used with -S)"
echo echo
exit 1 exit 1
@ -65,39 +57,6 @@ pr_err() {
echo "!!! ${@}" 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() { bye_bye() {
rm -rf ${_TMPDIR} ${_PID} rm -rf ${_TMPDIR} ${_PID}
exit 1 exit 1
@ -250,6 +209,32 @@ do_i_need_to_reboot() {
fi 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 while getopts 'KSc' arg; do
case ${arg} in case ${arg} in
K) nokrn=1 ;; K) nokrn=1 ;;
@ -260,6 +245,19 @@ while getopts 'KSc' arg; do
done done
[ $# = $(($OPTIND-1)) ] || usage [ $# = $(($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 if [ -f ${_PID} ]; then
pr_err "openup is already running ($(cat ${_PID})):" pr_err "openup is already running ($(cat ${_PID})):"
pr_err "${_PID}" pr_err "${_PID}"
@ -267,9 +265,6 @@ if [ -f ${_PID} ]; then
fi fi
echo $$ >${_PID} echo $$ >${_PID}
[ -n "${checkrun}" -a -n "${nosig}" ] && usage
check_openupd
if [ -n "${nokrn}" ]; then if [ -n "${nokrn}" ]; then
EXCLUDE_PKG="binpatch${_REL_INT}-${_ARCH}-kernel ${EXCLUDE_PKG}" EXCLUDE_PKG="binpatch${_REL_INT}-${_ARCH}-kernel ${EXCLUDE_PKG}"
fi fi
@ -277,6 +272,8 @@ if [ -n "${EXCLUDE_PKG}" ]; then
pr "Excluded package(s)/binpatch(es): ${EXCLUDE_PKG}" pr "Excluded package(s)/binpatch(es): ${EXCLUDE_PKG}"
fi fi
check_openupd
if [ "${checkrun}" ]; then if [ "${checkrun}" ]; then
check_vuxml check_vuxml
else else