1
0
Fork 0
forked from mirrors/openup

Sanitize variables name.

Make this tool standalone and not rely on externaly set PKG_PATH
or installpath.
This commit is contained in:
Antoine Jacoutot 2013-08-20 11:22:11 +02:00
commit 6c8c11bfb3

95
openup
View file

@ -20,13 +20,18 @@
# https://stable.mtier.org/vuxml/53.xml # https://stable.mtier.org/vuxml/53.xml
### user defined variables ### user defined variables
OPENUP_URL='https://stable.mtier.org/openup' OPENUP_URL="https://stable.mtier.org/openup"
PKG_CERT_URL='https://stable.mtier.org/mtier.cert' PKG_CERT_URL="https://stable.mtier.org/mtier.cert"
PKG_CERT_FPRINT='DE:29:0F:7F:B8:0E:36:5A:AF:A9:BF:E0:4E:08:C2:0F:2D:50:16:97' PKG_CERT_FPRINT="DE:29:0F:7F:B8:0E:36:5A:AF:A9:BF:E0:4E:08:C2:0F:2D:50:16:97"
PKG_PATH_MAIN="http://ftp.fr.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(arch -s)"
PKG_PATH_UPDATE="https://stable.mtier.org/updates/$(uname -r)/$(arch -s)"
### end of user defined variables ### end of user defined variables
### DO NOT MODIFY ANYTHING BELOW THIS LINE!!! ### DO NOT MODIFY ANYTHING BELOW THIS LINE!!!
_OPENUP_VERSION=2
_OPENUP_MINREL=53
usage() { usage() {
echo echo
echo "usage: ${0##*/} [-SUn]" >&2 echo "usage: ${0##*/} [-SUn]" >&2
@ -46,31 +51,19 @@ if [ "$(id -u)" -ne 0 ]; then
fi fi
# regex taken from fw_update(1) # regex taken from fw_update(1)
set -A REL -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q') set -A _REL -- $(sysctl -n kern.version | sed 's/^OpenBSD \([0-9]\.[0-9]\)\([^ ]*\).*/\1 \2/;q')
REL_INT="$(echo ${REL[0]} | tr -d '.')" _REL_INT="$(echo ${_REL[0]} | tr -d '.')"
if [ "${REL[1]}" == -!(stable) -o "${REL_INT}" -lt "${OPENUP_MINREL}" ]; then if [ "${_REL[1]}" == -!(stable) -o "${_REL_INT}" -lt "${_OPENUP_MINREL}" ]; then
pr_error "${REL[0]}${REL[1]} is not a supported release" pr_error "${_REL[0]}${_REL[1]} is not a supported release"
exit 1 exit 1
fi fi
if ! grep -q installpath /etc/pkg.conf 2>/dev/null; then
if [ -z "${PKG_PATH}" ]; then
pr_error "No package repository defined in pkg.conf(5) nor PKG_PATH"
pr_error
pr_error "The \${PKG_PATH} environment variable can be set as follow:"
pr_error "PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/\$(uname -r)/packages/\$(arch -s)"
pr_error "PKG_PATH=https://stable.mtier.org/updates/\$(uname -r)/\$(arch -s):\${PKG_PATH}"
pr_error "export PKG_PATH"
exit 1
fi
fi
# check that we have no installed binpatches from a previous release # check that we have no installed binpatches from a previous release
_BPLIST=$(pkg_info -q | grep "^binpatch") _BPLIST=$(pkg_info -q | grep "^binpatch")
if [ -n "${_BPLIST}" ]; then if [ -n "${_BPLIST}" ]; then
_i=$(echo ${_BPLIST} | wc -w) _i=$(echo ${_BPLIST} | wc -w)
_v=$(echo ${_BPLIST} | grep "^binpatch${REL_INT}" | wc -w) _v=$(echo ${_BPLIST} | grep "^binpatch${_REL_INT}" | wc -w)
if [ "${_i}" -ne "${_v}" ]; then if [ "${_i}" -ne "${_v}" ]; then
pr_error "Binpatch(es) from a previous release installed" pr_error "Binpatch(es) from a previous release installed"
exit 1 exit 1
@ -78,18 +71,18 @@ if [ -n "${_BPLIST}" ]; then
fi fi
unset _BPLIST unset _BPLIST
OPENUP_VERSION=2 _MEESA=$(readlink -f $0)
OPENUP_MINREL=53 _TMPDIR="${_TMPDIR:=/tmp}"
MEESA=$(readlink -f $0) _TMPCERT=$(mktemp -p ${_TMPDIR} openup-pkg_cert.XXXXXX) || exit 1
TMPDIR="${TMPDIR:=/tmp}" _TMPUPD=$(mktemp -p ${_TMPDIR} openup-update.XXXXXX) || exit 1
TMPCERT=$(mktemp -p ${TMPDIR} openup-pkg_cert.XXXXXX) || exit 1 _TMPSPLITCERT=$(mktemp -p ${_TMPDIR} openup-split_cert.XXXXXX) || exit 1
TMPUPD=$(mktemp -p ${TMPDIR} openup-update.XXXXXX) || exit 1
TMPSPLITCERT=$(mktemp -p ${TMPDIR} openup-split_cert.XXXXXX) || exit 1
trap "rm -f ${TMPDIR}/openup-*" 1 2 3 13 15 export PKG_PATH=${PKG_PATH_UPDATE}:${PKG_PATH_MAIN}
trap "rm -f ${_TMPDIR}/openup-*" 1 2 3 13 15
pr_bigarrow() { pr_bigarrow() {
echo "===> ${@}${DRYRUN}" echo "===> ${@}${dryrun}"
} }
pr_smallarrow() { pr_smallarrow() {
@ -100,24 +93,24 @@ get_cert() {
local _CMD local _CMD
[[ -r /etc/ssl/pkgca.pem ]] && \ [[ -r /etc/ssl/pkgca.pem ]] && \
split -p '^-----BEGIN CERTIFICATE-----$' /etc/ssl/pkgca.pem ${TMPSPLITCERT} split -p '^-----BEGIN CERTIFICATE-----$' /etc/ssl/pkgca.pem ${_TMPSPLITCERT}
for i in ${TMPSPLITCERT}* ; do for i in ${_TMPSPLITCERT}* ; do
openssl x509 -noout -in $i -fingerprint 2>/dev/null | \ openssl x509 -noout -in $i -fingerprint 2>/dev/null | \
grep -q "${PKG_CERT_FPRINT}" && return grep -q "${PKG_CERT_FPRINT}" && return
done done
pr_bigarrow "Downloading certificate" pr_bigarrow "Downloading certificate"
_CMD="ftp -Vo ${TMPCERT} ${PKG_CERT_URL}" _CMD="ftp -Vo ${_TMPCERT} ${PKG_CERT_URL}"
pr_smallarrow "${_CMD}" pr_smallarrow "${_CMD}"
if [ -z "${DRYRUN}" ]; then if [ -z "${dryrun}" ]; then
eval ${_CMD} || exit 1 eval ${_CMD} || exit 1
fi fi
pr_bigarrow "Installing certificate" pr_bigarrow "Installing certificate"
_CMD="cat ${TMPCERT} >>/etc/ssl/pkgca.pem" _CMD="cat ${_TMPCERT} >>/etc/ssl/pkgca.pem"
pr_smallarrow "${_CMD}" pr_smallarrow "${_CMD}"
if [ -z "${DRYRUN}" ]; then if [ -z "${dryrun}" ]; then
eval ${_CMD} || exit 1 eval ${_CMD} || exit 1
fi fi
} }
@ -126,26 +119,26 @@ update_self() {
local _CMD _N local _CMD _N
pr_bigarrow "Checking for openup update" pr_bigarrow "Checking for openup update"
_CMD="ftp -Vo ${TMPUPD} ${OPENUP_URL}" _CMD="ftp -Vo ${_TMPUPD} ${OPENUP_URL}"
pr_smallarrow "${_CMD}" pr_smallarrow "${_CMD}"
if [ -z "${DRYRUN}" ]; then if [ -z "${dryrun}" ]; then
eval ${_CMD} || exit 1 eval ${_CMD} || exit 1
fi fi
_N=$(grep -Eo '^OPENUP_VERSION=.*' ${TMPUPD} | awk -F '=' '{ print $2 }') _N=$(grep -Eo '^_OPENUP_VERSION=.*' ${_TMPUPD} | awk -F '=' '{ print $2 }')
if [ -n "${_N}" -o -n "${DRYRUN}" ]; then if [ -n "${_N}" -o -n "${dryrun}" ]; then
if [ "${OPENUP_VERSION}" -lt "${_N}" -o -n "${DRYRUN}" ]; then if [ "${_OPENUP_VERSION}" -lt "${_N}" -o -n "${dryrun}" ]; then
pr_bigarrow "Updating openup to the latest release" pr_bigarrow "Updating openup to the latest release"
_CMD="cat ${TMPUPD} >${MEESA}" _CMD="cat ${_TMPUPD} >${_MEESA}"
pr_smallarrow "${_CMD}" pr_smallarrow "${_CMD}"
if [ -z "${DRYRUN}" ]; then if [ -z "${dryrun}" ]; then
eval ${_CMD} || exit 1 eval ${_CMD} || exit 1
rtn=$? rtn=$?
fi fi
pr_bigarrow "openup has been updated, restarting" pr_bigarrow "openup has been updated, restarting"
_CMD="${MEESA} -U $@" _CMD="${_MEESA} -U $@"
pr_smallarrow "${_CMD}" pr_smallarrow "${_CMD}"
if [ -z "${DRYRUN}" ]; then if [ -z "${dryrun}" ]; then
eval ${_CMD} eval ${_CMD}
exit $rtn exit $rtn
fi fi
@ -156,7 +149,7 @@ update_self() {
update_binpatches() { update_binpatches() {
local _BP _CMD local _BP _CMD
_BP=$(pkg_info -Q binpatch${REL_INT}-$(arch -s) | sed 's/.[^-]*$//' | sort -u | tr '\n' ' ') _BP=$(pkg_info -Q binpatch${_REL_INT}-$(arch -s) | sed 's/.[^-]*$//' | sort -u | tr '\n' ' ')
if [ -n "$_BP" ]; then if [ -n "$_BP" ]; then
pr_bigarrow "Updating binpatch(es)" pr_bigarrow "Updating binpatch(es)"
@ -186,18 +179,18 @@ update_fw() {
while getopts 'SUn' arg; do while getopts 'SUn' arg; do
case ${arg} in case ${arg} in
S) NOSIG=1; pkg_opt="${pkg_opt} -D nosig" ;; S) nosig=1; pkg_opt="${pkg_opt} -D nosig" ;;
U) NOSELFUPDATE=1 ;; U) noselfupdate=1 ;;
n) DRYRUN=" (dry run)"; pkg_opt="${pkg_opt} -n -D nosig"; fw_opt="-n" ;; n) dryrun=" (dry run)"; pkg_opt="${pkg_opt} -n -D nosig"; fw_opt="-n" ;;
*) usage ;; *) usage ;;
esac esac
done done
[ $# = $(($OPTIND-1)) ] || usage [ $# = $(($OPTIND-1)) ] || usage
[[ -z $NOSELFUPDATE ]] && update_self [[ -z $noselfupdate ]] && update_self
[[ -z $NOSIG ]] && get_cert [[ -z $nosig ]] && get_cert
update_binpatches update_binpatches
update_pkg update_pkg
update_fw update_fw
rm -f ${TMPDIR}/openup-* rm -f ${_TMPDIR}/openup-*