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 grml-live -F $* -a $ARCH -s $SUITE -c $CLASSES -o $OUTPUT_DIR \
70 -g "$grml_name" -v "$shortdate" -r grml-live-autobuild -i $ISO_NAME \
71 >/var/log/grml-buildd.stdout \
72 2>/var/log/grml-buildd.stderr ; RC=$?
74 if [ "$RC" = "0" ] ; then
84 ( cd / && tar zcfh $ATTACHMENT $FAI_LOGFILES /var/log/grml-buildd.stderr /var/log/grml-buildd.stdout $GRML_LOGFILE >/dev/null )
87 # store logs on remote server:
89 [ -n "$RSYNC_MIRROR" ] || return 1
90 rsync --exclude dmesg.log --times --partial --copy-links -rltDz --quiet /var/log/grml-buildd.* \
91 $FAI_LOGFILES $GRML_LOGFILE $RSYNC_MIRROR/logs/"${NAME}_${DATE}"/
94 # store information of ISO size:
96 if ! [ -f "$OUTPUT_DIR/grml_isos/$ISO_NAME" ] ; then
97 ISO_DETAILS="There was an error creating $ISO_NAME"
99 ISO_DETAILS=$(ls -lh $OUTPUT_DIR/grml_isos/$ISO_NAME)
105 # create logs if using 'send_mail -e'
106 [ "$1" = "-e" ] && create_logs
108 # attach logs only if we have some:
109 [ -r "$ATTACHMENT" ] && MUTT_ATTACH="-a $ATTACHMENT" || MUTT_ATTACH=''
111 echo -en "Automatically generated mail by $SCRIPTNAME
115 Return code of grml-live run was: $RC
117 $(grep -A2 'Executed grml-live' $GRML_LOGFILE || echo "* executed grml-live command line not available")
119 $(grep -A2 'Executed FAI' $GRML_LOGFILE || echo "* executed FAI command line not available")
121 The following errors have been noticed (several might be warnings only):
123 $(grep -i error $FAI_LOGFILES/* /var/log/grml-buildd.std* | grep -ve liberror -ve libgpg-error || echo "* nothing")
125 The following errors have been noticed in FAI scripts:
127 $(grep -B2 "FAILED with exit code" $FAI_LOGFILES/* | echo "* nothing")
129 The following warnings have been noticed:
131 $(grep -i warn $FAI_LOGFILES/* /var/log/grml-buildd.std* || echo "* nothing")
133 There following dependency problems have been noticed:
135 $(grep -i "Not Installed" $FAI_LOGFILES/software.log || echo "* nothing")
137 The following packages could not be installed:
139 $(grep -i "Couldn't find.*package" $FAI_LOGFILES/software.log | sed 's/\(.*\)"\(.*\)"\(.*\)/\2/' | sort -u || echo "* nothing")
141 See attached files for further details.
144 mutt -e "my_hdr From: grml-live autobuild daemon <$FROM>" -s "$SCRIPTNAME [${DATE}] - $RC_INFO" \
145 -a /var/log/grml-buildd.stderr $MUTT_ATTACH -- "$RECIPIENT"
148 # make sure we store the final iso:
150 if [ "$RC" = "0" ] ; then
151 [ -d "$ISO_DIR" ] || mkdir "$ISO_DIR"
152 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}" "$ISO_DIR"
153 if [ -r "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.md5" ] ; then
154 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.md5" "${ISO_DIR}"
156 if [ -r "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.sha1" ] ; then
157 mv "${OUTPUT_DIR}/grml_isos/${ISO_NAME}.sha1" "${ISO_DIR}"
164 if [ "$RC" = "0" ] ; then
165 rm -rf "$ATTACHMENT" "$TMP_DIR" "$OUTPUT_DIR"
168 echo "building ISO failed, keeping build files [${OUTPUT_DIR} / ${TMP_DIR}]">&2
173 trap bailout 1 2 3 15
175 ## END OF FILE #################################################################