#!/bin/bash

set +o posix

# This is to test kernel builds using distcc but without running through
# the Kernel SlackBuild process.
# It's useful to make quick chages to the kernel config and build a new zImage
# to test before committing to rebuilding the Slackware packages.


export DISTCC_HOSTS="prisere/5"
ping -c1 kitt > /dev/null 2>&1 && export DISTCC_HOSTS="$DISTCC_HOSTS kitt/9"
ping -c1 turrican > /dev/null 2>&1 && export DISTCC_HOSTS="$DISTCC_HOSTS turrican/3"
export NUMJOBS=$[$(sed 's?[^0-9]*/?+?g' <<<$DISTCC_HOSTS)]
export NUMJOBS="-j$NUMJOBS"

tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15

dialog \
   --clear \
   --no-tags \
   --extra-label "Choice" \
   --title " Quick out-of-package-tree Kernel build using distcc " "$@" \
   --menu "\nPlease select which Kernel build option you'd like.\n" 12 60 70 \
    "make $NUMJOBS zImage dtbs" "Build zImage & DTBs" \
    "make $NUMJOBS zImage dtbs modules" "Build zImage, modules & DTBs" \
    "make $NUMJOBS zImage" "Build zImage" \
    "make $NUMJOBS uImage" "Build uImage" \
    "make $NUMJOBS modules" "Build modules" \
    "make modules_install INSTALL_MOD_PATH=/tmp/moose/kernel-modulez" "Install Kernel modules to a temp dir" \
    "make headers_install INSTALL_HDR_PATH=/tmp/moose/kernel-headers" "Install Kernel headers to a temp dir" 2> $tempfile

echo "*********************************"
echo "distcc hosts: $DISTCC_HOSTS"
echo "Number of jobs: $NUMJOBS"
echo "*********************************"
export PATH=/tmp/DISTCC:$PATH

cat << EOF
Executing command:
$( cat $tempfile )

EOF

cat  $tempfile | bash



