]> hackdaworld.org Git - hdw-linux/hdw-linux.git/blob - scripts/Build-Distro
bugfixed hdw-get
[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                                         ./scripts/Create-Binary \
120                                                 -package $package-$pr \
121                                                 -tar-name $package \
122                                                 -root /$root > /dev/null 2>&1
123                                         echo_g " done"
124                                 fi
125                         fi
126                 else
127                         echo
128                         echo_w "$package already build in stage $stage, skipped"
129                         echo_w "remove $root/var/adm/logs/$stage-$pr-$package"
130                         echo_w "if you want to rebuild it."
131                 fi
132         done
133         # has there been a special exit code?
134         [ "$?" != "0" -a "$hdw_abort" = "1" ] && exit 1
135
136         # do stage relevant stuff at the end
137         if [ "$stage" != "3" ] ; then
138         echo
139         echo
140         echo_w "entering stage $((stage+1)) ..."
141         echo
142         elif [ "$stage" = "3" ] ; then
143         echo
144         echo
145         echo_g "finished last stage ..."
146         echo
147         fi
148         if [ "$stage" = "1" ]; then
149                 # cleanup
150                 for i in `mount | grep hdw-linux-${hdw_version} | \
151                                 awk '{ print $3 }'`; do
152                         echo_c "unmounting $i"
153                         umount $i
154                 done
155                 umount $hdw_build_dir/dev/pts > /dev/null 2>&1
156                 [ "$?" = "0" ] && echo_c "unmounted devpts"
157                 umount $hdw_build_dir/dev/shm > /dev/null 2>&1
158                 [ "$?" = "0" ] && echo_c "unmounted tmpfs"
159                 umount $hdw_build_dir/dev > /dev/null 2>&1
160                 [ "$?" = "0" ] && echo_c "unmounted ramfs"
161                 rm -rf $hdw_build_dir/dev/*
162                 umount $hdw_build_dir/proc > /dev/null 2>&1
163                 [ "$?" = "0" ] && echo_c "unmounted procfs"
164                 umount $hdw_build_dir/sys > /dev/null 2>&1
165                 [ "$?" = "0" ] && echo_c "unmounted sysfs"
166                 
167                 # saving old build_order_stage* files
168                 for i in 2 3; do
169         [ -f $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} ] && \
170         mv $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} $root/
171                 done
172
173                 # deleting sources to make sure they are the latest ...
174                 if [ -d $root/usr/src/hdw-linux-${hdw_version} ] ; then
175                         echo_c "deleting old hdw-linux sources ..."
176                         rm -r $root/usr/src/hdw-linux*
177                 fi
178                 # well, following must be true :)
179                 if [ ! -d $root/usr/src/hdw-linux-${hdw_version} ] ; then
180                         echo_w "preparing hdw-linux sources ..."
181                         # copying & mounting sources
182                         mkdir -p $root/usr/src/hdw-linux-${hdw_version}
183                         ln -s ./hdw-linux-${hdw_version} \
184                                 $root/usr/src/hdw-linux
185                         cp -r $hdw_home_dir/{doc,misc} $root/usr/src/hdw-linux
186                         cp -r $hdw_home_dir/{packages,scripts,targets} \
187                                 $root/usr/src/hdw-linux
188                         cp $hdw_home_dir/Config \
189                                 $root/usr/src/hdw-linux
190                         mkdir -p $root/usr/src/hdw-linux/download
191                         [ -d $hdw_home_dir/binaries ] && \
192                                 mkdir -p $root/usr/src/hdw-linux/binaries
193                 fi
194                 # create chroot.sh file! we dont care if it already exists.
195                 echo_c "preparing chroot commands ..."
196                 cat > $root/chroot.sh <<- EOT
197 # PATH                          
198 export PATH="\$PATH:/${s1_prefix}/bin:/${s1_prefix}/sbin"
199 # create essential device nodes
200 mknod -m 600 /dev/console c 5 1
201 mknod -m 666 /dev/null c 1 3
202 # populate dev directory
203 udevstart
204 # add essential symlinks
205 ln -s /proc/self/fd /dev/fd
206 ln -s /proc/self/fd/0 /dev/stdin
207 ln -s /proc/self/fd/1 /dev/stdout
208 ln -s /proc/self/fd/2 /dev/stderr
209 ln -s /proc/kcore /dev/core
210 # build stages 2 & 3
211 cd /usr/src/hdw-linux
212 . ./scripts/Build-Distro -chroot
213 EOT
214                 chmod 700 $root/chroot.sh
215                 
216                 # restoring build_order_stage* files
217                 for i in 2 3; do
218                 [ -f $root/build_order_stage${i} ] && \
219                 mv $root/build_order_stage${i} $hdw_build_dir/usr/src/hdw-linux
220                 done
221
222                 # finally mount stuff, do the chroot and build
223                 echo_c "mounting packages + sysfs & proc filesystem ..."
224                 mount --bind $hdw_home_dir/download \
225                         $root/usr/src/hdw-linux-${hdw_version}/download
226                 [ -d $hdw_home_dir/binaries ] && \
227                         mount --bind $hdw_home_dir/binaries \
228                         $root/usr/src/hdw-linux-${hdw_version}/binaries
229                 # obsolete -- udev
230                 # mount -t devfs none $root/dev
231                 mount -t proc proc $root/proc
232                 mount -t sysfs sysfs $root/sys
233                 mount -t ramfs ramfs $root/dev
234                 mkdir -p $root/dev/{pts,shm}
235                 mount -t tmpfs tmpfs $root/dev/shm
236                 mount -t devpts devpts $root/dev/pts
237                 echo_w "entering chroot and start building now ..."
238                 echo
239                 chroot $hdw_build_dir /${s1_prefix}/bin/env PS1='\u@\w\$ ' \
240                         PATH="/bin:/usr/bin:/sbin:/usr/sbin" HOME=/root \
241                         /${s1_prefix}/bin/bash --login +h /chroot.sh
242                 if [ ! "$?" = "0" ]; then
243                         echo_r "something failed in the chroot, aborting."
244                         exit 1
245                 fi
246                 # remove buildorder files
247                 rm -f $root/usr/src/hdw-linux/build_order*
248                 # last message
249                 echo 
250                 echo_w "you should now have build your hdw-linux distro"
251                 echo_w "you are on your own now... :)"
252                 echo
253                 echo_w "you should chroot to the target directory and make "
254                 echo_w "further adaptions:"
255                 echo_w "chroot $hdw_build_dir /bin/bash --login"
256                 echo
257                 echo_w "(modify at least /etc/fstab's / entry, set a passwd"
258                 echo_w " for root + compile a new kernel if needed)"
259                 echo 
260                 echo "if your hdw-build directory was not on a seperated"
261                 echo "partition, use cp -a to copy it over. copy the created"
262                 echo "kernel to your existing /boot partitition and tell your"
263                 echo "bootloader (root device append!)"
264                 echo
265                 echo "bugreports -> hackbard@hackdaworld.dyndns.org"
266                 echo
267                 for i in `mount | grep hdw-linux-${hdw_version} | \
268                                                 awk '{ print $3 }'`; do
269                         echo_c "unmounting $i ..."
270                         umount $i
271                 done
272                 umount $hdw_home_dir/download
273                 exit 0
274         fi
275 done
276
277 # end