All pastes #811219 Raw Edit

clueless

public text v1 · immutable
·published 2007-12-10 18:47 UTC
rendered paste body
#!/bin/shset -eexport LC_ALL=Ctype=$1preversion=$2package_name(){    echo libc6}# Borrowed from sysvinit's postinst.#	Function like update-rc.d but simpler & faster.#	Usage: updatercd basename start|stop NN runlevel .##	Now we use the real update-rc.d, so now this function should#	be equivalent to /usr/sbin/update-rc.d.#updatercd() {	if [ ! -f /etc/init.d/$1 ]	then		return	fi	if [ -x /usr/sbin/update-rc.d ]	then		update-rc.d "$@" > /dev/null		return $?	fi	base=$1	shift	while [ "$1" != "" ]	do		if [ "$1" = stop ]		then			tlet=K		else			tlet=S		fi		lev=$2		shift 2		while [ "$1" != "." ]		do			cd /etc/rc$1.d			tmp="`echo $tlet??$base`"			case "$tmp" in				"$tlet??$base")					# Not present yet.					ln -s ../init.d/$base $tlet$lev$base					;;				*)					# Already present.					;;			esac			shift		done		shift	done}# element() is a helper function for file-rc:element() {    local element list IFS    element="$1"    [ "$2" = "in" ] && shift    list="$2"    [ "$list" = "-" ] && return 1    [ "$list" = "*" ] && return 0    IFS=","    set -- $list    case $element in	"$1"|"$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9")	    return 0    esac    return 1}# filerc (runlevel, service) returns /etc/init.d/service, if service is# running in $runlevel:filerc() {    local runlevel basename    runlevel=$1    basename=$2    while read LINE    do	case $LINE in	    \#*|"") continue	esac	set -- $LINE	SORT_NO="$1"; STOP="$2"; START="$3"; CMD="$4"	[ "$CMD" = "/etc/init.d/$basename" ] || continue	if element "$runlevel" in "$START" || element "S" in "$START"	then	    echo "/etc/init.d/$basename"	    return 0	fi    done < /etc/runlevel.conf    echo ""}checkpkgver () {    local status pkg    pkg=$1    status=$(dpkg -s $pkg 2>/dev/null | grep ^Status: | sed -e 's/^Status: \(.*\) \(.*\) \(.*\)/\3/g')    if [ -n "$status" ] && [ "$status" != "not-installed" ] && [ "$status" != "config-files" ]; then	echo $(dpkg -s $pkg 2>/dev/null | grep ^Version: | sed -e 's/^Version: *//');    fi}if [ "$type" = "configure" ]then    # Handle upgrades for libdb.so.3. We do this before calling ldconfig,    # since it will create a symlink for us. Just move everything over. We    # use `cat' because I feel it is simpler and safer. Make sure that    # libdb.so.3 is either a symlink, or non-existent, just in case    # something weird happened and the new libdb2 is unpacked before we    # get here.    if [ -e /lib/libdb.so.3.old ]; then	if [ -L /lib/libdb.so.3 ] || [ ! -e /lib/libdb.so.3 ]; then	    rm -f /lib/libdb.so.3	    cat /lib/libdb.so.3.old > /lib/libdb.so.3	fi	rm -f /lib/libdb.so.3.old    fi    # Add support for /etc/ld.so.conf.d    if [ -e /etc/ld.so.conf ]; then        [ -z "$(tail -n 1 /etc/ld.so.conf)" ] || echo >> /etc/ld.so.conf    else        touch /etc/ld.so.conf    fi    if ! grep -q '^include /etc/ld.so.conf.d/.*\.conf$' /etc/ld.so.conf ; then        echo 'include /etc/ld.so.conf.d/*.conf' >> /etc/ld.so.conf    fi    # We don't use a registry anymore, remove the old file    rm -f /etc/ld.so.hwcappkgs     # /etc/ld.so.nohwcap code: NOHWCAP    # Handle upgrades when libc-opt package has been installed.    # When a /etc/ld.so.nohwcap file exists, ld.so only use libraries    # from /lib, and ignore all optimised libraries. This file is    # inconditionaly created in the preinst script of libc.     # Get the list of optimized packages for a given architecture    # Before removing a package from this list, make sure it appears    # in the Conflicts: line of libc.    case $(dpkg --print-architecture) in        i386)            hwcappkgs="libc6-i686 libc6-xen"            ;;        kfreebsd-i386)            hwcappkgs="libc0.1-i686"            ;;        sparc)            hwcappkgs="libc6-sparcv9 libc6-sparcv9b"            ;;    esac     # We check the version between the current installed libc and    # all optimized packages (on architectures where such packages    # exists).    all_upgraded=yes    if [ -n "$hwcappkgs" ]; then        for pkg in $hwcappkgs ; do            ver=$(dpkg -l $pkg 2>/dev/null | sed -e '/^i/!d;' -e "s/^i.\s\+$pkg\s\+//;s/\s.*//g")            if [ -n "$ver" ] && [ "$ver" != "2.6.1-2" ]; then                all_upgraded=no            fi        done    fi    # If the versions of all optimized packages are the same as the libc    # one, we could remove /etc/ld.so.nohwcap. Otherwise, it will be removed    # when all optimized packages are upgraded or removed.    if [ "$all_upgraded" = yes ] ; then        rm -f /etc/ld.so.nohwcap    fi    if [ ! -z $preversion ]; then	if [ ! -d /var/mail ] && [ ! -L /var/mail ]; then	    ln -sf spool/mail /var/mail	fi	if dpkg --compare-versions $preversion lt 2.3.5-1; then	    echo -n "Checking for services that may need to be restarted..."	    check="nis smail sendmail exim exim4-base ssh netbase"	    check="$check ssh-nonfree postfix-tls wu-ftpd boa cron postfix"	    check="$check wu-ftpd-academ vsftpd slapd openldapd wwwoffle"	    check="$check cupsys lprng lpr lpr-ppd autofs snmpd ssh-krb5"	    check="$check courier-authdaemon mysql-server spamassassin"	    check="$check apache apache-ssl apache-perl apache2-common"	    check="$check proftpd proftpd-ldap proftpd-mysql proftpd-pgsql"	    check="$check dovecot-common cucipop rsync samba saslauthd"	    check="$check webmin dropbear"	    # Only get the ones that are installed, and configured	    check=$(dpkg -s $check 2> /dev/null | egrep '^Package:|^Status:' | awk '{if ($1 ~ /^Package:/) { package=$2 } else if ($0 ~ /^Status: .* installed$/) { print package }}')	    # apache2 ships its init script in apache2-common, but the	    # script is apache2	    check=$(echo $check | sed 's/apache2-common/apache2/g')	    # exim4 ships its init script in exim4-base, but the script	    # is exim4	    check=$(echo $check | sed 's/exim4-base/exim4/g')	    # The name of proftpd-{ldap,mysql,pgsql} init script is	    # same as "proftpd".	    check=$(echo $check | sed 's/proftpd-.*/proftpd/g')	    # dovecot-common ships its init script, but the	    # script name is dovecot for dovecot-{imapd,pop3d}.	    check=$(echo $check | sed 's/dovecot-common/dovecot/g')	    # lpr and lpr-ppd ship its init script, but the 	    # script name is lpd and lpd-ppd.  The inserted space is	    # intentional to not replace lprng.	    check=$(echo $check | sed 's/lpr /lpd /g')	    check=$(echo $check | sed 's/lpr-ppd /lpd-ppd /g')	    # We have to list inetd and atd explicitly, because the packages	    # have different names to their init scripts	    check="$check inetd atd"	    rl=$(runlevel | awk '{print $2}')	    for service in $check; do		if [ -f /usr/share/file-rc/rc ] || [ -f /usr/lib/file-rc/rc ] && [ -f /etc/runlevel.conf ]; then		    idl=$(filerc $rl $service)		else		    idl=$(ls /etc/rc${rl}.d/S??${service} 2> /dev/null | head -1)		fi		if [ -n "$idl" ] && [ -x $idl ]; then		    services="$service $services"		fi	    done	    echo "done."	    if [ -n "$services" ]; then		echo		echo "Name Service Switch update in the C Library: post-installation question."		echo		echo "Running services and programs that are using NSS need to be restarted,"		echo "otherwise they might not be able to do lookup or authentication any more"		echo "(for services such as ssh, this can affect your ability to login)."		echo "Note: restarting sshd/telnetd should not affect any existing connections."		echo		echo "The services detected are: "		echo "        $services"		echo		echo "If other services have begun to fail mysteriously after this upgrade, it is"		echo "probably necessary to restart them too.  We recommend that you reboot your"		echo "machine after the upgrade to avoid NSS-related troubles."		echo		frontend=`echo "$DEBIAN_FRONTEND" | tr '[:upper:]' '[:lower:]'`		if [ "$frontend" = noninteractive ]; then		    echo "Non-interactive mode, restarting services"		    answer=yes		else		    echo -n "Do you wish to restart services? [Y/n] "		    read answer		    case $answer in			Y*|y*) answer=yes ;;			N*|n*) answer=no ;;			*) answer=yes ;;		    esac		fi		echo		if [ "$answer" = yes ] && [ "$services" != "" ]; then		    echo "Restarting services possibly affected by the upgrade:"		    failed=""		    for service in $services; do			if [ -f /usr/share/file-rc/rc ] || [ -f /usr/lib/file-rc/rc ] && [ -f /etc/runlevel.conf ]; then			    idl=$(filerc $rl $service)			else			    idl=$(ls /etc/rc${rl}.d/S??${service} 2> /dev/null | head -1)			fi			echo -n "  $service: stopping..."			$idl stop > /dev/null 2>&1 || true			sleep 2			echo -n "starting..."			if $idl start > /dev/null 2>&1; then			    echo "done."			else			    echo "FAILED! ($?)"			    failed="$service $failed"			fi		    done		    echo		    if [ -n "$failed" ]; then			# Ruh roh, George			echo "The following services failed to start: $failed"			echo			echo "You will need to start these manually by running \`/etc/init.d/<service> start'"			echo "If the service still fails to start, you may need to file a bug on"			echo "$(package_name) or the service involved."			if [ "$DEBIAN_FRONTEND" != noninteractive ]; then			    echo			    echo -n "Press ENTER to continue: "			    read foo			fi		    else			echo "Services restarted successfully."		    fi		    echo		fi	    fi	fi # end upgrading and $preversion lt 2.3.5-1    fi # Upgrading    # Generate cache file /usr/lib/gconv/gconv-modules.cache    iconvconfig || true#    # DO NOT FOLLOW THIS EXAMPLE IN OTHER PACKAGES     updatercd glibc.sh start 01 S .     if [ -x /usr/sbin/invoke-rc.d ]; then	invoke-rc.d glibc.sh start     else	/etc/init.d/glibc.sh 2>/dev/null || true     fifiif [ "`uname -s`" = Linux ]; then##       Upgrade init if possible. There was a bug in all versions#       up to and including 2.75-4, which didn't affect i386 but#       did affect most other architectures.#sysvinitver="`dpkg -s sysvinit 2>/dev/null | grep ^Version: | sed -e 's/^Version: *//'`"case "`uname -m`" in        i?86)                badsysvinitver="2.[0-6]*|2.7[0-3]*"                ;;        *)                badsysvinitver="2.[0-6]*|2.7[0-4]*|2.75-*"                ;;esac# Black magic. If we are in a chroot, then /proc/1/exe will not resolve to# a file (will return EPERM). This keeps us from breaking things in# debootstrap, and the like.case "$sysvinitver" in        $badsysvinitver)                ;;        *)		if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then			# the devicenumber/inode pair of / is the same as that of /sbin/init's			# root, so we're *not* in a chroot			(init u ; sleep 1)		fi		;;esacfi# Automatically added by dh_makeshlibsif [ "$1" = "configure" ]; then	ldconfigfi# End automatically added sectionexit 0