#!/bin/sh # # $Id: mms,v 1.7 2009-11-26 18:51:54 martti Exp $ # # Copyright (c) 2009 Martti Kuparinen # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. # TMPFILE="/tmp/`basename $0`" usage() { cat << EOF Make Me Slim \$Revision: 1.7 $ Martti Kuparinen Usage: `basename $0` [-b] [-h] [-n] [-y] -b Remove even packages needed during pkgsrc bootstrap -h This help -n Do not actually remove anything (usually used together with -y) -y Assume y for all questions EOF exit 1 } error() { echo ${*} exit 1 } ## ## MAIN ## set -- `getopt bhny ${*}` if test ${?} != 0; then usage fi OPT_b=false OPT_n=false OPT_y=false for i do case "${i}" in -b) OPT_b=true shift ;; -h) usage shift ;; -n) OPT_n=true shift ;; -y) OPT_y=true shift ;; --) shift break ;; esac done if [ ! -f /etc/slackware-version ]; then echo echo "ERROR: This tool is only for Slackware Linux" echo exit 1 fi # Get list of currently installed packages cd /var/adm/packages || error "/var/adm/packages: No such directory found!" ls | sed 's#-[^-]*-[^-]*-[^-]*$##' | sort > "${TMPFILE}.src" # Check that we really have everything to bootstrap pkgsrc if ! ${OPT_b}; then NOTIFIED=false for i in binutils cpio cvs diffutils gawk gcc gcc-g++ glibc glibc-solibs \ groff kernel-headers make man man-pages mpfr ncurses openssh \ openssl openssl-solibs sed tar do P=`grep "^${i}\$" "${TMPFILE}.src"` if [ -z "${P}" ]; then echo "ERROR: You must install ${i}" NOTIFIED=true fi done if ${NOTIFIED}; then exit 1 fi fi # Generate list of packages to keep cat > "${TMPFILE}.ignore" << EOF /^aaa_base$/d /^aaa_elflibs$/d /^aaa_terminfo$/d /^acpid$/d /^acl$/d /^bash$/d /^bc$/d /^bin$/d /^binutils$/d /^bzip2$/d /^coreutils$/d /^cpio$/d /^cxxlibs$/d /^dcron$/d /^device-mapper$/d /^devs$/d /^dhcpcd$/d /^diffutils$/d /^e2fsprogs$/d /^elvis$/d /^etc$/d /^ethtool$/d /^file$/d /^findutils$/d /^gawk$/d /^gcc$/d /^gcc-g++$/d /^gettext$/d /^glibc$/d /^glibc-solibs$/d /^glibc-zoneinfo$/d /^grep$/d /^groff$/d /^gzip$/d /^iproute2$/d /^iptables$/d /^iputils$/d /^kbd$/d /^kernel-firmware/d /^kernel-generic/d /^kernel-headers/d /^kernel-huge/d /^kernel-modules/d /^less$/d /^lilo$/d /^logrotate$/d /^lvm2$/d /^make$/d /^man$/d /^man-pages$/d /^mkinitrd$/d /^module-init-tools$/d /^mpfr$/d /^ncurses$/d /^netkit-routed$/d /^net-tools$/d /^network-scripts$/d /^nfs-utils$/d /^patch$/d /^pciutils$/d /^pkgtools$/d /^portmap$/d /^procps$/d /^sed$/d /^shadow$/d /^slackpkg$/d /^sysklogd$/d /^sysvinit/d /^tar$/d /^udev$/d /^utempter$/d /^util-linux-ng$/d /^which$/d /^xz$/d EOF # We might need these if [ ! -z "`mount | grep jfs`" ]; then echo '/^jfsutils$/' >> "${TMPFILE}.ignore" fi if [ ! -z "`mount | grep reiser`" ]; then echo '/^reiserfsprogs$/' >> "${TMPFILE}.ignore" fi # We need these during bootstrap if ! ${OPT_b}; then cat >> "${TMPFILE}.ignore" << EOF /^cvs$/d /^openssh$/d /^openssl$/d /^openssl-solibs$/d EOF fi # Create list of packages to remove sed -f "${TMPFILE}.ignore" < "${TMPFILE}.src" > "${TMPFILE}.remove" # Remove the packages for i in `cat "${TMPFILE}.remove"` do if ! ${OPT_y}; then echo -n "Remove ${i} (y/N)? " read ANSWER case "x${ANSWER}" in x[yY]) YES=true ;; *) YES=false ;; esac else YES=true fi if ${YES}; then if ${OPT_n}; then echo "${i} not really removed" else removepkg ${i} fi fi done # Clean up rm -f "${TMPFILE}.src" "${TMPFILE}.ignore" "${TMPFILE}.remove"