]> hackdaworld.org Git - hdw-linux/hdw-linux.git/blob - scripts/Build-Distro
added xfig package
[hdw-linux/hdw-linux.git] / scripts / Build-Distro
1 #!/bin/bash
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # this script is used to build the hdw-linux distribution.
6
7
8 # define max priority
9 max=20
10 stages="0 1"
11 no_src_del=""
12
13 while [ "$1" ] ; do
14         case "$1" in
15                 -chroot)        stages="2 3"    ; shift 1 ;;
16                 -no_src_del)    no_src_del="1"  ; shift 1 ;;
17                 *)              echo 
18                                 echo "Usage:"
19                                 echo
20                                 echo " ./scripts/Build-Distro"
21                                 echo " ./scripts/Build-Distro -chroot"
22                                 echo 
23                                 echo " optional: -no_src_del"
24                                 echo 
25                                 exit 1;;
26         esac
27 done
28
29 # minimal check if everything is right.
30 if [ ! -f ./Config ] ; then
31         echo "./Config file not found. are you in correct directory?"
32         exit 1
33 fi
34
35 # reading subroutines, Config and otimization
36 . ./Config
37 . ./scripts/Config -stage `echo $stages | cut -b1` # wrong - we dont care!
38 . ./scripts/subroutines
39 . ./scripts/optimization
40
41 # check system for required tools (what about gcc? ld? ...)
42 [ "$stages" = "0 1" ] && ./scripts/syscheck
43
44 # build the stages
45 for stage in $stages; do
46
47         if [ "$stage" = "0" ] ; then
48                 echo
49                 echo
50                 echo -e "\a"
51                 echo_y "welcome to hdw-linux!!"
52                 echo
53                 echo_y "let's start ..."
54                 echo
55                 sleep 3
56         fi
57         
58         # calculating buildorder
59         if [ -f ./build_order_stage${stage} ] ; then
60                 echo_w "found old buildorder, i am using it!"
61                 echo_w "(remove ./build_order_stage${stage}, to calculate it)"
62                 echo
63         else
64                 echo_w "calculating buildorder for stage $stage ..."
65                 create_buildorder $stage $max > \
66                         ./build_order_stage${stage}
67                 if [ ! -f ./build_order_stage${stage} ] ; then
68                         echo_r "can't create buildorder! aborting ..."
69                         exit 1
70                 fi
71         fi
72
73         # do stage relevant stuff at the beginning.
74         if [ "$stage" = "0" ]; then
75                 # create the log directory
76                 [ ! -d ${hdw_build_dir}/var/adm/logs ] && \
77                         mkdir -p ${hdw_build_dir}/var/adm/logs
78                 [ ! -d ${hdw_build_dir}/var/adm/flists ] && \
79                         mkdir -p ${hdw_build_dir}/var/adm/flists
80                 [ ! -d ${hdw_build_dir}/var/adm/deps ] && \
81                         mkdir -p ${hdw_build_dir}/var/adm/deps/{run,build}
82                 # symlinking the stage 0/1 prefix to hostsystem root
83                 if [ -d /$s1_prefix ]; then
84                         if [ ! -L /$s1_prefix ]; then
85                                 echo_r "WARNING: "
86                                 echo_w "move /$s1_prefix to /${s1_prefix}_old"
87                                 mv /$s1_prefix /${s1_prefix}_old
88                         fi
89                 fi
90                 ln -sf $hdw_build_dir/$s1_prefix /
91         fi
92
93         # build according buildorder
94         cat ./build_order_stage${stage} | grep -v '^#' | \
95                         while read x pr dir package; do
96                 # already build?
97                 if [ ! -f $root/var/adm/logs/$stage-$pr-$package ]; then
98                         echo
99                         echo "building package `pkg_c $package`, stage $stage."
100                         echo_w "log -> $root/var/adm/logs/$stage-$pr-$package"
101                         echo_y "started, `date | awk '{ print $4 }'`"
102                         b_append=""
103                         [ ! -z "$no_src_del" ] && b_append="-no_src_del"
104                         ./scripts/Build -stage $stage -package $package \
105                                         -priority $pr -dir $dir $b_append > \
106                                 $root/var/adm/logs/$stage-$pr-$package.out 2>&1
107                         if [ ! "$?" = "0" ]; then
108                                 echo_r "failed to build package $package!"
109                                 echo_r "aborted."
110                                 [ "$hdw_abort" = "1" ] && exit 1
111                         else
112                                 mv $root/var/adm/logs/$stage-$pr-$package.out \
113                                 $root/var/adm/logs/$stage-$pr-$package
114                                 echo_g "done, `date | awk '{ print $4 }'`"
115                                 # make binary tar package
116                                 if [ "$hdw_make_package" = "1" -a \
117                                      "$hdw_status" -ge "2" ] ; then
118                                         echo -n "creating binary package ..."
119                                         if [ -d binaries/*/$package ] ; then
120                                                 echo -n " (deleting old first)"
121                                                 rm -rf binaries/*/$package
122                                         fi
123                                         ./scripts/Create-Binary \
124                                                 -package $package-$pr \
125                                                 -tar-name $package \
126                                                 -root /$root > /dev/null 2>&1
127                                         echo_g " done"
128                                 fi
129                         fi
130                 else
131                         echo
132                         echo_w "$package already build in stage $stage, skipped"
133                         echo_w "remove $root/var/adm/logs/$stage-$pr-$package"
134                         echo_w "if you want to rebuild it."
135                 fi
136         done
137         # has there been a special exit code?
138         [ "$?" != "0" -a "$hdw_abort" = "1" ] && exit 1
139
140         # do stage relevant stuff at the end
141         if [ "$stage" != "3" ] ; then
142         echo
143         echo
144         echo_w "entering stage $((stage+1)) ..."
145         echo
146         elif [ "$stage" = "3" ] ; then
147         echo
148         echo
149         echo_g "finished last stage ..."
150         echo
151         fi
152         if [ "$stage" = "1" ]; then
153                 # cleanup
154                 for i in `mount | grep hdw-linux-${hdw_version} | \
155                                 awk '{ print $3 }'`; do
156                         echo_c "unmounting $i"
157                         umount $i
158                 done
159                 umount $hdw_build_dir/dev/pts > /dev/null 2>&1
160                 [ "$?" = "0" ] && echo_c "unmounted devpts"
161                 umount $hdw_build_dir/dev/shm > /dev/null 2>&1
162                 [ "$?" = "0" ] && echo_c "unmounted tmpfs"
163                 umount $hdw_build_dir/dev > /dev/null 2>&1
164                 [ "$?" = "0" ] && echo_c "unmounted ramfs"
165                 rm -rf $hdw_build_dir/dev/*
166                 umount $hdw_build_dir/proc > /dev/null 2>&1
167                 [ "$?" = "0" ] && echo_c "unmounted procfs"
168                 umount $hdw_build_dir/sys > /dev/null 2>&1
169                 [ "$?" = "0" ] && echo_c "unmounted sysfs"
170                 
171                 # saving old build_order_stage* files
172                 for i in 2 3; do
173         [ -f $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} ] && \
174         mv $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} $root/
175                 done
176
177                 # deleting sources to make sure they are the latest ...
178                 if [ -d $root/usr/src/hdw-linux-${hdw_version} ] ; then
179                         echo_c "deleting old hdw-linux sources ..."
180                         rm -r $root/usr/src/hdw-linux*
181                 fi
182                 # well, following must be true :)
183                 if [ ! -d $root/usr/src/hdw-linux-${hdw_version} ] ; then
184                         echo_w "preparing hdw-linux sources ..."
185                         # copying & mounting sources
186                         mkdir -p $root/usr/src/hdw-linux-${hdw_version}
187                         ln -s ./hdw-linux-${hdw_version} \
188                                 $root/usr/src/hdw-linux
189                         cp -r $hdw_home_dir/{doc,misc} $root/usr/src/hdw-linux
190                         cp -r $hdw_home_dir/{packages,scripts,targets} \
191                                 $root/usr/src/hdw-linux
192                         cp $hdw_home_dir/Config \
193                                 $root/usr/src/hdw-linux
194                         mkdir -p $root/usr/src/hdw-linux/download
195                         [ -d $hdw_home_dir/binaries ] && \
196                                 mkdir -p $root/usr/src/hdw-linux/binaries
197                 fi
198                 # create chroot.sh file! we dont care if it already exists.
199                 echo_c "preparing chroot commands ..."
200                 cat > $root/chroot.sh <<- EOT
201 # PATH                          
202 export PATH="\$PATH:/${s1_prefix}/bin:/${s1_prefix}/sbin"
203 # create essential device nodes
204 mknod -m 600 /dev/console c 5 1
205 mknod -m 666 /dev/null c 1 3
206 # populate dev directory
207 udevstart
208 # add essential symlinks
209 ln -s /proc/self/fd /dev/fd
210 ln -s /proc/self/fd/0 /dev/stdin
211 ln -s /proc/self/fd/1 /dev/stdout
212 ln -s /proc/self/fd/2 /dev/stderr
213 ln -s /proc/kcore /dev/core
214 # build stages 2 & 3
215 cd /usr/src/hdw-linux
216 . ./scripts/Build-Distro -chroot
217 EOT
218                 chmod 700 $root/chroot.sh
219                 
220                 # restoring build_order_stage* files
221                 for i in 2 3; do
222                 [ -f $root/build_order_stage${i} ] && \
223                 mv $root/build_order_stage${i} $hdw_build_dir/usr/src/hdw-linux
224                 done
225
226                 # finally mount stuff, do the chroot and build
227                 echo_c "mounting packages + sysfs & proc filesystem ..."
228                 mount --bind $hdw_home_dir/download \
229                         $root/usr/src/hdw-linux-${hdw_version}/download
230                 [ -d $hdw_home_dir/binaries ] && \
231                         mount --bind $hdw_home_dir/binaries \
232                         $root/usr/src/hdw-linux-${hdw_version}/binaries
233                 # obsolete -- udev
234                 # mount -t devfs none $root/dev
235                 mount -t proc proc $root/proc
236                 mount -t sysfs sysfs $root/sys
237                 mount -t ramfs ramfs $root/dev
238                 mkdir -p $root/dev/{pts,shm}
239                 mount -t tmpfs tmpfs $root/dev/shm
240                 mount -t devpts devpts $root/dev/pts
241                 echo_w "entering chroot and start building now ..."
242                 echo
243                 chroot $hdw_build_dir /${s1_prefix}/bin/env PS1='\u@\w\$ ' \
244                         PATH="/bin:/usr/bin:/sbin:/usr/sbin" HOME=/root \
245                         /${s1_prefix}/bin/bash --login +h /chroot.sh
246                 if [ ! "$?" = "0" ]; then
247                         echo_r "something failed in the chroot, aborting."
248                         exit 1
249                 fi
250                 # remove buildorder files
251                 rm -f $root/usr/src/hdw-linux/build_order*
252                 # last message
253                 echo 
254                 echo_w "you should now have build your hdw-linux distro"
255                 echo_w "you are on your own now... :)"
256                 echo
257                 echo_w "you should chroot to the target directory and make "
258                 echo_w "further adaptions:"
259                 echo_w "chroot $hdw_build_dir /bin/bash --login"
260                 echo
261                 echo_w "(modify at least /etc/fstab's / entry, set a passwd"
262                 echo_w " for root + compile a new kernel if needed)"
263                 echo 
264                 echo "if your hdw-build directory was not on a seperated"
265                 echo "partition, use cp -a to copy it over. copy the created"
266                 echo "kernel to your existing /boot partitition and tell your"
267                 echo "bootloader (root device append!)"
268                 echo
269                 echo "bugreports -> hackbard@hackdaworld.dyndns.org"
270                 echo
271                 for i in `mount | grep hdw-linux-${hdw_version} | \
272                                                 awk '{ print $3 }'`; do
273                         echo_c "unmounting $i ..."
274                         umount $i
275                 done
276                 umount $hdw_home_dir/download
277                 exit 0
278         fi
279 done
280
281 # end