]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-interactive
Rewrote some things in make.sh...
[ipfire-3.x.git] / tools / make-interactive
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 case "$1" in
23 build)
24 clear
25 #a prebuilt toolchain package is only used if found in cache
26 if [ ! -d $BASEDIR/cache ]; then
27 exiterror "Use make.sh downloadsrc first!"
28 fi
29 cd $BASEDIR/cache/toolchains
30 PACKAGE=`ls -v -r $TOOLCHAINNAME.tar.bz2 2> /dev/null | head -n 1`
31 #only restore on a clean disk
32
33 echo -ne "Building for ${BOLD}${MACHINE} on ${MACHINE_REAL}${NORMAL}\n"
34
35 if [ -f $BASEDIR/log_${MACHINE}/02_base/stage2-LFS ]; then
36 prepareenv
37 echo "Using installed toolchain" >> $LOGFILE
38 beautify message DONE "Stage toolchain already built or extracted"
39 else
40 if [ -z "$PACKAGE" ]; then
41 echo "Full toolchain compilation" | tee -a $LOGFILE
42 prepareenv
43
44 . $BASEDIR/tools/make-check
45 check_toolchain
46
47 beautify build_stage "Building toolchain"
48 toolchain_build
49 else
50 echo "Restore from $PACKAGE" | tee -a $LOGFILE
51 if [ `md5sum $BASEDIR/cache/toolchains/$PACKAGE | awk '{print $1}'` == `cat $BASEDIR/cache/toolchains/$TOOLCHAINNAME.md5 | awk '{print $1}'` ]; then
52 cd $BASEDIR && tar jxf $BASEDIR/cache/toolchains/$PACKAGE
53 prepareenv
54 else
55 exiterror "$TOOLCHAINNAME md5 did not match, check downloaded package"
56 fi
57 fi
58 fi
59
60 beautify build_stage "Building base"
61 base_build
62
63 beautify build_stage "Building $SNAME"
64 ipfire_build
65
66 beautify build_stage "Building miscellaneous"
67 misc_build
68
69 beautify build_stage "Building installer"
70 installer_build
71
72 beautify build_stage "Building packages"
73 packages_build
74
75 echo ""
76 echo "... and all this hard work for this:"
77 du -bsh $BASEDIR/${SNAME}-${VERSION}.${MACHINE}.iso
78 ;;
79
80 shell)
81 # enter a shell inside LFS chroot
82 # may be used to change kernel settings
83 prepareenv
84 entershell
85 ;;
86
87 clean)
88 echo -ne "Cleaning ${BOLD}$MACHINE${NORMAL} buildtree"
89 for i in `mount | grep $BASEDIR | sed 's/^.*loop=\(.*\))/\1/'`
90 do
91 $LOSETUP -d $i 2>/dev/null
92 done
93
94 for i in `mount | grep $BASEDIR | cut -d " " -f 1`
95 do
96 umount $i
97 done
98
99 stdumount
100
101 for i in `seq 0 7`
102 do
103 if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
104 umount /dev/loop${i} 2>/dev/null;
105 losetup -d /dev/loop${i} 2>/dev/null;
106 fi;
107 done
108
109 rm -rf $BASEDIR/build_${MACHINE}
110 rm -rf $BASEDIR/log_${MACHINE}
111 rm -rf $BASEDIR/packages
112
113 if [ -h $TOOLS_DIR ]; then
114 rm -f $TOOLS_DIR
115 fi
116 beautify message DONE
117 ;;
118
119 downloadsrc)
120 LOGFILE=$BASEDIR/log_${MACHINE}/_build.preparation.log
121
122 if [ ! -d $BASEDIR/cache ]; then
123 mkdir $BASEDIR/cache
124 fi
125 mkdir -p $BASEDIR/log_${MACHINE}
126 echo -e "${BOLD}Preload all source files${NORMAL}" | tee -a $LOGFILE
127 cd $BASEDIR/lfs
128 for i in *; do
129 if [ -f "$i" -a "$i" != "Config" ]; then
130 echo -ne "Loading $i"
131 make -s -f $i LFS_BASEDIR=$BASEDIR MESSAGE="$i\t" download >> $LOGFILE 2>&1
132 if [ $? -ne 0 ]; then
133 beautify message FAIL
134 else
135 beautify message DONE
136 fi
137 fi
138 done
139 cd - >/dev/null 2>&1
140 ;;
141
142 toolchain)
143 prepareenv
144 # Check if host can build the toolchain
145 check_toolchain_prerequisites
146 toolchain_build
147 echo "Create toolchain tar.bz for $MACHINE" | tee -a $LOGFILE
148 # Safer inside the chroot
149 echo -ne "Stripping lib"
150 chroot $LFS $TOOLS_DIR/bin/find $TOOLS_DIR/lib \
151 -type f \( -name '*.so' -o -name '*.so[\.0-9]*' \) \
152 -exec $TOOLS_DIR/bin/strip --strip-debug {} \; 2>/dev/null
153 beautify message DONE
154 echo -ne "Stripping binaries"
155 chroot $LFS $TOOLS_DIR/bin/find /usr/local /usr/src/binutils-build $TOOLS_DIR/bin $TOOLS_DIR/sbin \
156 -type f \
157 -exec $TOOLS_DIR/bin/strip --strip-all {} \; 2> /dev/null
158 beautify message DONE
159 stdumount
160 echo -ne "Tar creation "
161 [ -d cache/toolchains ] || mkdir cache/toolchains
162 cd $BASEDIR && tar cj \
163 --exclude='log_${MACHINE}/_build.*.log' \
164 --file=cache/toolchains/$TOOLCHAINNAME.tar.bz2 \
165 build_${MACHINE} \
166 log_${MACHINE} >> $LOGFILE
167 beautify message DONE
168 echo `ls -sh cache/toolchains/$TOOLCHAINNAME.tar.bz2`
169 md5sum cache/toolchains/$TOOLCHAINNAME.tar.bz2 \
170 > cache/toolchains/$TOOLCHAINNAME.md5
171
172 stdumount
173 ;;
174
175 gettoolchain)
176 if [ ! -f $BASEDIR/cache/toolchains/$TOOLCHAINNAME.tar.bz2 ]; then
177 URL_TOOLCHAIN=`grep URL_TOOLCHAIN lfs/Config | awk '{ print $3 }'`
178 test -d $BASEDIR/cache/toolchains || mkdir $BASEDIR/cache/toolchains
179 echo "Loading toolchain for $MACHINE"
180 cd $BASEDIR/cache/toolchains
181 wget -c -nv $URL_TOOLCHAIN/$TOOLCHAINNAME.tar.bz2 $URL_TOOLCHAIN/$TOOLCHAINNAME.md5
182 if [ $? -ne 0 ]; then
183 echo -n "ERROR: Downloading toolchain for $MACHINE machine"
184 beautify message FAIL
185 echo "Precompiled toolchain not always available for every machine"
186 else
187 if [ "`md5sum $TOOLCHAINNAME.tar.bz2 | awk '{print $1}'`" = "`cat $TOOLCHAINNAME.md5 | awk '{print $1}'`" ]; then
188 beautify message DONE
189 echo "Toolchain md5 ok"
190 else
191 exiterror "$TOOLCHAINNAME.md5 did not match, check downloaded package"
192 fi
193 fi
194 else
195 echo -n "Toolchain for $MACHINE is already existing"
196 beautify message SKIP
197 fi
198 ;;
199
200 othersrc)
201 prepareenv
202 echo -ne "`date -u '+%b %e %T'`: Build sources iso for $MACHINE" | tee -a $LOGFILE
203 chroot $LFS /tools/bin/env -i HOME=/root \
204 TERM=$TERM PS1='\u:\w\$ ' \
205 PATH=/usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbin \
206 VERSION=$VERSION NAME="$NAME" SNAME="$SNAME" MACHINE=$MACHINE \
207 /bin/bash -x -c "cd /usr/src/lfs && make -f sources-iso LFS_BASEDIR=/usr/src install" >>$LOGFILE 2>&1
208 mv $LFS/install/images/ipfire-* $BASEDIR >> $LOGFILE 2>&1
209 if [ $? -eq "0" ]; then
210 beautify message DONE
211 else
212 beautify message FAIL
213 fi
214 stdumount
215 ;;
216
217 svn)
218 . $BASEDIR/tools/make-subversion
219 case "$2" in
220 update|up)
221 svn_up
222 ;;
223 commit|ci)
224 clear
225 svn_commit
226 svn_up
227 ;;
228 dist)
229 svn_dist
230 ;;
231 diff|di)
232 svn_diff
233 ;;
234 log)
235 svn_log
236 ;;
237 esac
238 ;;
239
240 uploadsrc)
241 PWD=`pwd`
242 cd $BASEDIR/cache/
243 echo -e "Uploading cache to ftp server:"
244 for i in *; do
245 echo "${i}" | fgrep -q .md5 && continue
246 [ -e ${i}.md5 ] && continue
247 md5sum ${i} | tee ${i}.md5
248 done
249 ncftpls -u $FTP_CACHE_USER -p $FTP_CACHE_PASS ftp://$FTP_CACHE_URL/$FTP_CACHE_PATH/ > /tmp/ftplist
250 for i in *; do
251 if [ "$(basename $i)" == "toolchains" ]; then continue; fi
252 grep -q $(basename $i) /tmp/ftplist
253 if [ "$?" -ne "0" ]; then
254 echo -ne "$(basename $i)"
255 ncftpput -u $FTP_CACHE_USER -p $FTP_CACHE_PASS $FTP_CACHE_URL $FTP_CACHE_PATH/ $(basename $i)
256 if [ "$?" -ne "0" ]; then
257 beautify message FAIL
258 fi
259 fi
260 done
261 rm -f /tmp/ftplist
262 cd $PWD
263 exit 0
264 ;;
265
266 upload)
267 FTP_ISO_PORT=`echo "$FTP_ISO_URL" | awk -F: '{ print $2 }'`
268 FTP_ISO_URL=`echo "$FTP_ISO_URL" | awk -F: '{ print $1 }'`
269 if [ -z $FTP_ISO_PORT ]; then
270 FTP_ISO_PORT=21
271 fi
272 cat <<EOF > .ftp-commands
273 mkdir -p $FTP_ISO_PATH$SVN_REVISION
274 mkdir -p $FTP_ISO_PATH$SVN_REVISION/paks
275 quit
276 EOF
277 ncftp -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL < .ftp-commands
278 rm -f .ftp-commands
279
280 case "$2" in
281 iso)
282 echo -e "Uploading the iso to $FTP_ISO_PATH/$SVN_REVISION."
283
284 md5sum ipfire-$VERSION.$MACHINE-full.iso > ipfire-$VERSION.$MACHINE-full.iso.md5
285 for i in svn_status ipfire-source-r$SVN_REVISION.tar.gz ipfire-$VERSION.$MACHINE-full.iso ipfire-$VERSION.$MACHINE-full.iso.md5 ipfire-$VERSION.$MACHINE-devel.iso ipfire-$VERSION.$MACHINE-devel.iso.md5; do
286 if [ -e "$i" ]; then
287 ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/ $i
288 if [ "$?" -eq "0" ]; then
289 echo "The file with name $i was successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
290 else
291 echo "There was an error while uploading the file $i to the ftp server."
292 exit 1
293 fi
294 fi
295 done
296 rm -f ipfire-$VERSION.$MACHINE-full.iso.md5
297 if [ "$3" = "--with-sources-cd" ]; then
298 ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH/$SVN_REVISION/ ipfire-sources-cd-$VERSION.$MACHINE.iso
299 fi
300 ;;
301 paks)
302 ncftpput -u $FTP_ISO_USER -p $FTP_ISO_PASS -P $FTP_ISO_PORT $FTP_ISO_URL $FTP_ISO_PATH$SVN_REVISION/paks packages/*
303 if [ "$?" -eq "0" ]; then
304 echo -e "The packages were successfully uploaded to $FTP_ISO_URL$FTP_ISO_PATH$SVN_REVISION/."
305 else
306 echo -e "There was an error while uploading the packages to the ftp server."
307 exit 1
308 fi
309 ;;
310 esac
311 ;;
312
313 batch)
314 if [ "$2" = "--background" ]; then
315 batch_script
316 exit $?
317 fi
318 if [ `screen -ls | grep -q ipfire` ]; then
319 echo "Build is already running, sorry!"
320 exit 1
321 else
322 if [ "$2" = "--rebuild" ]; then
323 export IPFIRE_REBUILD=1
324 echo "REBUILD!"
325 else
326 export IPFIRE_REBUILD=0
327 fi
328 echo -en "${BOLD}***IPFire-Batch-Build is starting...${NORMAL}"
329 screen -dmS ipfire $0 batch --background
330 evaluate 1
331 exit 0
332 fi
333 ;;
334
335 watch|attach)
336 watch_screen
337 ;;
338
339 ccache)
340 . $BASEDIR/tools/make-compilers
341 ccache_stats
342 ;;
343
344 *)
345 cat doc/make.sh-usage
346 ;;
347
348 esac