#! /bin/sh # # author: hackbard@hackdaworld.dyndns.org # # this script defines functions used by the other scripts # echo_r() { echo -e "\e[01;31m${1}\e[0m" # Red } echo_g() { echo -e "\e[01;32m${1}\e[0m" # Green } echo_y() { echo -e "\e[01;33m${1}\e[0m" # Yellow } echo_c() { echo -e "\e[01;36m${1}\e[0m" # Cyan } echo_w() { echo -e "\e[01;37m${1}\e[0m" # White } pkg_c() { echo -en "\e[01;36m${1}\e[0m" } warn_beep() { (( n = 1 )) while (( n <= 5 )) do echo -en "\a" sleep 1 (( n += 1 )) done } abort_when_package_build_failed() { return="$1" last="$2" if [ "$return" != "0" -a "$hdw_abort" = "1" ]; then echo "failed building package $package!" echo "failed executing $last" echo "abort." warn_beep echo exit 1 fi } create_init() { echo "creating init ..." # default variables run="`basename $1 | awk -F. '{ print $1 }'`" bin=$package ; params="" ; depends="" ; exec="" path=$prefix/sbin ; sec_append="exit 0" sync_respawn="" ; use_pfh=0 ((s_value=50)) # reading variables . $1 # process ((s2_value = 100 - s_value)) if [ ! -d $root/etc/minit ] ; then echo "assuming sysvinit as init system!" cat > $root/etc/init.d/$run << EOF #!/bin/sh # # hdw - linux $root/etc/init.d/$run # # remove this for automatic startup $sec_append [ ! -f $path/$bin ] && exit 0 case "\$1" in start) echo "starting $run ..." $path/$bin $params ;; stop) echo "stopping $run ..." killall -15 $path/$bin ;; restart) echo "restarting $run ..." killall -1 $path/$bin ;; *) echo "usage: \$0 [start|stop|restart]" exit 1 ;; esac exit 0 EOF # permissions and links chmod 750 $root/etc/init.d/$run ln -sf ../$run $root/etc/init.d/rc2.d/S${s_value}${run} ln -sf ../$run $root/etc/init.d/rc2.d/K${s2_value}${run} else echo "assuming minit as init system!" mkdir -p $root/etc/minit/$run if [ "$use_pfh" = "1" ] ; then ln -sf $root/sbin/pidfilehack $root/etc/minit/$run/run elif [ ! -z "$exec" ] ; then rm -f $root/etc/minit/$run/run echo "exec $exec" > $root/etc/minit/$run/run else ln -sf $path/$bin $root/etc/minit/$run/run fi [ ! -z "$sync_respawn" ] && \ touch $root/etc/minit/$run/$snc_respawn if [ ! -z "$params" ]; then rm -f $root/etc/minit/$run/params for i in $params; do echo "$i" >> $root/etc/minit/$run/params done fi if [ ! -z "$depends" ]; then rm -f $root/etc/minit/$run/depends for i in $depends; do echo "$i" >> $root/etc/minit/$run/depends done fi fi } detect_file_ending() { file="$1" if [ "`echo $file | awk -F'tar\\\.' '{ print $2 }'`" = "bz2" ] ; then echo "tar.bz2" elif [ ! -z "`echo $file | grep '.tbz2'`" ] ; then echo "tbz2" fi if [ "`echo $file | awk -F'tar\\\.' '{ print $2 }'`" = "gz" ] ; then echo "tar.gz" elif [ ! -z "`echo $file | grep '.tgz'`" ] ; then echo "tgz" elif [ ! -z "`echo $file | grep 'tar.Z'`" ] ; then echo "tar.Z" fi } create_setup_scripts() { destfile="`echo $1 | awk -F/ '{ print $NF }' | sed 's/\.setup//'`.sh" cat > $root/etc/setup.d/$destfile << EOF #!/bin/sh # # hdw - linux $root/etc/setup.d/$destfile # EOF if [ -z "`grep setup_block $1`" ] ; then cat >> $root/etc/setup.d/$destfile << EOF setup_block() { echo "setup not supported" } EOF fi if [ -z "`grep uninstall_block $1`" ] ; then cat >> $root/etc/setup.d/$destfile << EOF uninstall_block() { echo "uninstall not supported" } EOF fi cat $1 >> $root/etc/setup.d/$destfile cat >> $root/etc/setup.d/$destfile << EOF usage() { echo "usage: \$0 [setup|uninstall]" exit 1 } [ -z "\$1" ] && usage while [ "\$1" ] ; do case "\$1" in setup) setup_block ; shift ;; uninstall) uninstall_block ; shift ;; *) usage ; exit 1 ;; esac done EOF chmod 750 $root/etc/setup.d/$destfile } output_if_valid() { local stage local priority local package local dir package=$1 stage=$2 priority=$3 dir="`echo $package | awk -F/ '{ print $3 }'`" for match in `grep '^# \[S\]' $package | \ awk '{ for(i=3;i<=NF;i++) print $i }'`; do if [ "$stage-$priority" = "$match" ] ; then echo -en "$stage \t $priority \t\t $dir " echo -e "`basename $package`" fi done } create_buildorder() { local stage stages=$1 max_priority=$2 # categories categories=`grep '^# \[C\]' ./targets/$hdw_target/include | \ awk '{ print $3 }'` categories="$categories $hdw_arch" # add single packages to categories singlepackages=`grep '^# \[P\]' ./targets/$hdw_target/include | \ awk '{ print $3 }'` [ ! -z "$singlepackages" ] && categories="$categories $singlepackages" # packages to remove delpackages=`grep '^# \[R\]' ./targets/$hdw_target/include | \ awk '{ print $3 }'` # use dietlibc? if [ "$hdw_use_dietlibc" = "1" ] ; then [ -z "`echo $categories | grep diet`"] && \ singlepackages="$singlepackages diet/dietlibc" delpackages="$delpackages base/glibc" fi echo -e "#stage \t #priority \t #category package" for stage in $stages; do (( counter = -1 )) while (( counter <= max_priority )); do ((counter += 1)) for dir in $categories; do for package in ./packages/$dir/[!C]*; do pkg=`basename $package` if [ -d $package -a -f $package/$pkg ] ; then [ -z "`echo $delpackages | grep $dir/$pkg`" ] && \ output_if_valid $package/`basename $package` \ $stage $counter else foo=`basename $dir` [ -f ./packages/$dir/$foo ] && \ output_if_valid ./packages/$dir/$foo \ $stage $counter fi done done done done }