2 # Filename: /usr/share/grml-live/buildd/functions.sh
3 # Purpose: main 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 ################################################################################
10 [ -n "$1" ] && echo "$1">&2
14 . /etc/grml/grml-buildd.conf || die "Could not source /etc/grml/grml-buildd.conf. Exiting."
16 which mutt >/dev/null 2>&1 || die "mutt binary not found. Exiting."
18 # exit if important variables aren't set:
19 [ -n "$STORAGE" ] || die "\$STORAGE is not set. Exiting."
20 [ -n "$SUITE" ] || die "\$SUITE is not set. Exiting."
21 [ -n "$CLASSES" ] || die "\$CLASSES is not set. Exiting."
22 [ -n "$NAME" ] || die "\$NAME is not set. Exiting."
23 [ -n "$ISO_NAME" ] || die "\$ISO_NAME is not set. Exiting."
26 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
27 DATE=$(date +'%Y%m%d_%H%M%S')
28 TMP_DIR="$(mktemp -d)"
29 [ -n "$TMP_DIR" ] || die "Could not create \$TMP_DIR. Exiting."
31 # make sure we have same safe defaults:
32 [ -n "$OUTPUT_DIR" ] || OUTPUT_DIR="${STORAGE}/grml-live_${DATE}.$$"
33 [ -n "$ISO_DIR" ] || ISO_DIR=$STORAGE/grml-isos
34 [ -n "$RECIPIENT" ] || RECIPIENT=root@localhost
35 [ -n "$FROM" ] || FROM=root@localhost
36 [ -n "$ARCH" ] || ARCH="$(dpkg --print-architecture)"
37 ATTACHMENT="$TMP_DIR/grml-live-logs_$DATE.tar.gz"
39 if [ -n "$LOGFILE" ] ; then
40 GRML_LOGFILE="$LOGFILE"
42 [ -n "$GRML_LOGFILE" ] || GRML_LOGFILE=/var/log/grml-live.log
45 [ -n "$FAI_LOGFILES" ] || FAI_LOGFILES=/var/log/fai/grml/last
49 if ! [ "$FORCE_REBUILD" = "1" ] ; then
50 if [ -f "$ISO_DIR/$ISO_NAME" ] ; then
51 echo "$ISO_DIR/$ISO_NAME exists already. Nothing to be done, exiting."
56 # workaround the 32 chars limit of mkisofs -V ....
57 # 'grml64-small-daily-squeeze 090223' is too long
60 squeeze) CODENAME=squ ;;
61 wheezy) CODENAME=wheez ;;
62 lenny) CODENAME=lenny ;;
63 etch) CODENAME=etch ;;
66 grml_name="$NAME-daily-$CODENAME"
67 shortdate="$(date +%y%m%d)"
69 TIME_START=$(date +%s)
70 grml-live -F $* -a $ARCH -s $SUITE -c $CLASSES -o $OUTPUT_DIR \
71 -g "$grml_name" -v "$shortdate" -r grml-live-autobuild -i $ISO_NAME \
72 >/var/log/grml-buildd.stdout \
73 2>/var/log/grml-buildd.stderr ; RC=$?
75 let WALLTIME=$TIME_END-$TIME_START
77 if [ "$RC" = "0" ] ; then
87 ( cd / && tar zcfh $ATTACHMENT $FAI_LOGFILES /var/log/grml-buildd.stderr /var/log/grml-buildd.stdout $GRML_LOGFILE >/dev/null )
90 # store logs on remote server:
92 [ -n "$RSYNC_MIRROR" ] || return 1
93 rsync --exclude dmesg.log --times --partial --copy-links -rltDz --quiet /var/log/grml-buildd.* \
94 $FAI_LOGFILES $GRML_LOGFILE $RSYNC_MIRROR/logs/"${NAME}_${DATE}"/
97 # store information of ISO size:
99 if ! [ -f "$OUTPUT_DIR/grml_isos/$ISO_NAME" ] ; then
100 ISO_DETAILS="There was an error creating $ISO_NAME"
102 ISO_DETAILS=$(ls -lh $OUTPUT_DIR/grml_isos/$ISO_NAME)
108 # create logs if using 'send_mail -e'
109 [ "$1" = "-e" ] && create_logs
111 # attach logs only if we have some:
112 [ -r "$ATTACHMENT" ] && MUTT_ATTACH="-a $ATTACHMENT" || MUTT_ATTACH=''
114 echo "Automatically generated mail by $SCRIPTNAME
118 Return code of grml-live was: $RC
121 $(grep -A2 'Executed grml-live' $GRML_LOGFILE || echo "* executed grml-live command line not available")
123 $(grep -A2 'Executed FAI' $GRML_LOGFILE || echo "* executed FAI command line not available")
125 The following errors have been noticed (several might be warnings only):
127 $(grep -i error $FAI_LOGFILES/*.log /var/log/grml-buildd.std* | grep -ve liberror -ve libgpg-error -ve libcomerr -ve 'no errors found' || echo "* nothing")
129 The following errors have been noticed in FAI scripts:
131 $(grep -B2 "FAILED with exit code" $FAI_LOGFILES/* | echo "* nothing")
133 The following warnings have been noticed:
135 $(grep -i warn $FAI_LOGFILES/* /var/log/grml-buildd.std* || echo "* nothing")
137 There following dependency problems have been noticed:
139 $(grep -i "Not Installed" $FAI_LOGFILES/software.log || echo "* nothing")
141 The following packages could not be installed:
143 $(grep -i "Couldn't find.*package" $FAI_LOGFILES/software.log | sed 's/\(.*\)"\(.*\)"\(.*\)/\2/' | sort -u || echo "* nothing")
145 See attached files for further details.
148 mutt -e "my_hdr From: grml-live autobuild daemon <$FROM>" -s "$SCRIPTNAME [${DATE}] - $RC_INFO" \
149 -a /var/log/grml-buildd.stderr $MUTT_ATTACH -- "$RECIPIENT"
152 # make sure we store the final iso:
154 if [ "$RC" = "0" ] ; then
155 [ -d "$ISO_DIR" ] || mkdir "$ISO_DIR"
156 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}" "$ISO_DIR"
157 if [ -r "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.md5" ] ; then
158 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.md5" "${ISO_DIR}"
160 if [ -r "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.sha1" ] ; then
161 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.sha1" "${ISO_DIR}"
168 if [ "$RC" = "0" ] ; then
169 rm -rf "$ATTACHMENT" "$TMP_DIR" "$OUTPUT_DIR"
172 echo "building ISO failed, keeping build files [${OUTPUT_DIR} / ${TMP_DIR}]">&2
177 trap bailout 1 2 3 15
179 ## END OF FILE #################################################################