3 # author: hackbard@hackdaworld.dyndns.org
5 # this script is used to build the hdw-linux distribution.
15 -chroot) stages="2 3" ; shift 1 ;;
16 -no_src_del) no_src_del="1" ; shift 1 ;;
20 echo " ./scripts/Build-Distro"
21 echo " ./scripts/Build-Distro -chroot"
23 echo " optional: -no_src_del"
29 # minimal check if everything is right.
30 if [ ! -f ./Config ] ; then
31 echo "./Config file not found. are you in correct directory?"
35 # reading subroutines, Config and otimization
37 . ./scripts/Config -stage `echo $stages | cut -b1` # wrong - we dont care!
38 . ./scripts/subroutines
39 . ./scripts/optimization
41 # check system for required tools (what about gcc? ld? ...)
42 [ "$stages" = "0 1" ] && ./scripts/syscheck
45 for stage in $stages; do
47 if [ "$stage" = "0" ] ; then
51 echo_y "welcome to hdw-linux!!"
53 echo_y "let's start ..."
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)"
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 ..."
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
86 echo_w "move /$s1_prefix to /${s1_prefix}_old"
87 mv /$s1_prefix /${s1_prefix}_old
90 ln -sf $hdw_build_dir/$s1_prefix /
93 # build according buildorder
94 cat ./build_order_stage${stage} | grep -v '^#' | \
95 while read x pr dir package; do
97 if [ ! -f $root/var/adm/logs/$stage-$pr-$package ]; then
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 }'`"
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!"
110 [ "$hdw_abort" = "1" ] && exit 1
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 \
122 -root /$root > /dev/null 2>&1
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."
133 # has there been a special exit code?
134 [ "$?" != "0" -a "$hdw_abort" = "1" ] && exit 1
136 # do stage relevant stuff at the end
137 if [ "$stage" != "3" ] ; then
140 echo_w "entering stage $((stage+1)) ..."
142 elif [ "$stage" = "3" ] ; then
145 echo_g "finished last stage ..."
148 if [ "$stage" = "1" ]; then
150 for i in `mount | grep hdw-linux-${hdw_version} | \
151 awk '{ print $3 }'`; do
152 echo_c "unmounting $i"
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"
167 # saving old build_order_stage* files
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/
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*
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
194 # create chroot.sh file! we dont care if it already exists.
195 echo_c "preparing chroot commands ..."
196 cat > $root/chroot.sh <<- EOT
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
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
211 cd /usr/src/hdw-linux
212 . ./scripts/Build-Distro -chroot
214 chmod 700 $root/chroot.sh
216 # restoring build_order_stage* files
218 [ -f $root/build_order_stage${i} ] && \
219 mv $root/build_order_stage${i} $hdw_build_dir/usr/src/hdw-linux
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
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 ..."
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."
246 # remove buildorder files
247 rm -f $root/usr/src/hdw-linux/build_order*
250 echo_w "you should now have build your hdw-linux distro"
251 echo_w "you are on your own now... :)"
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"
257 echo_w "(modify at least /etc/fstab's / entry, set a passwd"
258 echo_w " for root + compile a new kernel if needed)"
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!)"
265 echo "bugreports -> hackbard@hackdaworld.dyndns.org"
267 for i in `mount | grep hdw-linux-${hdw_version} | \
268 awk '{ print $3 }'`; do
269 echo_c "unmounting $i ..."
272 umount $hdw_home_dir/download