]> git.wh0rd.org Git - home.git/commitdiff
gentoo-sync: add better logging by default
authorMike Frysinger <vapier@gentoo.org>
Wed, 4 May 2022 13:41:22 +0000 (09:41 -0400)
committerMike Frysinger <vapier@gentoo.org>
Wed, 4 May 2022 13:41:22 +0000 (09:41 -0400)
.bin/gentoo-sync

index c41f04dcacbec059e7b261e9ad7ec0c3a51b1706..6d272070dd16a42002f78dd35d86ada4a3042111 100755 (executable)
@@ -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