1 | #!/bin/sh
|
---|
2 |
|
---|
3 | version="
|
---|
4 | jhalfs 0.1
|
---|
5 | Written by Jeremy Huntwork.
|
---|
6 |
|
---|
7 | This program is published under the \
|
---|
8 | Gnu General Public License, Version 2."
|
---|
9 |
|
---|
10 | usage="\
|
---|
11 | Usage: $0 [OPTION]
|
---|
12 |
|
---|
13 | Options:
|
---|
14 | -h, --help print this help, then exit
|
---|
15 | -V, --version print version number, then exit
|
---|
16 | -L, --LFS-version=VER use VER version of the LFS book
|
---|
17 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
18 | packages
|
---|
19 | "
|
---|
20 |
|
---|
21 | help="\
|
---|
22 | Try '$0 --help' for more information."
|
---|
23 |
|
---|
24 | exit_missing_arg="\
|
---|
25 | echo \"Option '\$1' requires an argument\" >&2
|
---|
26 | echo \"\$help\" >&2
|
---|
27 | exit 1"
|
---|
28 |
|
---|
29 | no_dl_client="\
|
---|
30 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
31 | echo \"Attempting to continue.\" >&2"
|
---|
32 |
|
---|
33 | while test $# -gt 0 ; do
|
---|
34 | case $1 in
|
---|
35 | --version | -V )
|
---|
36 | echo "$version"
|
---|
37 | exit 0
|
---|
38 | ;;
|
---|
39 |
|
---|
40 | --help | -h )
|
---|
41 | echo "$usage"
|
---|
42 | exit 0
|
---|
43 | ;;
|
---|
44 |
|
---|
45 | --LFS-version | -L )
|
---|
46 | test $# = 1 && eval "$exit_missing_arg"
|
---|
47 | shift
|
---|
48 | case $1 in
|
---|
49 | dev* | SVN | trunk )
|
---|
50 | LFSVRS=development
|
---|
51 | ;;
|
---|
52 | * )
|
---|
53 | echo "$1 is an unsupported version at this time."
|
---|
54 | exit 1
|
---|
55 | ;;
|
---|
56 | esac
|
---|
57 | shift
|
---|
58 | ;;
|
---|
59 |
|
---|
60 | --download-client | -D )
|
---|
61 | test $# = 1 && eval "$exit_missing_arg"
|
---|
62 | shift
|
---|
63 | DL=$1
|
---|
64 | shift
|
---|
65 | ;;
|
---|
66 |
|
---|
67 | --su-lfs )
|
---|
68 | echo "Build section with 'lfs' user"
|
---|
69 | ;;
|
---|
70 |
|
---|
71 | --chroot)
|
---|
72 | echo "Build chroot section"
|
---|
73 | ;;
|
---|
74 |
|
---|
75 | * )
|
---|
76 | echo "$usage"
|
---|
77 | exit 1
|
---|
78 | ;;
|
---|
79 | esac
|
---|
80 | done
|
---|
81 |
|
---|
82 | # Test to make sure we're running the build as root
|
---|
83 |
|
---|
84 | if [ "$UID" != "0" ] ; then
|
---|
85 | echo "You must be logged in as root to successfully build LFS."
|
---|
86 | exit 1
|
---|
87 | fi
|
---|
88 |
|
---|
89 | # Find the download client to use, if not already specified.
|
---|
90 |
|
---|
91 | if [ -z $DL ] ; then
|
---|
92 | if [ `type -p wget` ] ; then
|
---|
93 | DL=wget
|
---|
94 | elif [ `type -p curl` ] ; then
|
---|
95 | DL=curl
|
---|
96 | else
|
---|
97 | eval "$no_dl_client"
|
---|
98 | fi
|
---|
99 | fi
|
---|
100 |
|
---|
101 | SVN="svn://svn.linuxfromscratch.org"
|
---|
102 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
103 | BUILDDIR=/mnt/lfs
|
---|
104 | LOG=build.log
|
---|
105 |
|
---|
106 | get_book() {
|
---|
107 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
108 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
109 | exit 1"
|
---|
110 | cd $BUILDDIR
|
---|
111 |
|
---|
112 | # Test to make sure the LFS version is set
|
---|
113 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
114 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
115 |
|
---|
116 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
117 | # repo. If we've already extracted the commands, move on to getting the
|
---|
118 | # sources.
|
---|
119 | if [ -d lfs-$LFSVRS ] ; then
|
---|
120 | cd lfs-$LFSVRS
|
---|
121 | if svn up | grep -q At && test -d $BUILDDIR/commands && \
|
---|
122 | test -f $BUILDDIR/packages && test -f $BUILDDIR/patches ; then
|
---|
123 | echo -ne "done\n"
|
---|
124 | get_sources
|
---|
125 | else
|
---|
126 | echo -ne "done\n"
|
---|
127 | extract_commands
|
---|
128 | fi
|
---|
129 | else
|
---|
130 | if [ $LFSVRS = development ] ; then
|
---|
131 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$BUILDDIR/$LOG 2>&1
|
---|
132 | else
|
---|
133 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$BUILDDIR/$LOG 2>&1
|
---|
134 | fi
|
---|
135 | echo -ne "done\n"
|
---|
136 | extract_commands
|
---|
137 | fi
|
---|
138 | }
|
---|
139 |
|
---|
140 | extract_commands() {
|
---|
141 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
142 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
143 | exit 1"
|
---|
144 | cd $BUILDDIR
|
---|
145 |
|
---|
146 | # Start clean
|
---|
147 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
148 | echo -n "Extracting commands... "
|
---|
149 |
|
---|
150 | # Use Maneul's stylesheet to dump the commands in text form from the LFS book.
|
---|
151 | xsltproc -v --nonet --xinclude -o ./commands/ \
|
---|
152 | lfs-$LFSVRS/stylesheets/dump-commands.xsl lfs-$LFSVRS/index.xml \
|
---|
153 | >>$BUILDDIR/$LOG 2>&1
|
---|
154 |
|
---|
155 | # Move the text files out from the chapter directories, and dump them
|
---|
156 | # all into the 'commands' directory.
|
---|
157 | cd commands
|
---|
158 | find ./* -xtype f -exec mv '{}' . \;
|
---|
159 | find ./* -maxdepth 0 -xtype d -exec rm -rf '{}' \;
|
---|
160 |
|
---|
161 | # Grab the patches and package names.
|
---|
162 | cd $BUILDDIR
|
---|
163 | for i in patches packages ; do rm -f $i ; done
|
---|
164 | grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
165 | -e '/generic/d' >> packages
|
---|
166 | grep "ENTITY" lfs-$LFSVRS/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
167 |
|
---|
168 | # Done. Moving on...
|
---|
169 | echo -ne "done\n"
|
---|
170 | get_sources
|
---|
171 | }
|
---|
172 |
|
---|
173 | download() {
|
---|
174 | cd $BUILDDIR/sources
|
---|
175 |
|
---|
176 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
177 | # to norms in the URL scheme.
|
---|
178 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
179 |
|
---|
180 | # Find the md5 sum for this package.
|
---|
181 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
182 |
|
---|
183 | if [ ! -f $2 ] ; then
|
---|
184 | case $DL in
|
---|
185 | wget )
|
---|
186 | wget $HTTP/$DIR/$2
|
---|
187 | ;;
|
---|
188 | curl )
|
---|
189 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
190 | ;;
|
---|
191 | * )
|
---|
192 | echo "$DL not supported at this time."
|
---|
193 | ;;
|
---|
194 | esac
|
---|
195 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
196 | case $DL in
|
---|
197 | wget )
|
---|
198 | wget -c $HTTP/$DIR/$2
|
---|
199 | ;;
|
---|
200 | curl )
|
---|
201 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
202 | ;;
|
---|
203 | * )
|
---|
204 | echo "$DL not supported at this time."
|
---|
205 | ;;
|
---|
206 | esac
|
---|
207 | fi
|
---|
208 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
209 | exit 1
|
---|
210 | fi
|
---|
211 | }
|
---|
212 |
|
---|
213 | get_sources() {
|
---|
214 |
|
---|
215 | # This variable is necessary to make sure the `cat $BUILDDIR/packages`
|
---|
216 | # separates each iteration by lines. It is necessary to have the second
|
---|
217 | # ' on the next line.
|
---|
218 | IFS='
|
---|
219 | '
|
---|
220 |
|
---|
221 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
222 | cd $BUILDDIR/sources
|
---|
223 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
224 |
|
---|
225 | download "" MD5SUMS
|
---|
226 |
|
---|
227 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
228 | for i in `cat $BUILDDIR/packages` ; do
|
---|
229 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
230 |
|
---|
231 | # Someone used some silly entities right next to the valid package entities.
|
---|
232 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
233 |
|
---|
234 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
235 | if [ "$PKG" = "tcl" ] ; then
|
---|
236 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
237 | else
|
---|
238 | FILE="$PKG-$VRS.tar.bz2"
|
---|
239 | fi
|
---|
240 | download $PKG $FILE
|
---|
241 | for patch in `grep "$PKG-&$PKG" $BUILDDIR/patches` ; do
|
---|
242 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
243 | download $PKG $PATCH
|
---|
244 | done
|
---|
245 | done
|
---|
246 | }
|
---|
247 |
|
---|
248 |
|
---|
249 | if [ ! -d $BUILDDIR ] ; then
|
---|
250 | mkdir $BUILDDIR
|
---|
251 | fi
|
---|
252 |
|
---|
253 | >$BUILDDIR/$LOG
|
---|
254 | cp $0 $BUILDDIR/
|
---|
255 | get_book
|
---|