From 3a9c01363a0af7c64179c19f1d6e884c4a7cb873 Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Fri, 25 Apr 2014 16:46:33 +0200 Subject: use common functions. runs all scripts as copies from /tmp, so the source scripts can be updated while running. --- bin/chroot-installation.sh | 21 +++------------- bin/chroot-run.sh | 24 +++--------------- bin/common-functions.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++ bin/d-i_build.sh | 13 +++------- bin/d-i_check_jobs.sh | 11 +++------ bin/d-i_manual.sh | 13 +++------- bin/d-i_parse_logs.sh | 18 ++++---------- bin/g-i-installation.sh | 13 +++------- bin/housekeeping.sh | 10 +++----- bin/schroot-create.sh | 29 ++++++---------------- bin/webcheck_url.sh | 18 ++++---------- 11 files changed, 100 insertions(+), 131 deletions(-) create mode 100755 bin/common-functions.sh diff --git a/bin/chroot-installation.sh b/bin/chroot-installation.sh index 921a9315..ce161477 100755 --- a/bin/chroot-installation.sh +++ b/bin/chroot-installation.sh @@ -1,8 +1,11 @@ #!/bin/bash -# Copyright 2012,2013 Holger Levsen +# Copyright 2012-2014 Holger Levsen # released under the GPLv=2 +. /srv/jenkins/bin/common-functions.sh +common_init "$@" + # $1 = base distro # $2 = extra component # $3 = upgrade distro @@ -19,22 +22,6 @@ SLEEP=$(shuf -i 1-10 -n 1) echo "Sleeping $SLEEP seconds to randomize start times and parallel runs." sleep $SLEEP -# -# default settings -# -set -x -set -e -export LC_ALL=C -export MIRROR=http://ftp.de.debian.org/debian -export http_proxy="http://localhost:3128" - -export SCRIPT_HEADER="#!/bin/bash -set -x -set -e -export DEBIAN_FRONTEND=noninteractive -export LC_ALL=C -export http_proxy=$http_proxy" - export CHROOT_TARGET=$(mktemp -d -p /chroots/ chroot-installation-$1.XXXXXXXXX) export TMPFILE=$(mktemp -u) export CTMPFILE=$CHROOT_TARGET/$TMPFILE diff --git a/bin/chroot-run.sh b/bin/chroot-run.sh index 4d3555bb..05df628b 100755 --- a/bin/chroot-run.sh +++ b/bin/chroot-run.sh @@ -4,23 +4,12 @@ # Copyright 2013 Antonio Terceiro # released under the GPLv=2 +. /srv/jenkins/bin/common-functions.sh +common_init "$@" + # $1 = base distro # $2 $3 ... = command to run inside a clean chroot running the distro in $1 -set -e -export LC_ALL=C - -# Defaults for the jenkins.debian.net environment -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 [ $# -lt 2 ]; then echo "usage: $0 DISTRO [backports] CMD [ARG1 ARG2 ...]" exit 1 @@ -48,13 +37,6 @@ fi export CURDIR=$(pwd) -export SCRIPT_HEADER="#!/bin/bash -set -x -set -e -export DEBIAN_FRONTEND=noninteractive -export LC_ALL=C -export http_proxy=$http_proxy" - bootstrap() { mkdir -p "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d" echo force-unsafe-io > "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d/02dpkg-unsafe-io" 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 +# 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 +} + diff --git a/bin/d-i_build.sh b/bin/d-i_build.sh index 0b43edca..8685f8f5 100755 --- a/bin/d-i_build.sh +++ b/bin/d-i_build.sh @@ -1,17 +1,10 @@ #!/bin/bash -# Copyright 2012-2013 Holger Levsen +# Copyright 2012-2014 Holger Levsen # released under the GPLv=2 -# -# default settings -# -set -x -set -e -export LC_ALL=C -export MIRROR=http://ftp.de.debian.org/debian -export http_proxy="http://localhost:3128" -export +. /srv/jenkins/bin/common-functions.sh +common_init "$@" init_workspace() { # diff --git a/bin/d-i_check_jobs.sh b/bin/d-i_check_jobs.sh index 524943b5..dad4f95b 100755 --- a/bin/d-i_check_jobs.sh +++ b/bin/d-i_check_jobs.sh @@ -1,15 +1,10 @@ #!/bin/bash -# Copyright 2012 Holger Levsen +# Copyright 2012,2014 Holger Levsen # released under the GPLv=2 -# -# default settings -# -#set -x -set -e -export LC_ALL=C -export http_proxy="http://localhost:3128" +. /srv/jenkins/bin/common-functions.sh +common_init "$@" # # define some variables diff --git a/bin/d-i_manual.sh b/bin/d-i_manual.sh index 7a0eaf0b..47680f85 100755 --- a/bin/d-i_manual.sh +++ b/bin/d-i_manual.sh @@ -1,17 +1,10 @@ #!/bin/bash -# Copyright 2012 Holger Levsen +# Copyright 2012,2014 Holger Levsen # released under the GPLv=2 -# -# default settings -# -set -x -set -e -export LC_ALL=C -export MIRROR=http://ftp.de.debian.org/debian -export http_proxy="http://localhost:3128" -export +. /srv/jenkins/bin/common-functions.sh +common_init "$@" init_workspace() { # diff --git a/bin/d-i_parse_logs.sh b/bin/d-i_parse_logs.sh index 2fae7370..a3eaa3de 100755 --- a/bin/d-i_parse_logs.sh +++ b/bin/d-i_parse_logs.sh @@ -1,27 +1,19 @@ #!/bin/bash -# Copyright 2012, 2013 Holger Levsen +# Copyright 2012-2014 Holger Levsen # released under the GPLv=2 +. /srv/jenkins/bin/common-functions.sh +common_init "$@" + +# convert param to variables if [ "$1" == "" ] ; then echo "need at least one URL to act on" echo '# $1 = URL' exit 1 fi - -# -# convert params to variables -# URL=$1 -# -# default settings -# -#set -x -set -e -export LC_ALL=C -export http_proxy="http://localhost:3128" - TMPFILE=$(mktemp) curl $URL > $TMPFILE if [ $(grep -c failed $TMPFILE 2>/dev/null ) -gt 1 ] ; then diff --git a/bin/g-i-installation.sh b/bin/g-i-installation.sh index 7cbded62..817e0c31 100755 --- a/bin/g-i-installation.sh +++ b/bin/g-i-installation.sh @@ -3,6 +3,9 @@ # Copyright 2012-2014 Holger Levsen # released under the GPLv=2 +. /srv/jenkins/bin/common-functions.sh +common_init "$@" + # $1 = vnc-display, each job should have a unique one, so jobs can run in parallel # $2 = name # $3 = disksize in GB @@ -19,16 +22,6 @@ if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ] ; then exit 1 fi -# -# default settings -# -set -x -set -e -export LC_ALL=C -export MIRROR=http://ftp.de.debian.org/debian -export http_proxy="http://localhost:3128" -export - # # init # diff --git a/bin/housekeeping.sh b/bin/housekeeping.sh index 3d93a717..f322fec7 100755 --- a/bin/housekeeping.sh +++ b/bin/housekeeping.sh @@ -1,13 +1,10 @@ #!/bin/bash -# Copyright 2012-2013 Holger Levsen +# Copyright 2012-2014 Holger Levsen # released under the GPLv=2 -# -# default settings -# -export LC_ALL=C -set -e +. /srv/jenkins/bin/common-functions.sh +common_init "$@" check_for_mounted_chroots() { CHROOT_PATTERN="/chroots/${1}-*" @@ -47,7 +44,6 @@ report_filetype_usage() { rm $OUTPUT } - report_squid_usage() { REPORT=/var/www/calamaris/calamaris.txt if [ -z $1 ] ; then diff --git a/bin/schroot-create.sh b/bin/schroot-create.sh index 76a7f389..d39502e9 100755 --- a/bin/schroot-create.sh +++ b/bin/schroot-create.sh @@ -2,37 +2,22 @@ # Copyright 2012-2014 Holger Levsen # Copyright 2013 Antonio Terceiro +# Copyright 2014 Joachim Breitner # released under the GPLv=2 -# $2 = schroot name -# $1 = base distro -# $2 $3 ... = extra packages to install +. /srv/jenkins/bin/common-functions.sh +common_init "$@" # bootstraps a new chroot for schroot, and then moves it into the right location -set -e -export LC_ALL=C - -# Defaults for the jenkins.debian.net environment -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 +# $1 = schroot name +# $2 = base distro +# $3 $4 ... = extra packages to install if [ $# -lt 2 ]; then - echo "usage: $0 DISTRO [backports] CMD [ARG1 ARG2 ...]" + echo "usage: $0 TARGET DISTRO [backports] CMD [ARG1 ARG2 ...]" exit 1 fi - TARGET="$1" shift DISTRO="$1" diff --git a/bin/webcheck_url.sh b/bin/webcheck_url.sh index bd500658..582d4aa6 100755 --- a/bin/webcheck_url.sh +++ b/bin/webcheck_url.sh @@ -1,28 +1,20 @@ #!/bin/bash -# Copyright 2012 Holger Levsen +# Copyright 2012,2014 Holger Levsen # released under the GPLv=2 +. /srv/jenkins/bin/common-functions.sh +common_init "$@" + +# convert params to variables if [ "$1" == "" ] ; then echo "need at least one URL to act on" echo '# $1 = URL' exit 1 fi - -# -# convert params to variables -# URL=$1 PATTERNS=$2 -# -# default settings -# -#set -x -set -e -export LC_ALL=C -export http_proxy="http://localhost:3128" - # # Don't use --continue on first run # -- cgit v1.2.3-54-g00ecf