From 8fed6328bbb0a132440fdb205c85a745a5dbb976 Mon Sep 17 00:00:00 2001 From: Robert Martin-Legene <robert@nic.ar> Date: Fri, 24 May 2019 13:43:36 -0300 Subject: [PATCH] Un bfaupdate.sh mas avanzado --- bin/bfaupdate.sh | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/bin/bfaupdate.sh b/bin/bfaupdate.sh index bbc8ec8..4137623 100755 --- a/bin/bfaupdate.sh +++ b/bin/bfaupdate.sh @@ -1,11 +1,45 @@ #!/bin/bash # Robert Martin-Legene <robert@nic.ar> +# 2019 +# You can start this as root or not - as long as $BFAHOME is set, it +# should work. + +trap "exit 1" ERR if [ -z "${BFAHOME}" ]; then echo "\$BFAHOME not set. Did you source bfa/bin/env ?" >&2; exit 1; fi source ${BFAHOME}/bin/libbfa.sh || exit 1 + +function runasownerof +{ + path=$1 + precmd= + shift 1 + if [ $( stat --format=%u $path ) -ne $UID ] + then + precmd="sudo -u $( stat --format=%U $path )" + fi + unset path + ${precmd} "$@" + unset precmd +} + set -x -cd ${BFAHOME} -sudo apt -y install libclass-accessor-perl -git pull -npm rebuild +if [ "$1" = "" ] +then + cd `dirname $0` + # Pulling may update this script itself. + # We pull an updated repository, including an updated version of + # ourself, and then we execute the updates "us" + # This first part of the if is static. Changes (updates to this + # script) goes after the 'else' + # + # To keep things neat, make sure we pull as the user owning the + # directory. + runasownerof . git pull + exec ./`basename $0` wealreadypulled +else + cd ${BFAHOME} + runasownerof / apt -y install libclass-accessor-perl + runasownerof . npm rebuild +fi -- GitLab