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 if [ -d binaries/*/$package ] ; then
120 echo -n " (deleting old first)"
121 rm -rf binaries/*/$package
123 ./scripts/Create-Binary \
124 -package $package-$pr \
126 -root /$root > /dev/null 2>&1
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."
137 # has there been a special exit code?
138 [ "$?" != "0" -a "$hdw_abort" = "1" ] && exit 1
140 # do stage relevant stuff at the end
141 if [ "$stage" != "3" ] ; then
144 echo_w "entering stage $((stage+1)) ..."
146 elif [ "$stage" = "3" ] ; then
149 echo_g "finished last stage ..."
152 if [ "$stage" = "1" ]; then
154 for i in `mount | grep hdw-linux-${hdw_version} | \
155 awk '{ print $3 }'`; do
156 echo_c "unmounting $i"
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"
171 # saving old build_order_stage* files
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/
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*
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
198 # create chroot.sh file! we dont care if it already exists.
199 echo_c "preparing chroot commands ..."
200 cat > $root/chroot.sh <<- EOT
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
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
215 cd /usr/src/hdw-linux
216 . ./scripts/Build-Distro -chroot
218 chmod 700 $root/chroot.sh
220 # restoring build_order_stage* files
222 [ -f $root/build_order_stage${i} ] && \
223 mv $root/build_order_stage${i} $hdw_build_dir/usr/src/hdw-linux
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
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 ..."
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."
250 # remove buildorder files
251 rm -f $root/usr/src/hdw-linux/build_order*
254 echo_w "you should now have build your hdw-linux distro"
255 echo_w "you are on your own now... :)"
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"
261 echo_w "(modify at least /etc/fstab's / entry, set a passwd"
262 echo_w " for root + compile a new kernel if needed)"
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!)"
269 echo "bugreports -> hackbard@hackdaworld.dyndns.org"
271 for i in `mount | grep hdw-linux-${hdw_version} | \
272 awk '{ print $3 }'`; do
273 echo_c "unmounting $i ..."
276 umount $hdw_home_dir/download