#!/bin/csh # NAME # ~/bin/.csh/customise # SYNOPSIS: customise [path] [release] # EXAMPLES # customise # customise src # customise some_path/src # customise ports # customise some_path/ports # customise /usr/src 6.0-RELEASE # AUTHOR "Julian H. Stacey" # COPYRIGHT # Copyright Julian Stacey, Munich 1993-2005. # Free Software. Liability Disclaimed. # DESCRIPTION # This Cshell script starts with a standard FreeBSD src &/or ports tree, # then applies my tree of local customisations, # - Directories ending _imp are imports # - Directories ending _gen contain code of generic interest. # - Directories ending _jhs contain code of personal interest. # - File ending .diff are used to patch the target tree. # - Ending eg *.REL=6.2-RELEASE.diff only patch if release matches. # - ending eg *.REL=ALL.diff are used to patch regardless of release. # - Files ending .cust_rel These are not patch files, but raw # files, to be installed as is unchanged, in target tree, but only if # the release name matches. Useful for installing different patch # files in ports/*/*/files/patch-* dependent on release. # ASSUMPTIONS # I assume /usr/src & /usr/ports point to valid trees. # BUGS: # Produces links like this: # /usr1/work/freebsd/2.2.8-RELEASE/src/contrib/nvi/\ # LN.README.JHS -> \ # /a/flip/usr/home/jhs/public_html/src/bsd/fixes/FreeBSD/\ # src/gen/./contrib/nvi/README.JHS # If run on a laptop in standalone mode one gets a pointer to # /usr/backup/host/flip/usr/home/jhs/...... # which will be out of date when working @ holz. # In both cases it would be better to do a x=`cd ~jhs;pwd` # & then replace all future path containing $x with the # meta path /usr/home/jhs # If run on host=laps.no.net it produces eg # /sys/i386/conf/LN.HOLZ@ -> # /usr/home/jhs/._/public_html/src/bsd/fixes/\ # FreeBSD/src/jhs/./sys/i386/conf/HOLZ # which later takes the obsolete frozen config., # not newer one on host=user. set OS_NAME = `uname -s` set UNAME_R = `uname -r` set USER = `logname`# sx whoami reports root set FIXES = ~$USER/public_html/src/bsd/fixes/$OS_NAME set PATCH_FLAGS = set ECHO = echo # set ECHO = true # set ECHO to echo or true, depending how much chat you want. if ( $1.x == .x ) then #{ switch ($OS_NAME) #{ case FreeBSD: set SRC_PORTS = "/usr/src /usr/ports" breaksw case NetBSD: set SRC_PORTS = "/usr/src" set PATCH_FLAGS = -N # patch -N appropriate for pc532 same src tree, # never new, not appropriate for i486, always # new tree. breaksw case default: echo "Error no default for this operating system" exit 1 breaksw endsw #} else #}{ set SRC_PORTS = "$1" endif #} if ( $2.x != .x ) then #{ # Add a fix to allow human to specify a version, to over-ride # uname -r to support eg # - 5.1 to use latest 5.3 fixes. eg for ports/*/Makefile # - 5 stable to be able to install a 5.4-RELEASE pre make world. # - Forcing 6.0-BETA3 to use 6.0-BETA2 older ptaches, or # 6.0-RELEASE pre named patches. $ECHO "Will use patches for $2 and not $UNAME_R" set UNAME_R = "$2" endif #} $ECHO "Targets: $SRC_PORTS" $ECHO "Patches: $FIXES" $ECHO "Ignore the next /nonexistent: No such file or directory." set no_dir = `cd /nonexistent;pwd` foreach j ( $SRC_PORTS ) #{ set BASE = `basename $j` cp /dev/null .customise # Check $BASE is src or ports, if it is not, abort. if (( $BASE.x == src.x ) || ( $BASE.x == ports.x )) then #{{ $ECHO "Passed check for src or ports." else #}{ echo "Error: $j must end as src or ports" # Before this check was added, if $BASE was for example # /usr/src.current, every file in my home directory # was copied into /usr/src.current ! exit 1 endif #}} set CUSTOMISATIONS = "" # Add generic then personal patches. set CUSTOMISATIONS = "$CUSTOMISATIONS gen $USER" $ECHO "Customisations: $CUSTOMISATIONS" foreach k ( $CUSTOMISATIONS ) #{ set patches=`cd $FIXES/$BASE/$k ; pwd_no_amd` if ( $patches.x == $no_dir.x ) then #{ echo "Fatal error: Cannot access patches directory" echo " $FIXES/$BASE/$k" exit 1 endif #} # Shorten the path, by jumping through any symbolic links. cd $patches set patches=`pwd_no_amd` echo "Need sed to convert leading /.amd_mnt/ to /host/" echo " " ; echo "Patches: $patches" set src_or_ports=`cd $j;pwd_no_amd` if ( $src_or_ports.x == $no_dir.x ) then #{ echo "Fatal error: Cannot access $src_or_ports" exit 1 endif #} # Shorten the path, by jumping through any symbolic links. cd $src_or_ports set src_or_ports=`pwd_no_amd` echo -n "Need to add sed code to convert any leading " echo "/.amd_mnt/ to /host/" # JJLATER echo "Target: $src_or_ports" # Create space to hold typescripts (that should not be held in # the top /usr/src, as this is nfs mounted & shared by # multiple hosts) mkdir -p host/`hostname` $ECHO "Creating directories in: $src_or_ports" $ECHO "to match: $patches" # Netbsd kept being received with directories in share/doc # missing, this broke the mk macros when used with make -i, # ending with cannot fork, or a crash if a superuser. # So I create empty dirs here foreach i ( `cd $patches ; find -L . -type d -print` ) #{ # $ECHO -n "Considering doing mkdir $i, " if ( -d $i ) then #{{ # echo "already exists." else #}{ if ( -e $i ) then #{{ # echo "Error:a non-directory exists:$i" else #}{ mkdir -p $i # $ECHO "made." endif #}} endif #}} end #} $ECHO "Installing new and replacement files:" # Dont break next line into 2 without testing. foreach i ( `cd $patches ; find -L . \( -type f -o -type l \) \ \! -name \*.diff \! -name \*.ignore \! -name \ \*.send-pr \! -name \*.cust_rel -print \ | sort` ) #{ $ECHO "Installing $i" #- Just doing ln -s $patches/$i $i # is too dangerous, as linked originals can get # damaged when /usr/src is changed (eg by vi, or # when the src tree is overlayed by a newer src tree.) #- Can not append a .ORIG with do mv -f $i $i.ORIG # as /usr/ports/*/*/patches/patch* will get # run twice, & cause errors, so must prepend the ORIG. if ( -e $i ) then #{{ (mv -f $i `dirname $i`/ORIG.`basename $i` ) \ >& /dev/null # mv must be in brackets, as eg # sys/Makefile_sub.c is not in tree # On 2nd run ORIG.$i gets overwritten. # but can recover it from master tree if req. else #}{ # echo -n "There was no $i to mv to " # echo "`dirname $i`/ORIG.`basename $i`" endif #}} cp $patches/$i $i # ---- # TEST(1) shows -h, but if I use -h below # instead of -e I get if: Badly formed number. set BLA = `dirname $i`/LN.`basename $i` if ( -e ${BLA} ) then #{{ echo "Pre-exists: ${BLA}" else #}{ ( ln -s $patches/$i ${BLA} ) endif #}} end # } $ECHO " " # Install FreeBSD version dependent files, # eg ports/*/*/files/patches-* . foreach i ( `cd $patches ; find -L . \( -type f -o -type l \) \ -name \*.cust_rel -print` ) #{ $ECHO " " # $ECHO "Considering: $patches/$i" # Determine if install for ALL releases or just eg # 4.9-RELEASE or 5.0-DP2 set rel = `basename $i .cust_rel|sed 's/REL=/ /' | \ awk '{printf "%s\n",$2}'` # $ECHO "DEBUG 11${rel}22" if ( ( ${rel} == ALL ) || ( ${rel} == ${UNAME_R} ) ) \ then #{ # $ECHO "Version match: $patches/$i" if ( -e $i ) then #{{ (mv -f $i \ `dirname $i`/ORIG.`basename $i` ) \ >& /dev/null # mv must be in brackets, as eg # sys/Makefile_sub.c is not in tree # On 2nd run ORIG.$i gets overwritten. # but can recover it from master tree # if req. else #}{ # echo -n "There was no $i to mv to " # echo "`dirname $i`/ORIG.`basename $i`" endif #}} # Map files from eg: # patch-js-HP_ScanJet_4400c.REL=6.2-RELEASE.cust_rel # to eg: patch-js-HP_ScanJet_4400c set rel = `basename $i .diff|sed 's/REL=/ /' | \ awk '{printf "%s\n",$2}'` $ECHO -n "Installing $patches/$i " $ECHO -n "To `dirname $i`/" $ECHO "`basename $i .REL=$rel`" cp $patches/$i \ `dirname $i`/`basename $i .REL=$rel` else #}{ $ECHO "Skipping: $patches/$i" endif # } end # } $ECHO " " # Apply patches # Sort ensures predictable order of # src/Makefile.[12].diff etc foreach i ( `cd $patches ; find -L . \( -type f -o -type l \) \ -name \*.diff -print | sort` ) #{ $ECHO " " # $ECHO "Considering: $patches/$i" # Determine if patch for ALL releases or just eg # 4.9-RELEASE or 5.0-DP2 set rel = `basename $i .diff|sed 's/REL=/ /' | \ awk '{printf "%s\n",$2}'` # $ECHO "DEBUG 11${rel}22" if ( ( ${rel} == ALL ) || ( ${rel} == ${UNAME_R} ) ) \ then #{ $ECHO "Patching from: $patches/$i" patch -s -p2 ${PATCH_FLAGS} -V t < $patches/$i # To allow for local shortname patches. # I should detect diff path length from header, # and then dynamicly decide whether to # instead do a # ( cd `dirname $i` ; patch -s -p2 \ # ${PATCH_FLAGS} -V t < $patches/$i ) else #}{ $ECHO "Not Patching from: $patches/$i" endif # } end # } $ECHO " " foreach i ( `cd $patches ; find -L . \( -type f -o -type l \) \ -name \*.ignore -print | sort` ) #{ $ECHO "Ignoring $i" end # } $ECHO " " $ECHO "Appending $k to `pwd_no_amd`/.customise" $ECHO -n " $k" >> .customise # read by ~/bin/ctms foreach i ( `cd $patches ; find -L . -type f -name \*.ignore \ -o -name \*.send_pr -print |sort` ) #{ # JJLATER should I add \*.cust_rel above ? $ECHO "Skipped: $patches/$i" end # } $ECHO "Finished applying all patches from tree $BASE/$k." end # } if ( $BASE.x == ports.x ) then #{ $ECHO "Consider this:" $ECHO "ln -s /usr/public/freebsd/distfiles/links $BASE/distfiles" endif #} echo "" >> .customise # CR end #} ( cd / ; ln -s usr/src/sys /sys ) # rm -rf games # save space & time ! $ECHO "Starting host specific stuff" switch ($USER) #{ case `whoami`: #{ switch ($OS_NAME) #{ case FreeBSD: #{ #( cd /sys ; ./SELECT research ) #( cd /usr/src ; rm -f sys/compile/.keep_me ) breaksw #} case NetBSD: #{ $ECHO "Calling netbsd_purge" netbsd_purge # scrap other architectures chmod +x /usr/src/usr.bin/lex/mkskel.sh breaksw #} case default: #{ echo "Warning no default for this system" breaksw #} endsw #} breaksw #} case default: #{ echo "Warning no default for user $USER" breaksw #} endsw #} $ECHO "Ending host specific stuff" exit 0 cat ~/public_html/src/bsd/fixes/FreeBSD/src/gen/bad_rooted_links exit # This belongs somewhere else: # after installing new binaries, I will want to do this: cd /usr mv X11R6/lib/X11/fvwm/system.fvwmrc X11R6/lib/X11/fvwm/system.fvwmrc.orig ln -s ../../../../../etc/system.fvwmrc X11R6/lib/X11/fvwm/system.fvwmrc mv X11R6/lib/X11/xdm/Xservers X11R6/lib/X11/xdm/Xservers.orig ln -s ../../../../../etc/Xservers X11R6/lib/X11/xdm/Xservers mv X11R6/lib/X11/xdm/xdm-config X11R6/lib/X11/xdm/xdm-config.orig ln -s ../../../../../etc/xdm-config X11R6/lib/X11/xdm/xdm-config mv local/etc/apache local/etc/apache.orig ln -s ../../../site/usr/local/etc/apache local/etc/apache mv local/etc/mailcap local/etc/mailcap.orig ln -s ../../../site/usr/local/etc/mailcap local/etc/mailcap