Skip to content

Instantly share code, notes, and snippets.

@0xf10e
Last active February 21, 2018 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xf10e/161ce33281d6f73082020e9295320231 to your computer and use it in GitHub Desktop.
Save 0xf10e/161ce33281d6f73082020e9295320231 to your computer and use it in GitHub Desktop.
Used on my 11^W12-CURRENT laptop to rebuild FreeBSD from source.
#!/bin/sh
UPDATE_SRC=false
if [ ! -z "$1" ] && [ "$1" = "-u" ];
then
UPDATE_SRC=true
if which svn; then
SVN=`which svn`
elif which svnlite; then
SVN=`which svnlite`
else
echo ' ! No SVN-client found.'
SVN=/nonexistant
UPDATE_SRC=false
fi
fi
if [ -d /usr/obj/usr ];
then
chflags -R noschg /usr/obj/usr && \
rm -rf /usr/obj/usr || \
exit 1
fi
cd /usr/src && \
make cleandir && \
make cleandir
if $UPDATE_SRC && [ -x "$SVN" ]; then
$SVN up
fi
#!/bin/sh -e
if [ -f /usr/src/src.conf ];
then
SRCCONF_PARM="SRCCONF=/usr/src/src.conf"
fi
if [ -f /usr/src/sys/amd64/conf/IPSEC_VIMAGE ];
then
KERNCONF_PARM="KERNCONF=IPSEC_VIMAGE"
fi
KEEP=false
NO_KERNEL=false
CPUS=`sysctl -n hw.ncpu`
JOBS=$CPUS
while [ "x$1" != "x" ];
do
case "$1" in
# Prevents make clean
-K) KEEP=true
echo "Does not work as advertised!"
exit 2
;;
# set number of parallel
# jobs to run
-j) if [ "$2" != "${2#/}" ];
then
JOBS=$(( $CPUS / ${2#/} ))
else
JOBS=$2
fi
if [ $JOBS -le 1 ];
then
echo " ! Can't run less than one job." \
> /dev/stderr
JOBS=1
fi
shift
;;
-N) NO_KERNEL=true
;;
*) echo " ! Unknown parameter '$1'." \
> /dev/stderr
exit 1
;;
esac
shift
done
cd /usr/src
if ! $KEEP;
then
test -d /usr/obj/usr && \
chflags -R noschg /usr/obj/usr
rm -rf /usr/obj/usr
make cleandir
make cleandir
else
echo " * Not cleaning /usr/src before running make"
sleep 2
fi
/usr/bin/time -o make_buildworld.time \
nice make -j $JOBS $SRCCONF_PARM buildworld
/usr/bin/time -o make_buildkernel.time \
nice make -j $JOBS \
$SRCCONF_PARM $KERNCONF_PARM buildkernel
if $NO_KERNEL;
then
echo " * Not installing the built kernel."
else
make $SRCCONF_PARM $KERNCONF_PARM installkernel
fi
#!/bin/sh -e
# based on
# http://www.bsdnow.tv/tutorials/stable-current
UPDATE_PKGS=false
if [ "x$1" = "x-p" ];
then
UPDATE_PKGS=true
fi
if [ -f /usr/src/src.conf ];
then
SRCCONF_PARM="SRCCONF=/usr/src/src.conf"
fi
cd /usr/src
## If anything needs to be merged, added or removed.
mergemaster -p
make $SRCCONF_PARM installworld
# You will merge the new config files with your old ones.
mergemaster -iUF
yes | make delete-old
if $UPDATE_PKGS;
then
echo " * Updating packages before removing old libs."
pkg upgrade
fi
yes | make delete-old-libs
chflags -R noschg /usr/obj/*
rm -rf /usr/obj/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment