#!/bin/sh # # Author: Martti Kuparinen # # $Id: up2date,v 1.3 2005-12-18 09:31:35 martti Exp $ # URL1="ftp://ftp.funet.fi/pub/mirrors/ftp.slackware.com/pub/slackware-" URL2="patches/packages" OPT_L= OPT_I= OPT_V="10.2" OPT_D="/tmp/slackware-${OPT_V}" usage() { echo echo "Usage: `basename $0` {-l | -i} [-d dir] [-v version]" echo echo " -l Load updates" echo " -i Install updates" echo " -d dir Destination directory (default: ${OPT_D})" echo " -v version Slackware version to download (default: ${OPT_V})" echo echo "Example: Download and install all updates for Slackware 10.2" echo echo "# `basename $0` -l -d /tmp/slackware91 -v 10.2" echo "# `basename $0` -i -d /tmp/slackware91" echo exit 1 } if [ ! -f /etc/slackware-version ]; then echo echo "ERROR: This tool is only for Slackware Linux" echo exit 1 fi ## ## MAIN ## set -- `getopt d:ilv: ${*}` if test ${?} != 0; then usage fi for i do case "${i}" in -d) OPT_D="${2}" shift 2;; -i) OPT_I=1 shift;; -l) OPT_L=1 shift;; -v) OPT_V="${2}" shift 2;; --) shift; break;; esac done [ -z "${OPT_L}" -a -z "${OPT_I}" ] && usage echo "Getting list of installed packages" (cd /var/adm/packages && ls | sed 's+-[0-9].*++' > /tmp/slack1.$$) # Download the updates if [ ! -z "${OPT_L}" ]; then [ -d "${OPT_D}" ] && echo "WARNING: ${OPT_D} already exists" mkdir -p "${OPT_D}" || exit 1 cd "${OPT_D}" || exit 1 echo "Downloading list of updates" echo "ls *.tgz" | \ /usr/pkg/bin/ftp "${URL1}${OPT_V}/${URL2}/" | \ grep '.tgz$' | \ awk '{print $9}' > /tmp/slack2.$$ echo "Downloading updates for installed packages" for i in `cat /tmp/slack2.$$` do N="`echo ${i} | sed 's+-[0-9].*++'`" if [ ! -z "`grep "^${N}\$" /tmp/slack1.$$`" ]; then echo -n "===> ${i}: " if [ -f "${i}" ]; then echo "Already downloaded" else echo "Downloading" /usr/pkg/bin/ftp "${URL1}${OPT_V}/${URL2}/${i}" fi fi done echo "Downloaded updates are now in ${OPT_D}" fi # Install the updates if [ ! -z "${OPT_I}" ]; then cd "${OPT_D}" || exit 1 for i in *.tgz do echo "Upgrading ${i}" upgradepkg "${i}" done fi rm -f /tmp/slack*.$$ echo "All done."