PDA

View Full Version : openup


soup4you2
July 11th, 2003, 18:39
found this today.... thought i would post it to see what you all think about it....


[code:1:98ad61a047]
#!/bin/sh
# openup.sh 1.2: Upgrade OpenBSD to -stable or -current
#
# Copyright (c) 2003 Andre Nathan <andre@v2r.com.br>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#
# This was based on OpenBSD's release(8) and upgrade-minifaq, found at
# http://www.openbsd.org/faq/upgrade-minifaq.html
#
# Some ideas, like showing start and end times and the automatic installation
# of tcl and tk when building XF4 were borrowed from FenderQ's Release Building
# Shell Script v1.7 at http://www.geocities.com/easybakeoven88/release.html
#

usage() {
echo "openup.sh 1.2"
echo "Usage: `basename ${0}` <option>"
echo "option is one of: cvs, kernel, build, release, xfree or xfree-release"
echo " cvs takes two optional arguments:"
echo " -s, --skip <[src] [ports] [xfree]>"
echo " Don't fetch space-separated list of selected sources."
echo " -t, --tree <stable|current>"
echo " Choose which tree to fetch."
echo " kernel takes an option argument:"
echo " -k, --kernel <file>"
echo " Specifies the kernel configurarion file. This file must"
echo " live in the /usr/src/sys/arch/`machine`/conf directory."
exit
}

get_cvs() {
export CVSROOT
cvsopt=""
if [ "X${TREE}" = X"stable" ]; then
cvsopt="-r${STABLE}"
fi
echo
echo ">>> Starting CVS update process for ${TREE} sources"
if [ "X${GETSRC}" = X"yes" ]; then
echo
if [ ! -d "/usr/src" ]
[ -d "/usr/src" -a -z "`ls /usr/src`" ]; then
mkdir -p /usr/src
cvscmd="get"
echo "* Getting src"
else
cvscmd="up"
echo "* Updating src"
fi
echo
cd /usr/src &&
cvs -z${CVSCOMPRESS} -d ${CVSROOT} ${cvscmd} ${cvsopt} -PAd
fi
if [ "X${GETPORTS}" = X"yes" ]; then
echo
if [ ! -d "/usr/ports" ] ||
[ -d "/usr/ports" -a -z "`ls /usr/ports`" ]; then
mkdir -p /usr/ports
cvscmd="get"
echo "* Getting ports"
else
cvscmd="up"
echo "* Updating ports"
fi
echo
cd /usr/ports &&
cvs -z${CVSCOMPRESS} -d ${CVSROOT} ${cvscmd} ${cvsopt} -PAd
fi
if [ "X${GETXF4}" = X"yes" ]; then
echo
if [ ! -d "/usr/XF4" ] ||
[ -d "/usr/XF4" -a -z "`ls /usr/XF4`" ]; then
mkdir -p /usr/XF4
cvscmd="get"
echo "* Getting XF4"
else
cvscmd="up"
echo "* Updating XF4"
fi
echo
cd /usr/XF4 &&
cvs -z${CVSCOMPRESS} -d ${CVSROOT} ${cvscmd} ${cvsopt} -PAd
fi
echo
echo ">>> Finished updating via CVS"
echo
echo -n "\a"
}

compile_kernel() {
echo
echo ">>> Starting kernel compilation process for ${KERNEL}"
echo
cd /usr/src/sys/arch/`machine`/conf && config ${KERNEL} &&
cd /usr/src/sys/arch/`machine`/compile/${KERNEL} &&
make clean && make depend && make &&
cp /bsd /bsd.old && cp bsd /bsd && chown root:wheel /bsd
echo
echo ">>> Finished kernel compilation. Now reboot."
echo
echo -n "\a"
}

make_build() {
echo
echo ">>> Starting userland building process with ${TREE} sources"
echo
rm -rf /usr/obj/* && cd /usr/src &&
if [ "X${TREE}" = X"current" ]; then
find . -type l -name obj | xargs rm && make cleandir &&
make obj && cd /usr/src/etc && make DESTDIR=/ distrib-dirs &&
cd /usr/src && make obj && make build &&
[ -d ${NEWROOT} ] && rm -rf ${NEWROOT}
mkdir ${NEWROOT} && export DESTDIR=${NEWROOT} && cd /usr/src/etc &&
make distribution-etc-root-var && cd /dev &&
cp /usr/src/etc/etc.`machine`/MAKEDEV ./ && ./MAKEDEV all
else
make obj && make build && cd /dev && ./MAKEDEV all
fi
echo
echo ">>> Finished building system. Now configure /etc and /var by hand."
echo
echo -n "\a"
}

make_release() {
echo
echo ">>> Starting release building process."
echo
cd /usr/src/distrib/crunch && make obj depend all install
if [ "X`machine`" = X"sparc64" ]; then
cd /usr/src/distrib/sparc64/mksuncd &&
make obj depend all install
fi
export DESTDIR RELEASEDIR
[ -d "${DESTDIR}" ] && rm -rf ${DESTDIR}
mkdir -p ${DESTDIR} ${RELEASEDIR} && cd /usr/src/etc &&
make release && cd /usr/src/distrib/sets && sh checkflist
unset RELEASEDIR DESTDIR
echo
echo ">>> Finished making release."
echo
echo -n "\a"
}

build_xf4() {
echo
echo ">>> Starting XF4 building process."
echo
[ -d ${XF4BLD} ] && rm -rf ${XF4BLD} && mkdir -p ${XF4BLD} &&
if [ "X`machine`" = X"i386" ]; then
cd /usr/ports/lang/tcl/8.3 && make install clean clean-depends &&
cd /usr/ports/x11/tk/8.3 && make install clean clean-depends
fi
cd ${XF4BLD} && lndir /usr/XF4 && make build
echo
echo ">>> Finished building XF4."
echo
echo -n "\a"
}

make_xf4_release() {
export DESTDIR RELEASEDIR
echo
echo ">>> Starting XF4 release building process."
echo
[ -d "${DESTDIR}" ] && rm -rf ${DESTDIR} &&
mkdir -p ${DESTDIR} ${RELEASEDIR} && make release
unset RELEASEDIR DESTDIR
echo
echo ">>> Finished making XF4 release."
echo
echo -n "\a"
}


##
## MAIN
##

# The following variables can be overrided by using the ~/.openuprc file
if [ ! -z "`env | grep CVSROOT`" ]; then
ENV_CVSROOT=anoncvs@anoncvs1.ca.openbsd.org:/cvs
fi

TREE="stable"
STABLE="OPENBSD_3_3"
KERNEL="GENERIC"
CVSCOMPRESS=6
NEWROOT="/home/newroot"
DESTDIR="/home/release_build"
RELEASEDIR="/home/release"
XF4BLD="/home/xfree_build"
GETSRC="yes"
GETPORTS="yes"
GETXF4="yes"

if [ -f "${HOME}/.openuprc" ]; then
. ${HOME}/.openuprc
fi

if [ ! -z "${ENV_CVSROOT}" ]; then
# If ${CVSROOT} is set on the enviroment, it takes precedence
CVSROOT=${ENV_CVSROOT}
fi

start=`date`

action=""
case "${1}" in
cvs)
shift
while [ ! -z "${1}" ]; do
if [ "X${1}" = X"-t" -o "X${1}" = X"--tree" ]; then
shift
case "${1}" in
current) TREE="current" ;;
stable) TREE="stable" ;;
*) usage ;;
esac
shift
elif [ "X${1}" = X"-s" -o "X${1}" = X"--skip" ]; then
shift
[ -z "${1}" ] && usage
while [ ! -z "${1}" -a -z "$( echo ${1} | grep ^- )" ]; do
case "${1}" in
src)
GETSRC="no"
;;
ports)
GETPORTS="no"
;;
xfree)
GETXF4="no"
;;
*) usage ;;
esac
shift
done
else
usage
fi
done
string="CVS update for -${TREE}"
action="get_cvs"
;;
kernel)
shift
if [ ! -z "${1}" ]; then
if [ "X${1}" = X"-k" -o "X${1}" = X"--kernel" ]; then
shift
if [ -z "${1}" ]; then
usage
fi
KERNEL=${1}
if [ ! -f "/usr/src/sys/arch/`machine`/conf/${KERNEL}" ]; then
echo
echo "*** Kernel configuration file ${KERNEL} not found."
echo
exit
fi
else
usage
fi
fi
string="Kernel compiling"
action="compile_kernel"
;;
build)
shift
[ ! -z "${1}" ] && usage
string="Userland building"
action="make_build"
;;
release)
shift
[ ! -z "${1}" ] && usage
string="Release building"
action="make_release"
;;
xfree)
shift
[ ! -z "${1}" ] && usage
string="XF4 building"
action="build_xf4"
;;
xfree-release)
shift
[ ! -z "${1}" ] && usage
string="XF4 release building"
action="make_xf4_release"
;;
*) usage ;;
esac

[ ! -z "${2}" ] && usage

if [ ! -f "${HOME}/.openuprc" ]; then
cat <<EOF > ${HOME}/.openuprc
# Which tree will be fetched (stable or current)
TREE=${TREE}

# The CVS mirror
CVSROOT=${ENV_CVSROOT}

# CVS compress level
CVSCOMPRESS=${CVSCOMPRESS}

# CVS tag for -stable (OPENBSD_X_Y)
STABLE=${STABLE}

# Kernel configuration file name
KERNEL=${KERNEL}

# Where the updated /etc and /var will be
NEWROOT=${NEWROOT}

# Where the release will be built
DESTDIR=${DESTDIR}

# Where the release file will be
RELEASEDIR=${RELEASEDIR}

# Where XF4 will be built
XF4BLD=${XF4BLD}

# Fetch src? (yes or no)
GETSRC=${GETSRC}

# Fetch ports? (yes or no)
GETPORTS=${GETPORTS}

# Fetch xfree? (yes or no)
GETXF4=${GETXF4}
EOF
fi

${action}

end=`date`
echo "${string} started at: ${start}"
echo "${string} finished at: ${end}"
[/code:1:98ad61a047]