summaryrefslogtreecommitdiffstats
path: root/bin/common-functions.sh
diff options
context:
space:
mode:
authorHolger Levsen <holger@layer-acht.org>2014-04-25 16:46:33 +0200
committerHolger Levsen <holger@layer-acht.org>2014-04-26 20:11:52 +0200
commit3a9c01363a0af7c64179c19f1d6e884c4a7cb873 (patch)
treef144695a6c71458ca1fa1dd429af8921f056ac22 /bin/common-functions.sh
parente9d10b50dfa10dc5685d73d387f59772c3ea036d (diff)
downloadjenkins.debian.net-3a9c01363a0af7c64179c19f1d6e884c4a7cb873.tar.xz
use common functions. runs all scripts as copies from /tmp, so the source scripts can be updated while running.
Diffstat (limited to 'bin/common-functions.sh')
-rwxr-xr-xbin/common-functions.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/bin/common-functions.sh b/bin/common-functions.sh
new file mode 100755
index 00000000..327cdff7
--- /dev/null
+++ b/bin/common-functions.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+# Copyright 2014 Holger Levsen <holger@layer-acht.org>
+# released under the GPLv=2
+
+common_cleanup(){
+ echo "Cleaned up $TTT, finished running $0"
+ rm -f $TTT
+}
+
+common_init() {
+# check whether this script has been started from /tmp already
+if [ "${0:0:5}" != "/tmp/" ] ; then
+ # mktemp some place for us...
+ TTT=$(mktemp --tmpdir=/tmp)
+ # prepare cleanup
+ trap common_cleanup INT TERM EXIT
+ # cp $0 to /tmp and run it from there
+ cp $0 $TTT
+ chmod +x $TTT
+ # run ourself with the same parameter as we are running
+ # but run a copy from /tmp so that the source can be updated
+ # (Running shell scripts fail weirdly when overwritten when running,
+ # this hack makes it possible to overwrite long running scripts
+ # anytime...)
+ echo "Start running \"$0\" as \"$TTT\" with arguments \"$@\""
+ $TTT "$@"
+ exit 0 # auto cleanup on trap
+else
+ # default settings used for the jenkins.debian.net environment
+ if [ -z "$LC_ALL" ]; then
+ export LC_ALL=C
+ fi
+ if [ -z "$MIRROR" ]; then
+ export MIRROR=http://ftp.de.debian.org/debian
+ fi
+ if [ -z "$http_proxy" ]; then
+ export http_proxy="http://localhost:3128"
+ fi
+ if [ -z "$CHROOT_BASE" ]; then
+ export CHROOT_BASE=/chroots
+ fi
+ if [ -z "$SCHROOT_BASE" ]; then
+ export SCHROOT_BASE=/schroots
+ fi
+ # use these settings in the scripts in the (s)chroots too
+ export SCRIPT_HEADER="#!/bin/bash
+ set -e
+ set -x
+ export DEBIAN_FRONTEND=noninteractive
+ export LC_ALL=$LC_ALL
+ export http_proxy=$http_proxy
+ export MIRROR=$MIRROR"
+ # be more verbose
+ export
+ set -e
+ set -x
+
+fi
+}
+