~xubuntu-dev/livecd-rootfs/xubuntu-base

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
BUILD_LOG=~/public_html/BuildLive.out
ALWAYS_SEND_LOG=yes
LANG=C

finish() {
    [ $? != "0" ] && STATUS="Failed" || STATUS="Successful"
    if [ "$STATUS" = "Failed" ] || [ "$ALWAYS_SEND_LOG" = "yes" ]; then
    	SEND_LOG=yes
    fi
    if [ -e "$LOG" ]; then
        echo "======================= Log of livefs.sh output follows ======================="
        cat $LOG
    fi
    if [ "$SEND_LOG" = "yes" ]; then
        exec >/dev/null 2>&1
        mailx -s "LiveCD: $STATUS $STE:$FS${SUBPROJECT:+-$SUBPROJECT}${SUBARCH:+-$SUBARCH}${UBUNTU_DEFAULTS_LOCALE:+-$UBUNTU_DEFAULTS_LOCALE} build on ${ARCH}" buildd+porters < "$BUILD_LOG"
    fi
    rm -f ~/buildLiveCD.lock
    nohup ~/bin/pruneLiveCD >/dev/null 2>&1 &
}

if [ -n "$SSH_ORIGINAL_COMMAND" ]; then
    set -- $SSH_ORIGINAL_COMMAND
    [ ${1##*/} != 'BuildLiveCD' ] && echo bad command >&2 && exit 2
    shift
fi
ARCH=$(dpkg --print-architecture)
SUBARCH=""
NEWSUITE="precise"
SUITES=""
PROPOSED=""
IMAGEFORMAT=""
LIVE_BUILD=false
UBUNTU_DEFAULTS_LOCALE=""

while getopts :A:s:r:d:f:plu:t: name; do case $name in
    A)	ARCH="$OPTARG";;
    s)	SUBARCH="$OPTARG";;
    r)	SUBPROJECT="$OPTARG";;
    d)	NEWSUITE="$OPTARG";;
    f)	IMAGEFORMAT="$OPTARG";;
    p)	PROPOSED="-p";;
    l)	LIVE_BUILD=:;;
    u)	UBUNTU_DEFAULTS_LOCALE="$OPTARG";;
    t)	UBUNTU_TOUCH_ANDROID="$OPTARG";;
esac; done;
shift $((OPTIND-1))

for s in $NEWSUITE; do
    if [ -d build-${s}-live/chroot-${s} ]; then SUITES="$SUITES $s"; fi
done
if [ -z "$SUITES" ]; then
    echo "No valid suites to build for" >&2 && exit 1
fi
for s in $SUITES; do
    case $s in
        dapper|edgy|feisty|gutsy|hardy)
            old_suite="yes"
            ;;
        *)
            new_suite="yes"
            ;;
    esac
done
if [ "$new_suite" = "yes" ] && [ "$old_suite" = "yes" ]; then
    echo "Can't build images for suites older than intrepid and suites" >&2
    echo "greater than hardy at the same time, please use two invocations" >&2
    exit 1
fi
if ([ $# = 0 ] || [ "X$1" = "Xall" ]) && ! $LIVE_BUILD; then
    set -- ubuntu kubuntu kubuntu-active edubuntu xubuntu mythbuntu base
    if [ "$ARCH" = "i386" ]; then
        set -- ubuntu ubuntu-dvd ubuntu-lpia ubuntu-netbook kubuntu kubuntu-dvd kubuntu-active edubuntu edubuntu-dvd xubuntu mythbuntu base
    fi
fi

case ${ARCH} in
    hppa|sparc|powerpc) LINUX32=linux32;;
    *) LINUX32="";;
esac

if [ "`echo $@ | wc -w`" -gt "1" ]; then
    for arg in "$@"; do
        $0 $arg
    done
    exit 0
fi
FS="$1"
shift

# 12 hours should be enough for even the longest build queue to clear.
lockfile -8 -r$((12 * 60 * 60 / 8)) ~/buildLiveCD.lock || exit 1
trap "finish" 0
trap "rm -f ~/buildLiveCD.lock; exit 1" 1 2 3 15
exec > $BUILD_LOG 2>&1
set -e

for STE in $SUITES; do
    if [ -d ~/build-${STE}-live/chroot-${STE} ]; then
	sudo chroot ~/build-${STE}-live/chroot-${STE} apt-get -qq update || true
	sudo chroot ~/build-${STE}-live/chroot-${STE} apt-get -y dist-upgrade || true
	sudo chroot ~/build-${STE}-live/chroot-${STE} apt-get -y install livecd-rootfs eatmydata || true
	sudo chroot ~/build-${STE}-live/chroot-${STE} apt-get -y --install-recommends install ubuntu-defaults-builder || true
    fi
done
for STE in $SUITES; do
    if cd ~/build-${STE}-live 2>/dev/null; then
	DIR=~/build-${STE}-live/chroot-${STE}/./build/
    else
	cd ~/build.live
	DIR=~/build.live/chroot-${STE}/./build/
    fi

    PUBDIR=~/public_html/LiveCD/${STE}/${FS}${SUBPROJECT:+-$SUBPROJECT}${SUBARCH:+-$SUBARCH}${UBUNTU_DEFAULTS_LOCALE:+-$UBUNTU_DEFAULTS_LOCALE}/
    mkdir -p ${PUBDIR}

    NOW=$(date +%Y%m%d)
    if [ -d ${PUBDIR}${NOW} ]; then
	typeset -i n=1; while [ -d ${PUBDIR}${NOW}.$n ]; do n=n+1; done
	NOW=${NOW}.$n
    fi
    LOG=${PUBDIR}${NOW}/livecd-${NOW}-${ARCH}.out

    rm -f ${PUBDIR}latest
    ln -sf ${PUBDIR}${NOW} ${PUBDIR}latest
    mkdir -p ${PUBDIR}${NOW}
    > ${LOG}
    ln -sf livecd-${NOW}-${ARCH}.out ${PUBDIR}${NOW}/livecd-${ARCH}.out
    if $LIVE_BUILD; then
	$LINUX32 sudo chroot ${DIR%/./*} sh -c "cd /${DIR#*/./} && rm -rf auto && mkdir -p auto && for f in config build clean; do ln -s /usr/share/livecd-rootfs/live-build/auto/\$f auto/; done" >> ${LOG} 2>&1 || true
	$LINUX32 sudo chroot ${DIR%/./*} sh -c "cd /${DIR#*/./} && lb clean --purge" >> ${LOG} 2>&1 || true
	if ! $LINUX32 sudo chroot ${DIR%/./*} sh -c "cd /${DIR#*/./} && NOW=${NOW} SUITE=${STE} PROJECT=${FS} SUBPROJECT=${SUBPROJECT} ARCH=${ARCH} SUBARCH=${SUBARCH} IMAGEFORMAT=${IMAGEFORMAT} PROPOSED=${PROPOSED:+1} lb config" >> ${LOG} 2>&1; then
	    exit 1
	fi
	COMMAND="PROJECT=${FS} SUBPROJECT=${SUBPROJECT} ARCH=${ARCH} SUBARCH=${SUBARCH} lb build"
    elif [ "$UBUNTU_DEFAULTS_LOCALE" ]; then
	COMMAND="ubuntu-defaults-image --locale ${UBUNTU_DEFAULTS_LOCALE} --arch ${ARCH} --release ${STE}"
    else
	echo "Must pass either -l or -u."
	exit 1
    fi
    if $LINUX32 sudo chroot ${DIR%/./*} sh -c "cd /${DIR#*/./} && eatmydata -- $COMMAND" >> ${LOG} 2>&1; then
	rm -f ${PUBDIR}current
	ln -sf ${NOW} ${PUBDIR}current

	for file in ${DIR}livecd.*; do
	    if [ -f ${file} ]; then
		ext=${file##*.}
		base=${file%.*}; base=${base##*/}
		sudo chown buildd ${file}
		sudo mv ${file} ${PUBDIR}${NOW}/${base}-${NOW}-${ARCH}.${ext}
		ln -sf ${base}-${NOW}-${ARCH}.${ext} ${PUBDIR}${NOW}/${base}.${ext}
	    fi
	done

	for f in ${PUBDIR}${NOW}/livecd.*.cloop-*; do 
	    if [ -f ${f} ]; then
		target=${f%-*}
		if [ ! -f ${target} ]; then
		    for fsbs in 4096:4096 1024:65536; do
			if [ -f ${target}-${fsbs} ]; then
			    ln -sf ${target##*/}-${fsbs} ${target}
			    break
			fi
		    done
		    if [ ! -f ${target} ]; then
			best=$(ls -ld ${target}-* | sort -k5,5n| awk '{print $NF; quit}')
			ln -sf ${best##*/} ${target}
		    fi
		fi
	    fi
	done
    else
	exit 1
    fi
done