From: Mike Frysinger Date: Wed, 4 May 2022 13:41:22 +0000 (-0400) Subject: gentoo-sync: add better logging by default X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=7f44ba6d69ae6d0f51e0688304f3f0c5ac5f8b24;p=home.git gentoo-sync: add better logging by default --- diff --git a/.bin/gentoo-sync b/.bin/gentoo-sync index c41f04d..6d27207 100755 --- a/.bin/gentoo-sync +++ b/.bin/gentoo-sync @@ -7,14 +7,28 @@ GS_FETCH=false GS_UPWORLD=true GS_LAYMAN=true GS_DEBUG=false +GS_USER="portage" conf="/etc/gentoo-sync.conf" [[ -e ${conf} ]] && . "${conf}" +logdir="/var/log" +sync_log="${logdir}/rsync.log" +up_log="${logdir}/emerge-updates.log" + bootstrap() { - [[ "${FLOCKER}" != "$0" ]] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" - [[ $(id -u) -eq 0 ]] || exec sudo env -uUNSHARE FLOCKER="${FLOCKER}" HOME="$HOME" "$0" "$@" + local prog=$(realpath "$0") + if [[ "${FLOCKER}" != "${prog}" ]] ; then + exec env -uUNSHARE FLOCKER="${prog}" flock -en "${prog}" "${prog}" "$@" + fi if [[ -z ${UNSHARE} ]] ; then + if [[ $(id -u) -ne 0 ]] ; then + exec sudo env -uUNSHARE FLOCKER="${FLOCKER}" HOME="$HOME" "${prog}" "$@" + fi + + touch "${sync_log}" "${up_log}" + chown "${GS_USER}" "${sync_log}" "${up_log}" + mount_args= if type -P unshare >&/dev/null ; then test_arg() { unshare "$@" -- true >&/dev/null && uargs+=( "$@" ) || :; } @@ -23,7 +37,9 @@ bootstrap() { test_arg -i test_arg -p -f --mount-proc test_arg --propagation=private - UNSHARE=true exec unshare "${uargs[@]}" -- "$0" "$@" + exec unshare "${uargs[@]}" -- \ + sudo -u "${GS_USER}" UNSHARE="true" FLOCKER="${FLOCKER}" \ + "${prog}" "$@" fi else mount_args='-n' @@ -80,15 +96,19 @@ for x ; do esac done -${GS_DEBUG} && set -x - -logdir="/var/log" -sync_log="${logdir}/rsync.log" -up_log="${logdir}/emerge-updates.log" +run() { + echo "+ $*" + "$@" +} +if ${GS_DEBUG} ; then + set -x + run() { "$@" ; } +fi export NOCOLOR=true ( +id date if ${GS_RSYNC} ; then @@ -107,13 +127,15 @@ if ${GS_RSYNC} ; then fi if ${GS_SYNC} ; then - emerge --sync -q date - ${GS_EUPDATEDB} && $(type -P eupdatedb) + run emerge --sync -q + date + ${GS_EUPDATEDB} && run $(type -P eupdatedb) + date + ${GS_LAYMAN} && l=$(type -P layman) && run ${l} -S -q date - ${GS_LAYMAN} && l=$(type -P layman) && ${l} -S -q + ${GS_FETCH} && run emerge world -Duf date - ${GS_FETCH} && emerge world -Duf #q -qr fi