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 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
105 | LOG=build.log
|
---|
106 |
|
---|
107 | get_book() {
|
---|
108 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
109 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
110 | exit 1"
|
---|
111 | cd $JHALFSDIR
|
---|
112 |
|
---|
113 | # Test to make sure the LFS version is set
|
---|
114 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
115 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
116 |
|
---|
117 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
118 | # repo. If we've already extracted the commands, move on to getting the
|
---|
119 | # sources.
|
---|
120 | if [ -d lfs-$LFSVRS ] ; then
|
---|
121 | cd lfs-$LFSVRS
|
---|
122 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
123 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
124 | echo -ne "done\n"
|
---|
125 | get_sources
|
---|
126 | else
|
---|
127 | echo -ne "done\n"
|
---|
128 | extract_commands
|
---|
129 | fi
|
---|
130 | else
|
---|
131 | if [ $LFSVRS = development ] ; then
|
---|
132 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
133 | else
|
---|
134 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
135 | fi
|
---|
136 | echo -ne "done\n"
|
---|
137 | extract_commands
|
---|
138 | fi
|
---|
139 | }
|
---|
140 |
|
---|
141 | extract_commands() {
|
---|
142 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
143 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
144 | exit 1"
|
---|
145 | cd $JHALFSDIR
|
---|
146 |
|
---|
147 | # Start clean
|
---|
148 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
149 | echo -n "Extracting commands... "
|
---|
150 |
|
---|
151 | # Use Maneul's stylesheet to dump the commands in text form from the LFS book.
|
---|
152 | xsltproc -v --nonet --xinclude -o ./commands/ \
|
---|
153 | lfs-$LFSVRS/stylesheets/dump-commands.xsl lfs-$LFSVRS/index.xml \
|
---|
154 | >>$JHALFSDIR/$LOG 2>&1
|
---|
155 |
|
---|
156 | # Move the text files out from the chapter directories, and dump them
|
---|
157 | # all into the 'commands' directory.
|
---|
158 | cd commands
|
---|
159 | find ./* -xtype f -exec mv '{}' . \;
|
---|
160 | find ./* -maxdepth 0 -xtype d -exec rm -rf '{}' \;
|
---|
161 |
|
---|
162 | # Grab the patches and package names.
|
---|
163 | cd $JHALFSDIR
|
---|
164 | for i in patches packages ; do rm -f $i ; done
|
---|
165 | grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
166 | -e '/generic/d' >> packages
|
---|
167 | grep "ENTITY" lfs-$LFSVRS/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
168 |
|
---|
169 | # Done. Moving on...
|
---|
170 | echo -ne "done\n"
|
---|
171 | get_sources
|
---|
172 | }
|
---|
173 |
|
---|
174 | download() {
|
---|
175 | cd $BUILDDIR/sources
|
---|
176 |
|
---|
177 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
178 | # to norms in the URL scheme.
|
---|
179 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
180 |
|
---|
181 | # Find the md5 sum for this package.
|
---|
182 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
183 |
|
---|
184 | if [ ! -f $2 ] ; then
|
---|
185 | case $DL in
|
---|
186 | wget )
|
---|
187 | wget $HTTP/$DIR/$2
|
---|
188 | ;;
|
---|
189 | curl )
|
---|
190 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
191 | ;;
|
---|
192 | * )
|
---|
193 | echo "$DL not supported at this time."
|
---|
194 | ;;
|
---|
195 | esac
|
---|
196 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
197 | case $DL in
|
---|
198 | wget )
|
---|
199 | wget -c $HTTP/$DIR/$2
|
---|
200 | ;;
|
---|
201 | curl )
|
---|
202 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
203 | ;;
|
---|
204 | * )
|
---|
205 | echo "$DL not supported at this time."
|
---|
206 | ;;
|
---|
207 | esac
|
---|
208 | fi
|
---|
209 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
210 | exit 1
|
---|
211 | fi
|
---|
212 | }
|
---|
213 |
|
---|
214 | get_sources() {
|
---|
215 |
|
---|
216 | # This variable is necessary to make sure the `cat $BUILDDIR/packages`
|
---|
217 | # separates each iteration by lines. It is necessary to have the second
|
---|
218 | # ' on the next line.
|
---|
219 | IFS='
|
---|
220 | '
|
---|
221 |
|
---|
222 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
223 | cd $BUILDDIR/sources
|
---|
224 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
225 |
|
---|
226 | download "" MD5SUMS
|
---|
227 |
|
---|
228 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
229 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
230 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
231 |
|
---|
232 | # Someone used some silly entities right next to the valid package entities.
|
---|
233 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
234 |
|
---|
235 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
236 | if [ "$PKG" = "tcl" ] ; then
|
---|
237 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
238 | else
|
---|
239 | FILE="$PKG-$VRS.tar.bz2"
|
---|
240 | fi
|
---|
241 | download $PKG $FILE
|
---|
242 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
243 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
244 | download $PKG $PATCH
|
---|
245 | done
|
---|
246 | done
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | if [ ! -d $JHALFSDIR ] ; then
|
---|
251 | mkdir -p $JHALFSDIR
|
---|
252 | fi
|
---|
253 |
|
---|
254 | >$JHALFSDIR/$LOG
|
---|
255 | cp $0 $JHALFSDIR/
|
---|
256 | get_book
|
---|