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+=( "$@" ) || :; }
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'
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
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