#!/bin/bash # # author: hackbard@hackdaworld.dyndns.org # # this script is used to build the hdw-linux distribution. # # define max priority max=18 stages="0 1" no_src_del="" while [ "$1" ] ; do case "$1" in -chroot) stages="2 3" ; shift 1 ;; -no_src_del) no_src_del="1" ; shift 1 ;; *) echo echo "Usage:" echo echo " ./scripts/Build-Distro" echo " ./scripts/Build-Distro -chroot" echo echo " optional: -no_src_del" echo exit 1;; esac done # minimal check if everything is right. if [ ! -f ./Config ] ; then echo "./Config file not found. are you in correct directory?" exit 1 fi # reading subroutines, Config and otimization . ./Config . ./scripts/Config -stage `echo $stages | cut -b1` # wrong - we dont care! . ./scripts/subroutines . ./scripts/optimization # check system for required tools (what about gcc? ld? ...) [ "$stages" = "0 1" ] && ./scripts/syscheck # build the stages for stage in $stages; do if [ "$stage" = "0" ] ; then echo echo echo -e "\a" echo_y "welcome to hdw-linux!!" echo echo_y "let's start ..." echo sleep 3 fi # calculating buildorder if [ -f ./build_order_stage${stage} ] ; then echo_w "found old buildorder, i am using it!" echo_w "(remove ./build_order_stage${stage}, to calculate it)" echo else echo_w "calculating buildorder for stage $stage ..." create_buildorder $stage $max > \ ./build_order_stage${stage} if [ ! -f ./build_order_stage${stage} ] ; then echo_r "can't create buildorder! aborting ..." exit 1 fi fi # do stage relevant stuff at the beginning. if [ "$stage" = "0" ]; then # create the log directory [ ! -d ${hdw_build_dir}/var/adm/logs ] && \ mkdir -p ${hdw_build_dir}/var/adm/logs [ ! -d ${hdw_build_dir}/var/adm/flists ] && \ mkdir -p ${hdw_build_dir}/var/adm/flists [ ! -d ${hdw_build_dir}/var/adm/deps ] && \ mkdir -p ${hdw_build_dir}/var/adm/deps/{run,build} # symlinking the stage 0/1 prefix to hostsystem root if [ -d /$s1_prefix ]; then if [ ! -L /$s1_prefix ]; then echo_r "WARNING: " echo_w "move /$s1_prefix to /${s1_prefix}_old" mv /$s1_prefix /${s1_prefix}_old fi fi ln -sf $hdw_build_dir/$s1_prefix / fi # build according buildorder cat ./build_order_stage${stage} | grep -v '^#' | \ while read x pr dir package; do # already build? if [ ! -f $root/var/adm/logs/$x-$pr-$package ]; then echo echo "building package `pkg_c $package`, stage $stage." echo_w "log -> $root/var/adm/logs/$x-$pr-$package" echo_y "started, `date | awk '{ print $4 }'`" b_append="" [ ! -z "$no_src_del" ] && b_append="-no_src_del" ./scripts/Build -stage $x -package $package \ -priority $pr -dir $dir $b_append > \ $root/var/adm/logs/$x-$pr-$package.out 2>&1 if [ ! "$?" = "0" ]; then echo_r "failed to build package $package!" echo_r "aborted." [ "$hdw_abort" = "1" ] && exit 1 else mv $root/var/adm/logs/$x-$pr-$package.out \ $root/var/adm/logs/$x-$pr-$package echo_g "done, `date | awk '{ print $4 }'`" # make binary tar package if [ "$hdw_make_package" = "1" -a \ "$hdw_status" -ge "2" ] ; then echo -n "creating binary package ..." if [ -d binaries/{$hdw_arch}-${hdw_arch_opt}/$package ] ; then echo -n " (deleting old first)" rm -rf binaries/{$hdw_arch}-${hdw_arch_opt}/$package fi ./scripts/Create-Binary \ -package $package-$pr \ -tar-name $package \ -root /$root > /dev/null 2>&1 echo_g " done" fi fi else echo echo_w "$package already build in stage $stage, skipped" echo_w "remove $root/var/adm/logs/$x-$pr-$package" echo_w "if you want to rebuild it." fi done # has there been a special exit code? [ "$?" != "0" -a "$hdw_abort" = "1" ] && exit 1 # do stage relevant stuff at the end if [ "$stage" != "3" ] ; then echo echo echo_w "entering stage $((stage+1)) ..." echo elif [ "$stage" = "3" ] ; then echo echo echo_g "finished last stage ..." echo fi if [ "$stage" = "1" ]; then # cleanup for i in `mount | grep hdw-linux-${hdw_version} | \ awk '{ print $3 }'`; do echo_c "unmounting $i" umount $i done umount $hdw_build_dir/dev/pts > /dev/null 2>&1 [ "$?" = "0" ] && echo_c "unmounted devpts" umount $hdw_build_dir/dev/shm > /dev/null 2>&1 [ "$?" = "0" ] && echo_c "unmounted tmpfs" umount $hdw_build_dir/dev > /dev/null 2>&1 [ "$?" = "0" ] && echo_c "unmounted ramfs" rm -rf $hdw_build_dir/dev/* umount $hdw_build_dir/proc > /dev/null 2>&1 [ "$?" = "0" ] && echo_c "unmounted procfs" umount $hdw_build_dir/sys > /dev/null 2>&1 [ "$?" = "0" ] && echo_c "unmounted sysfs" # saving old build_order_stage* files for i in 2 3; do [ -f $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} ] && \ mv $hdw_build_dir/usr/src/hdw-linux/build_order_stage${i} $root/ done # deleting sources to make sure they are the latest ... if [ -d $root/usr/src/hdw-linux-${hdw_version} ] ; then echo_c "deleting old hdw-linux sources ..." rm -r $root/usr/src/hdw-linux* fi # well, following must be true :) if [ ! -d $root/usr/src/hdw-linux-${hdw_version} ] ; then echo_w "preparing hdw-linux sources ..." # copying & mounting sources mkdir -p $root/usr/src/hdw-linux-${hdw_version} ln -s ./hdw-linux-${hdw_version} \ $root/usr/src/hdw-linux cp -r $hdw_home_dir/{doc,misc} $root/usr/src/hdw-linux cp -r $hdw_home_dir/{packages,scripts,targets} \ $root/usr/src/hdw-linux cp $hdw_home_dir/Config \ $root/usr/src/hdw-linux mkdir -p $root/usr/src/hdw-linux/download [ -d $hdw_home_dir/binaries ] && \ mkdir -p $root/usr/src/hdw-linux/binaries fi # create chroot.sh file! we dont care if it already exists. echo_c "preparing chroot commands ..." cat > $root/chroot.sh <<- EOT # PATH export PATH="\$PATH:/${s1_prefix}/bin:/${s1_prefix}/sbin" # create essential device nodes mknod -m 600 /dev/console c 5 1 mknod -m 666 /dev/null c 1 3 # populate dev directory udevstart # add essential symlinks ln -s /proc/self/fd /dev/fd ln -s /proc/self/fd/0 /dev/stdin ln -s /proc/self/fd/1 /dev/stdout ln -s /proc/self/fd/2 /dev/stderr ln -s /proc/kcore /dev/core # build stages 2 & 3 cd /usr/src/hdw-linux . ./scripts/Build-Distro -chroot EOT chmod 700 $root/chroot.sh # restoring build_order_stage* files for i in 2 3; do [ -f $root/build_order_stage${i} ] && \ mv $root/build_order_stage${i} $hdw_build_dir/usr/src/hdw-linux done # finally mount stuff, do the chroot and build echo_c "mounting packages + sysfs & proc filesystem ..." mount --bind $hdw_home_dir/download \ $root/usr/src/hdw-linux-${hdw_version}/download [ -d $hdw_home_dir/binaries ] && \ mount --bind $hdw_home_dir/binaries \ $root/usr/src/hdw-linux-${hdw_version}/binaries # obsolete -- udev # mount -t devfs none $root/dev mount -t proc proc $root/proc mount -t sysfs sysfs $root/sys mount -t ramfs ramfs $root/dev mkdir -p $root/dev/{pts,shm} mount -t tmpfs tmpfs $root/dev/shm mount -t devpts devpts $root/dev/pts echo_w "entering chroot and start building now ..." echo chroot $hdw_build_dir /${s1_prefix}/bin/env PS1='\u@\w\$ ' \ PATH="/bin:/usr/bin:/sbin:/usr/sbin" HOME=/root \ /${s1_prefix}/bin/bash --login +h /chroot.sh if [ ! "$?" = "0" ]; then echo_r "something failed in the chroot, aborting." exit 1 fi # remove buildorder files rm -f $root/chroot.sh # last message echo echo_w "you should now have build your hdw-linux distro" echo_w "you are on your own now... :)" echo echo_w "you should chroot to the target directory and make " echo_w "further adaptions:" echo_w "chroot $hdw_build_dir /bin/bash --login" echo echo_w "(modify at least /etc/fstab's / entry, set a passwd" echo_w " for root + compile a new kernel if needed)" echo echo "if your hdw-build directory was not on a seperated" echo "partition, use cp -a to copy it over. copy the created" echo "kernel to your existing /boot partitition and tell your" echo "bootloader (root device append!)" echo echo "bugreports -> hackbard@hackdaworld.dyndns.org" echo for i in `mount | grep hdw-linux-${hdw_version} | \ awk '{ print $3 }'`; do echo_c "unmounting $i ..." umount $i done umount $hdw_home_dir/download exit 0 fi done # end