#!/bin/ksh - # $Han-Id: OpenBSD-binary-upgrade,v 1.6 2003/12/20 18:12:44 han Exp $ # $Id: snap-tool,v 1.34 2006/01/26 21:12:59 johan Exp $ # Copyright 2003 by Han Boetes # Copyright 2004 by Johan Fredin # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Usecases # -------- # 1. Download all sets, -g (get) # 2. Check md5 checksums, -c (check sums) # 3. Install sets, including running mergemaster, -i (install) # # Other options # ------------- # -x, override $X11, and download all X sets anyway # -d, change DOWNLOADDIR, defaults to ${PWD} # -a, change ARCH, defaults to `uname -m`. This determines for wich # architecture we want to download sets. Also used when installing kernels. # # Subrutines # ---------- # usage # download_sets # check_md5sums # install_kernels # unpack_sets # unpack_etc # Separated because of the TMPROOT creation. # run_mergemaster # ask_reboot # # # TODO # ---- # 1. # ### # Configuration part SUDO='/usr/bin/sudo' DOWNLOADDIR="${PWD}" TMPROOT='/var/tmp/temproot' BSDVERSION='39' # The versionnumber of the packages ARCH="`uname -m`" # Default architecture PAGER='/usr/bin/more' # stuff to remove from the temproot TMPROOT_REMOVE="./etc/myname ./etc/motd ./var/mail/root ./var/www/htdocs/manual/" # Packages # -------- # Select the packages you want. # You need at least bsd, etc and base. KERNEL='bsd bsd.rd' BASE='etc base man comp misc game' #X11='xfont xserv xbase xetc xshare' X11='' # FTP mirrors # ----------- # I recommend using wget or ncftpget since they can check if the local file # is older than the remote file and only then fetches the new file. FETCHCMD='/usr/local/bin/ncftpget' #FETCHCMD='/usr/local/bin/wget -N' #FETCHCMD='/usr/bin/ftp' MIRROR="ftp://ftp.openbsd.org/pub/OpenBSD/snapshots" #MIRROR="ftp://ftp.stacken.kth.se/pub/OpenBSD/snapshots" #MIRROR="ftp://ftp.su.se/pub/OpenBSD/snapshots" #MIRROR="ftp://ftp.kd85.com/pub/OpenBSD/snapshots" # End of configuration ### set -o posix # set POSIX mode to prevent +foo in getopt PATH='/bin:/usr/bin:/usr/local/bin:/usr/local/sbin' PROG=`basename "$0"` usage () { cat << __EOT Usage: ${PROG} action ... [-x] [-d downloaddir] [-a arch] Actions: -g, Get/download selected sets -c, Check md5 sums -i, Install kernels+sets and merge /etc -k, Install kernel -s, Install sets -m, Merge /etc Options: -x, override \$X11, and download all X sets anyway -d, change DOWNLOADDIR (default: \$PWD) -a, change ARCH (default: \`uname -m\`) Example: ${PROG} -gc -d /tmp -a sparc64 __EOT exit 1 } download_sets () { echo "Downloading sets to ${PWD}" MIRROR="${MIRROR}/${ARCH}" # Only when the downloader cannot do timestamping it's necesarry to # check if people want to remove old packages. case ${FETCHCMD} in *wget*) for i in ${FETCHFILES}; do FETCHSTRING="${FETCHSTRING} ${MIRROR}/${i}" done ;; *ncftpget*) # ncftpget does timestamping, but can't # take a long list of files to download. ;; *) # Make sure we have the latest MD5 sums rm -f MD5 unset all for i in ${FETCHFILES}; do if [ -e ${i} ]; then echo "${i} already exists;" echo -n "Delete/delete aLl/Keep/keep All [D/L/K/A] " [ "X${all}" = "X" ] && read answer case ${answer} in d*|D*) echo; rm -rf ${i} ;; a*|A*) break ;; l*|L*) echo; all=yes; rm -f ${i} ;; *) : ;; esac fi done for i in ${FETCHFILES}; do if [ ! -e "${i}" ]; then FETCHSTRING="${FETCHSTRING} ${MIRROR}/${i}" fi done ;; esac # wget, ftp and friends that can take all files on the command line if [ "X${FETCHSTRING}" != "X" ]; then echo "Downloading ${FETCHSTRING}" ${FETCHCMD} ${FETCHSTRING} [ $? -ne 0 ] && echo 'Download failed, aborting.' >&2 && exit 1 else # Poor ncftpget can't do that, we'll have to get them one by one for i in ${FETCHFILES}; do echo "Downloading ${MIRROR}/${i}" ${FETCHCMD} "${MIRROR}/${i}" done fi } check_md5sums () { echo "Checking md5 checksums in ${PWD}" unset abort [ ! -f ${DOWNLOADDIR}/MD5 ] && echo "${DOWNLOADDIR}/MD5 doesn't exist, aborting." >&2 && exit 1 for i in ${FETCHFILES%MD5}; do md5is=$(md5 ${i} | awk '{print $4}') md5shouldbe=$(grep \(${i}\) MD5 | awk '{print $4}') #echo "md5is: ${md5is}" #echo "md5shouldbe: ${md5shouldbe}" if [ "${md5is}" != "${md5shouldbe}" ]; then if [ "X${md5shouldbe}" = "X" ]; then echo "Warning, I don't have any md5 info for ${i}" else echo "The md5 checksum for ${i} is ${md5is} but it should be ${md5shouldbe}" abort=yes fi else echo "The md5 checksum for ${i} is OK." fi done if [ "${abort}" = "yes" ]; then echo 'Error, aborting.' >&2 exit 1 fi } install_kernels () { for i in ${KERNEL}; do if [ -e /${i} ]; then ${SUDO} install -S -p /${i} /o${i} || exit 1 fi echo "Installing ${i} in /" ${SUDO} install -S -p ${i} / || exit 1 done } unpack_sets () { for i in ${PACKAGES}; do if [ "${i}" = "${i#etc}" -a ${i} = ${i#base} ]; then echo "Extracting ${i} in /" ${SUDO} tar -zxpf ${i} -C / || exit 1 fi done # only now install base if [ ! "${PACKAGES#*base*}" = "$PACKAGES" ]; then echo "Extracting base$BSDVERSION.tgz in /" $SUDO tar xzfp base$BSDVERSION.tgz -C / || exit 1 fi } unpack_etc () { if [ ! -d "${TMPROOT}" ]; then echo "Creating temproot in ${TMPROOT}" ${SUDO} mkdir -p ${TMPROOT} [ $? -ne 0 ] && echo "Couldn't create temproot, aborting." >&2 && exit 1 fi echo "Extracting etc${BSDVERSION}.tgz in ${TMPROOT}" ${SUDO} tar -zxpf etc${BSDVERSION}.tgz -C ${TMPROOT} || exit 1 echo "Removing unwanted files from temproot.." for FILE in ${TMPROOT_REMOVE}; do echo "Removing ${TMPROOT}/${FILE}" sudo rm -rf ${TMPROOT}/${FILE} done } run_mergemaster () { ${SUDO} mergemaster -rat ${TMPROOT} || exit 1 ${SUDO} mergemaster -rt ${TMPROOT} || exit 1 } ask_reboot () { echo -n "Reboot? [y/N] " read answer case ${answer} in y*|Y*) ${SUDO} /sbin/reboot ;; *) : ;; esac } gflag=0 cflag=0 iflag=0 mflag=0 kflag=0 sflag=0 # Handle the command line arguments while getopts "gcimxksd:a:" c; do case $c in g) gflag=1 ;; c) cflag=1 ;; i) iflag=1 ;; m) mflag=1 ;; k) kflag=1 ;; s) sflag=1 ;; x) X11='xfont xserv xbase xetc xshare' ;; d) DOWNLOADDIR=${OPTARG} ;; a) ARCH=${OPTARG} ;; *) usage ;; esac done if [ $# -eq 0 ]; then usage fi case ${ARCH} in i386) KERNEL="${KERNEL} bsd.mp" FETCHFILES="${FETCHFILES} pxeboot cd${BSDVERSION}.iso" ;; sparc) FETCHFILES="${FETCHFILES} boot.net" ;; sparc64) FETCHFILES="${FETCHFILES} ofwboot ofwboot.net" ;; hppa) FETCHFILES="${FETCHFILES} lif${BSDVERSION}.fs xxboot" ;; macppc) FETCHFILES="${FETCHFILES} ofwboot" ;; esac # get local settings from ~/.snap-tool if it exists if [ -f ${HOME}/.snap-tool ]; then . ${HOME}/.snap-tool fi for i in ${BASE} ${X11}; do PACKAGES="${PACKAGES} ${i}${BSDVERSION}.tgz" done FETCHFILES="$KERNEL $PACKAGES ${FETCHFILES} MD5" [ ! -d "${DOWNLOADDIR}" ] && echo "${DOWNLOADDIR} doesn't exist, aborting." >&2 && exit 1 cd ${DOWNLOADDIR} [ $gflag -eq 1 ] && download_sets [ $cflag -eq 1 ] && check_md5sums [ $kflag -eq 1 ] && install_kernels [ $sflag -eq 1 ] && unpack_sets if [ $mflag -eq 1 ]; then if ! which mergemaster 2>&1 > /dev/null; then echo "${PROG}: This script requires mergemaster. Please install that port/package" >&2 exit 1 fi unpack_etc run_mergemaster ask_reboot fi if [ $iflag -eq 1 ]; then if ! which mergemaster 2>&1 > /dev/null; then echo "${PROG}: This script requires mergemaster. Please install that port/package" >&2 exit 1 fi install_kernels unpack_sets unpack_etc run_mergemaster ask_reboot fi