c76e099e1255a41cf110ab9e1657d220c4a98021
[grml-live.git] / buildd / main.sh
1 #!/bin/sh
2 # Filename:      main.sh
3 # Purpose:       main configuration and function file for grml-live buildd
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2 or any later version.
7 # Latest change: Don Okt 18 00:32:02 CEST 2007 [mika]
8 ################################################################################
9
10 # configuration:
11 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
12 DATE=$(date +%Y%m%d)
13 STORAGE=/grml-live/
14 OUTPUT_DIR="${STORAGE}/grml-live_${DATE}.$$"
15 TMP_DIR=$(mktemp -d)
16 MUTT_HEADERS=$(mktemp)
17 ATTACHMENT=$TMP_DIR/grml-live-logs_$DATE.tar.gz
18 [ -n "$ARCH" ] && GRML_LIVE_ARCH="-a $ARCH"
19 [ -n "$TMP_DIR" ] || exit 10
20 [ -n "$MUTT_HEADERS" ] || exit 20
21 RECIPIENT=root@localhost
22 ISO_DIR=/grml-live/grml-isos
23 echo "my_hdr From: grml-live autobuild daemon <root@localhost>" > $MUTT_HEADERS
24
25 # execute grml-live:
26 grml_live_run() {
27 grml-live -F $GRML_LIVE_ARCH -s $SUITE -c $CLASSES -o $OUTPUT_DIR \
28           -g $NAME -v $DATE -r grml-live-autobuild -i $ISO_NAME \
29           1>/var/log/fai/dirinstall/grml/grml-live.stdout \
30           2>/var/log/fai/dirinstall/grml/grml-live.stderr ; RC=$?
31
32 if [ "$RC" = "0" ] ; then
33    RC=success
34 else
35    RC=error
36 fi
37 }
38
39 create_logs() {
40 # create log archive:
41 tar zcf $ATTACHMENT /var/log/fai/dirinstall/grml 1>/dev/null
42 }
43
44 iso_details() {
45 if ! [ -f "$OUTPUT_DIR/grml_isos/$ISO_NAME" ] ; then
46    ISO_DETAILS="There was an error creating $ISO_NAME"
47 else
48    ISO_DETAILS=$(ls -lh $OUTPUT_DIR/grml_isos/$ISO_NAME)
49 fi
50 }
51
52 send_mail() {
53 # send status mail:
54 echo -en "Automatically generated mail by $SCRIPTNAME
55
56 $ISO_DETAILS
57
58 Return code of grml-live run was: $RC
59
60 The following errors have been noticed (several might be warnings only):
61
62 $(grep error /var/log/fai/dirinstall/grml/* | grep -ve liberror -ve libgpg-error)
63
64 The following warnings have been noticed:
65
66 $(grep warn /var/log/fai/dirinstall/grml/*)
67
68 Find details in the attached logs." | \
69 mutt -s "grml-live_autobuild_grml-large_sid.sh [${DATE}] - $RC" \
70      -a $ATTACHMENT \
71      $RECIPIENT
72 }
73
74 store_iso() {
75 # make sure we store the final iso:
76 [ -d "$ISO_DIR" ] || mkdir "$ISO_DIR"
77 mv $OUTPUT_DIR/grml_isos/$ISO_NAME $ISO_DIR
78 }
79
80 bailout() {
81   rm -rf "$TMP_DIR" "$MUTT_HEADERS" "$OUTPUT_DIR"
82 }
83
84 trap bailout 1 2 3 15
85
86 ## END OF FILE #################################################################