#!/bin/sh ## Author: Parv, parv UNDERSCORE AT yahoo DOT com ## Date: Jan 26, 2005 ## ## License: Free to use as you please w/ proper credit given. ## ## Name: biwk ## ## Purpose: This script builds world, builds & install kernels. ## it keeps logs of the three activities, showing only start and end ## of an activity. ## ## Usage: Run this script, biwk, w/o any arguments ## # - If the script started on jan. 25, 2002 3:49:25am EDT, log files will have # names like, where time is in UTC, ... # # Buildworld: bw.2002-0125-0849.25 # Buildkernel: bk.2002-0125-0849.25 # Installkernel: ik.2002-0125-0849.25 # Installworld: iw.2002-0125-0849.25 # # - Don't forget to change the kernel config below, instead of GENERIC # Change as appropriate SRC_dir="/usr/src" # Used to clean it & make kernel OBJ_dir="/usr/obj" # Directory in which log files will be created LOG_dir="/tmp" # Change kernel config if desired KERNEL_conf=GENERIC #case "$SRC_dir" in # */src-6 ) # KERNEL_conf="BOVINE-T42.6" # KERNEL_conf="$KERNEL_conf BOVINE-T42.6.Debug" # ;; #esac KERNEL_conf_dir="$SRC_dir/sys/i386/conf" KERNEL_compile_dir="${KERNEL_conf_dir}/../compile/${KERNEL_conf}" usage() { cat <&2 Usage: $0 clean $0 all # buildworld, buildkernel, installkernel $0 kern # buildkernel, installkernel $0 USAGE } exit_usage() { usage ; exit 1 } beep() { for n in $( jot ${1:-1} ) do printf "\a" sleep 0.4 done } msg() { local format format=${1:-""} shift #echo "F: $format #: $# @: $@" >&2 case $# in 0 ) echo "$format" ;; * ) echo "$*" ;; esac } err_msg() { msg $@ >&2 } # Append current date/time to given log file tee_date() { case $# in 0) rc=0 ;; *) echo ' ## ## time: '`date` | tee -a "$1" rc=$? ;; esac return $rc } # Sanity checking. chk_score=0 # Check if directories specified exist for chk_dir in "$SRC_dir" "$OBJ_dir" "$LOG_dir" do [ -d "$chk_dir" -a -r "$chk_dir" -a -w "$chk_dir" ] && continue; err_msg "'$chk_dir' is not a read/writeable directory." chk_score=$(($chk_score+1)) done # Check if kernel configuration exist. for kern in $KERNEL_conf do if [ ! -e "${SRC_dir}/sys/i386/conf/${kern}" ] then err_msg "Kernel configuration file '$kern' does not seem to exist." chk_score=$(($chk_score+1)) fi done # Exit if any files/directories missing if [ $chk_score -ne 0 ] then err_msg '...due to non-existent files, exiting...' exit 1 fi #set +x PLAN= case $1 in # Clean $SRC_dir & $OBJ_dir if "clean" option given # cl*) shift msg ' cleaning %s' "$SRC_dir" rm -rf "${OBJ_dir}/*" chflags -R noschg "$OBJ_dir" rm -rf "${OBJ_dir}/*" { cd $SRC_dir && make cleandir && make cleandir && make clean ; } >/dev/null msg ' ...cleaning done' exit ;; buildw* | bw ) PLAN="buildworld" ;; installw* | iw ) PLAN="installworld" ;; buildk* | bk ) PLAN="buildkernel" ;; installk* | ik ) PLAN="installkernel" ;; ker* | bik ) PLAN="kernel" ;; all ) PLAN="buildworld kernel" ;; * ) usage exit 1 ;; esac # Links to actual log files link_bw="${LOG_dir}/bw" link_bk="${LOG_dir}/bk" link_ik="${LOG_dir}/ik" link_iw="${LOG_dir}/iw" link_bik="${LOG_dir}/bik" log_bw= log_iw= log_bk= log_ik= log_bik= date_start=`date -u '+%Y-%m%d-%H%M.%S'` # Set actual log file names gen_name() { # Log file names for build world & kernel log_bw="${link_bw}.${date_start}" log_bk="${link_bk}.${date_start}" # Log file names for install world & kernel log_ik="${link_ik}.${date_start}" log_iw="${link_iw}.${date_start}" # Log file name for combined build-install kernel making. log_bik="${link_bik}.${date_start}" } make_log_link() { local log="$1" link=$( echo "$log" | sed -E -e 's/\.'"$date_start"'//' ) touch "$log" && \ ln -sf "$log" "$link" || exit_msg "Error in linking " } # Append current date/time to given log files; and show log file names verbose_tee_date () { case $# in 0) date rc=$? ;; *) for log in $@ do tee_date "$log" msg ' -- log: %s' "$log" done rc=$? ;; esac return $rc } # Show error message based on passed $? and world/kernel make target show_err_exit() { case $2 in buildworld ) msg="building world" ;; installworld ) msg="building world" ;; buildkernel) msg="building kernel" ;; installkernel ) msg="installing kernel" ;; kernel ) msg="making/installing kernel" ;; *) msg=" _Doing_Something_Unknown_ " ;; esac if [ $1 -ne 0 ] then err_msg " ...error (${1}) while ${msg}; exiting..." exit 1 fi } handle_kern_world() { local target="$1" local log="$2" local rc cd "$SRC_dir" \ && verbose_tee_date "$log" \ && printf "object dir: %s\nkernel(s): %s\n" "$OBJ_dir" "$KERNEL_conf" \ | tee -a "$log" \ && MAKEOBJDIRPREFIX="$OBJ_dir" \ make $target KERNCONF="$KERNEL_conf" >> "$log" 2>&1 rc=$? tee_date "$log" return $rc } gen_name build_install() { case $# in 1) ;; *) exit_usage ;; esac case $1 in buildworld ) make_log_link "$log_bw" handle_kern_world buildworld "$log_bw" rc_bi=$? ;; installworld ) make_log_link "$log_iw" handle_kern_world installworld "$log_iw" rc_bi=$? ;; buildkernel ) make_log_link "$log_bk" handle_kern_world buildkernel "$log_bk" rc_bi=$? ;; installkernel ) make_log_link "$log_ik" handle_kern_world installkernel "$log_ik" rc_bi=$? ;; kern* ) make_log_link "$log_bik" handle_kern_world kernel "$log_bik" rc_bi=$? ;; *) exit_usage ;; esac show_err_exit $rc_bi "$1" } for target in $PLAN do msg "\n- make %s ...\n" "$target" build_install "$target" beep 2 msg "\n... done %s\n" "$target" done noise || beep 3 &