[Parsix-Devel] SVN Commit 2632 - /pkg/main/initscripts-parsix-live/trunk/debian/
alanbach-guest at users.alioth.debian.org
alanbach-guest at users.alioth.debian.org
Fri Dec 7 07:47:58 CET 2007
Author: alanbach-guest
Date: Fri Dec 7 06:47:58 2007
New Revision: 2632
URL: http://svn.debian.org/wsvn/pkg-parsix/?sc=1&rev=2632
Log:
* Brand new reboot/halt script from FLL project
Modified:
pkg/main/initscripts-parsix-live/trunk/debian/changelog
pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init
Modified: pkg/main/initscripts-parsix-live/trunk/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-parsix/pkg/main/initscripts-parsix-live/trunk/debian/changelog?rev=2632&op=diff
==============================================================================
--- pkg/main/initscripts-parsix-live/trunk/debian/changelog (original)
+++ pkg/main/initscripts-parsix-live/trunk/debian/changelog Fri Dec 7 06:47:58 2007
@@ -1,3 +1,9 @@
+initscripts-parsix-live (1.0.0) unstable; urgency=low
+
+ * Brand new reboot/halt script from FLL project
+
+ -- Alan Baghumian <alan at technotux.org> Fri, 07 Dec 2007 10:16:35 +0330
+
initscripts-parsix-live (0.9.1) unstable; urgency=low
* Trying to fix final eject problem
Modified: pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init
URL: http://svn.debian.org/wsvn/pkg-parsix/pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init?rev=2632&op=diff
==============================================================================
--- pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init (original)
+++ pkg/main/initscripts-parsix-live/trunk/debian/live-reboot.init Fri Dec 7 06:47:58 2007
@@ -1,166 +1,448 @@
-#!/bin/sh
+#!/bin/bash
+
### BEGIN INIT INFO
-# Provides: live-reboot
+# Provides: fll-reboot
# Required-Start:
-# Required-Stop:
+# Required-Stop:
# Default-Start:
-# Default-Stop:
-# Short-Description: halt/reboot service
-# Description: Halt/Reboot Service for Parsix
+# Default-Stop: 0 6
+# Short-Description: shutdown and eject live media
+# Description: This script provides the equivalent of umountfs,
+# umountroot and halt on a stadard debian system. It umounts
+# live mounts and ejects the live media at shutdown/reboot.
### END INIT INFO
-PATH=/sbin:/bin:/usr/bin:/usr/sbin
-export PATH
-
-# override tool behaviour through distro-defaults
+###
+# F.U.L.L.S.T.O.R.Y init script
+#
+# Copyright: (C) 2007 F.U.L.L.S.T.O.R.Y Project
+# Copyright: (C) 2007 Kel Modderman <kel at otaku42.de>
+# Copyright: (C) 2007 Alan Baghumian <alan at technotux.org>
+# License: GPLv2
+#
+# F.U.L.L.S.T.O.R.Y Project Homepage:
+# http://developer.berlios.de/projects/fullstory
+###
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+NAME="fll-reboot"
+
+###
+# source distro-defaults, no-op unless in live mode
+###
FLL_DISTRO_MODE="installed"
-FLL_DISTRO_NAME="PARSIX"
-
-#[ -r /etc/default/distro ] && . /etc/default/distro
-#FLL_DISTRO_NAME="$(echo $FLL_DISTRO_NAME | tr [a-z] [A-Z])"
-
-[ ! "$FLL_DISTRO_MODE" = "live" ] && exit 0
-
-case "$1" in
+
+if [ -s /etc/default/distro ]; then
+ . /etc/default/distro
+fi
+
+if [ "${FLL_DISTRO_MODE}" != "live" ]; then
+ exit 0
+fi
+
+###
+# VERBOSE setting and other rcS variables
+###
+. /lib/init/vars.sh
+
+###
+# source lsb functions
+###
+. /lib/lsb/init-functions
+
+###
+# ANSI escape sequences (N, R, G, Y, B, M, C, W)
+###
+. /lib/fll/fll-init-cols
+
+###
+# define this for copy_exec
+###
+DESTDIR="/live-hack"
+
+if [ -f /proc/cmdline ]; then
+ for param in $(cat /proc/cmdline); do
+ case "${param}" in
+ flldebug=*)
+ [ "${param#flldebug=}" = "${NAME#fll-}" ] && set -x
+ ;;
+ noeject)
+ NOEJECT="1"
+ ;;
+ noprompt)
+ NOPROMPT="1"
+ ;;
+ esac
+ done
+fi
+
+###############################################################################
+# Adapted from initscripts: /etc/init.d/umountfs (2.86.ds1-38)
+###############################################################################
+# Print in order of decreasing length
+#
+# Algorithm: Find and print longest argument, then call self
+# to print remaining arguments in order of decreasing length
+#
+# This function runs at one tenth the speed of the sort program
+# but we use the function because we don't want to rely on any
+# programs in /usr/.
+#
+# N.B.: Arguments must not be null and must not contain whitespace
+#
+pioodl() {
+ [ "$1" ] || return 0
+
+ ARGNUM=1
+ ARGNUM_LONGEST=0
+ ARGLENGTH_LONGEST=0
+ for ARG in "$@"
+ do
+ ARGLENGTH="${#ARG}"
+ if [ "$ARGLENGTH" -gt "$ARGLENGTH_LONGEST" ]
+ then
+ ARGLENGTH_LONGEST="$ARGLENGTH"
+ ARGNUM_LONGEST="$ARGNUM"
+ fi
+ ARGNUM=$(($ARGNUM + 1))
+ done
+
+ # The method of passing prevargs assumes that args can be
+ # delimited with spaces
+ ARGNUM=1
+ PREVARGS=""
+ while [ "$ARGNUM" -lt "$ARGNUM_LONGEST" ]
+ do
+ PREVARGS="$PREVARGS $1"
+ shift
+ ARGNUM=$(($ARGNUM + 1))
+ done
+ echo "$1"
+ shift
+
+ pioodl $PREVARGS "$@"
+}
+
+do_umount() {
+ exec 9<&0 < /proc/mounts
+
+ REG_MTPTS=""
+ TMPFS_MTPTS=""
+ while read DEV MTPT FSTYPE OPTS REST
+ do
+ case "$MTPT" in
+ #
+ # live hack
+ #
+ /fll/*)
+ case "$FSTYPE" in
+ iso9660)
+ if [ "$MTPT" = /fll/fromiso ]; then
+ LIVE_MTPTS="$LIVE_MTPTS $MTPT"
+ else
+ LIVE_CDROM="$DEV"
+ fi
+ ;;
+ *)
+ LIVE_MTPTS="$LIVE_MTPTS $MTPT"
+ ;;
+ esac
+ continue
+ ;;
+ #
+ # live hack
+ #
+ /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/lib/init/rw)
+ continue
+ ;;
+ /var/run)
+ if [ yes = "$RAMRUN" ] ; then
+ continue
+ fi
+ ;;
+ /var/lock)
+ if [ yes = "$RAMLOCK" ] ; then
+ continue
+ fi
+ ;;
+ esac
+ case "$FSTYPE" in
+ proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
+ continue
+ ;;
+ #
+ # live hack
+ #
+ aufs|unionfs)
+ UNION_MTPTS="$UNION_MTPTS $MTPT"
+ ;;
+ squashfs)
+ SQUSH_MTPTS="$SQUSH_MTPTS $MTPT"
+ ;;
+ #
+ # live hack
+ #
+ tmpfs)
+ TMPFS_MTPTS="$TMPFS_MTPTS $MTPT"
+ ;;
+ *)
+ REG_MTPTS="$REG_MTPTS $MTPT"
+ ;;
+ esac
+ done
+
+ exec 0<&9 9<&-
+
+ #
+ # Make sure tmpfs file systems are umounted before turning off
+ # swap, to avoid running out of memory if the tmpfs filesystems
+ # use a lot of space.
+ #
+ if [ "$TMPFS_MTPTS" ]
+ then
+ TMPFS_MTPTS="$(pioodl $TMPFS_MTPTS)"
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Unmounting temporary filesystems"
+ umount $TMPFS_MTPTS
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now unmount temporary filesystems"
+ umount -v $TMPFS_MTPTS
+ log_end_msg $?
+ fi
+ fi
+
+ #
+ # Deactivate swap
+ #
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Deactivating swap"
+ swapoff -a >/dev/null
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now deactivate swap"
+ swapoff -a -v
+ log_end_msg $?
+ fi
+
+ #
+ # Unmount local filesystems
+ #
+ if [ "$REG_MTPTS" ]
+ then
+ REG_MTPTS="$(pioodl $REG_MTPTS)"
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Unmounting local filesystems"
+ umount -n -f -r -d $REG_MTPTS
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now unmount local filesystems"
+ umount -n -f -v -r -d $REG_MTPTS
+ log_end_msg $?
+ fi
+ fi
+
+ #
+ # live hack: any command after this point must be prefixed with ${BINDIR}
+ #
+ if [ "$UNION_MTPTS" ]
+ then
+ UNION_MTPTS="$(pioodl $UNION_MTPTS)"
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Unmounting union filesystems"
+ ${BINDIR}umount -l -n -f -d $UNION_MTPTS
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now unmount union filesystems"
+ ${BINDIR}umount -l -n -f -v -d $UNION_MTPTS
+ log_end_msg $?
+ fi
+ fi
+
+ if [ "$SQSH_MTPTS" ]
+ then
+ SQSH_MTPTS="$(pioodl $SQSH_MTPTS)"
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Unmounting squashfs filesystems"
+ ${BINDIR}umount -l -n -f -d $SQSH_MTPTS
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now unmount squashfs filesystems"
+ ${BINDIR}umount -l -n -f -v -d $SQSH_MTPTS
+ log_end_msg $?
+ fi
+ fi
+
+ if [ "$LIVE_MTPTS" ]
+ then
+ LIVE_MTPTS="$(pioodl $LIVE_MTPTS)"
+ if [ "$VERBOSE" = no ]
+ then
+ log_action_begin_msg "Unmounting live filesystems"
+ ${BINDIR}umount -l -n -f -d $LIVE_MTPTS
+ log_action_end_msg $?
+ else
+ log_daemon_msg "Will now unmount live filesystems"
+ ${BINDIR}umount -l -n -f -v -d $LIVE_MTPTS
+ log_end_msg $?
+ fi
+ fi
+
+ if [ "$LIVE_CDROM" ]; then
+ export LIVE_CDROM
+ fi
+}
+###############################################################################
+# Adapted from initramfs-tools hook-functions (0.87b)
+###############################################################################
+# $1 is source
+# $2 is relative destination
+copy_exec() {
+ local verbose="${VERBOSE}"
+ local final_destination=${DESTDIR}/${2}/`basename ${1}`
+
+ if [ -L "$final_destination" ]; then
+ if ! [ `readlink ${final_destination}` = "${1}" ]; then
+ return
+ fi
+ else
+ cp ${1} ${DESTDIR}/${2}
+ if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then
+ echo "Adding binary ${1}"
+ fi
+ fi
+
+ # Copy the dependant libraries
+ for x in $(ldd ${1} 2>/dev/null | sed -e '
+ /\//!d;
+ /linux-gate/d;
+ /=>/ {s/.*=>[[:blank:]]*\([^[:blank:]]*\).*/\1/};
+ s/[[:blank:]]*\([^[:blank:]]*\) (.*)/\1/' 2>/dev/null); do
+
+ # Try to use non-optimised libraries where possible.
+ # We assume that all HWCAP libraries will be in tls.
+ nonoptlib=$(echo ${x} | sed -e 's#/lib/tls.*/\(lib.*\)#/lib/\1#')
+
+ if [ -e ${nonoptlib} ]; then
+ x=${nonoptlib}
+ fi
+
+ libname=$(basename ${x})
+ dirname=$(dirname ${x})
+
+ mkdir -p ${DESTDIR}/${dirname}
+ if [ ! -e ${DESTDIR}/${dirname}/${libname} ]; then
+ cp ${x} ${DESTDIR}/${dirname}
+ if [ -n "${verbose}" ] && [ "${verbose}" = "y" ]; then
+ echo "Adding library ${x}"
+ fi
+ fi
+ done
+}
+###############################################################################
+# End adapted functions
+###############################################################################
+
+live_hack() {
+ mkdir -p ${DESTDIR}/bin
+ copy_exec /bin/umount /bin
+ copy_exec /sbin/halt /bin
+ copy_exec /sbin/reboot /bin
+ copy_exec /usr/bin/eject /bin
+
+ LD_LIBRARY_PATH="${DESTDIR}/lib"
+ if [ -e "${DESTDIR}/lib64" ]; then
+ LD_LIBRARY_PATH="${DESTDIR}/lib64:${LD_LIBRARY_PATH}"
+ fi
+ export LD_LIBRARY_PATH
+
+ LD_LINUX="${DESTDIR}/lib/ld-linux.so.2"
+ if [ -e "${DESTDIR}/lib64/ld-linux-x86-64.so.2" ]; then
+ LD_LINUX="${DESTDIR}/lib64/ld-linux-x86-64.so.2"
+ fi
+ export LD_LINUX
+
+ PATH="${DESTDIR}/bin:${PATH}"
+ export PATH
+
+ BINDIR="${LD_LINUX} ${DESTDIR}/bin/"
+ export BINDIR
+}
+
+pop_live_cd()
+{
+ if [ -z "${LIVE_CDROM}" ] || [ "${NOEJECT}" ]; then
+ return 0
+ fi
+
+ #
+ # disable kernel messages while ejecting cdrom (libata noise)
+ #
+ echo "0" > /proc/sys/kernel/printk
+
+ if [ -b "${LIVE_CDROM}" ]; then
+ ${BINDIR}eject -m -p ${LIVE_CDROM}
+ fi
+
+ echo "6" > /proc/sys/kernel/printk
+
+ if [ -z "${NOPROMPT}" ]; then
+ echo "${Y}Please remove CD, close cdrom drive and hit return.${N}" > /dev/console
+ read
+ fi
+}
+
+do_stop() {
+ local command message options
+
+ # prepare binaries for post-umount of live media
+ live_hack
+ # umount the live media and other mount points
+ do_umount
+
+ case "${0}" in
+ *halt)
+ message="${G}${FLL_DISTRO_SNAME} halted.${N}"
+ command="halt"
+ options="-h -n -p -i -f"
+ ;;
+ *reboot)
+ message="${G}Preparing for reboot...${N}"
+ command="reboot"
+ options="-n -i -f"
+ ;;
+ *)
+ echo "${0}: call this script as \"halt\" or \"reboot\" please!"
+ exit 1
+ ;;
+ esac
+
+ echo "${message}" > /dev/console
+
+ pop_live_cd
+
+ exec ${BINDIR}${command} ${options} > /dev/console 2>&1 < /dev/console
+}
+
+case "${1}" in
start)
+ # no-op
+ ;;
+ restart|reload|force-reload)
+ echo "Error: argument '${1}' not supported" >&2
+ exit 3
;;
stop)
+ # live-hack, umount and eject
+ do_stop
;;
- restart|force-reload)
+ *)
+ echo "Usage: ${NAME} {start|stop}" >&2
+ exit 3
;;
esac
-
-# Clean input/output
-exec > /dev/console 2>&1 < /dev/console
-
-NORMAL="[0;39m"
-RED="[1;31m"
-GREEN="[1;32m"
-YELLOW="[1;33m"
-BLUE="[1;34m"
-MAGENTA="[1;35m"
-CYAN="[1;36m"
-WHITE="[1;37m"
-
-case "$0" in
- *halt)
- message="${YELLOW}${FLL_DISTRO_NAME} halted.${NORMAL}"
- command="halt"
- options="-p -d -i -f"
- ;;
- *reboot)
- message="${GREEN}Preparing for reboot...${NORMAL}"
- command="reboot"
- options="-d -i -f"
- ;;
- *)
- echo "$0: call this script as \"halt\" or \"reboot\" please!"
- exit 1
- ;;
-esac
-
-# No sync and no wtmp entry if running from CD
-options="$options -n"
-
-mysleep()
-{
- for i in $(seq 1 40); do
- sleep "0.075s"
- echo -n "$1.${NORMAL}"
- done
- echo ""
-}
-
-# Disable kernel messages
-echo "0" > /proc/sys/kernel/printk
-
-# poweroff pcmcia devices
-if lsmod | grep -q pcmcia_core 2>&1 > /dev/null; then
- echo -n "${BLUE}Shutting down PCMCIA devices...${NORMAL}"
- pccardctl eject 2>&1 > /dev/null
- sleep 2
- echo ""
-fi
-
-# Now kill them all
-killall5 -15
-sleep 1
-echo -n "${BLUE}Sent all processes the TERM signal...${NORMAL}"
-mysleep "$BLUE"
-
-killall5 -9
-sleep 1
-echo -n "${RED}Sent all processes the KILL signal...${NORMAL}"
-mysleep "$RED"
-
-# Unmount network filesystems first before shutting down network
-NETMOUNTS="$(awk '{if($1~/:/){print $2}}' /proc/mounts 2> /dev/null)"
-if [ -n "$NETMOUNTS" ]; then
- echo "${BLUE}Unmounting network filesystems.${NORMAL}"
- umount -t nfs -arvf 2> /dev/null
-fi
-
-# Shutdown network
-NETDEVICES="$(awk -F: '/ath.:|eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>/dev/null)"
-if [ -n "$NETDEVICES" ]; then
- pidof pump 2>&1 > /dev/null && { pump -k ; sleep 2; }
- echo -n "${BLUE}Shutting down network device${NORMAL}"
- for n in $NETDEVICES; do
- echo -n " ${MAGENTA}$n${NORMAL}"
- ifconfig "$n" down
- done
- echo ""
-fi
-
-# read cmdline params
-NOEJECT=""
-NOPROMPT=""
-read CMDLINE <<EOT
-$(cat /proc/cmdline 2> /dev/null)
-EOT
-case "$CMDLINE" in *noeject*) NOEJECT="yes"; ;; esac
-case "$CMDLINE" in *noprompt*) NOPROMPT="yes"; ;; esac
-
-CDROM="$(awk '/ \/cdrom /{print $1;exit 0;}' /proc/mounts)"
-
-# This uses standard sysvinit
-FINALCMD="/etc/live-hack/$command"
-rm -rf /etc/live-hack 2>&1 > /dev/null
-mkdir -p /etc/live-hack
-[ -x "/etc/live-hack/$command" ] || cp -p "/sbin/$command" /etc/live-hack/
-[ -x /usr/bin/eject ] && cp -p /usr/bin/eject /etc/live-hack/eject
-LD_LINUX=ld-linux.so.2
-[ -x /lib/ld-linux-x86-64.so.2 ] && LD_LINUX=ld-linux-x86-64.so.2
-[ -x "/etc/live-hack/$LD_LINUX" ] || cp -p "/lib/$LD_LINUX" /etc/live-hack/
-
-# Turn off swap, then unmount file systems.
-swapoff -a 2>&1 > /dev/null
-
-echo "${BLUE}Unmounting file systems.${NORMAL}"
-
-cd /
-
-# Umount everything but root
-umount -arvf 2> /dev/null
-if [ "$?" != "0" ] ; then
- # Free loopback devices if necessary, so we can unmount the host media
- for i in /dev/loop*; do losetup -d "$i" 2> /dev/null; done
- # And retry
- umount -arf 2> /dev/null
-fi
-
-# Remove remaining unused modules
-rmmod -a 2>&1 > /dev/null
-
-echo "$message" > /dev/console
-
-# eject CD-ROM, noprompt implies noeject (backward compatibility)
-if [ -z "$NOPROMPT" ]; then
- [ -n "$CDROM" -a -z "$NOEJECT" ] && "/etc/live-hack/$LD_LINUX" /etc/live-hack/eject -m -p "$CDROM" 2>&1 >/dev/null
- echo "${CYAN}Please remove CD, close cdrom drive and hit return.${NORMAL}"
- read
-fi
-
-# Now halt or reboot.
-exec "/etc/live-hack/$LD_LINUX" "$FINALCMD" $options > /dev/console 2>&1 < /dev/console
-
More information about the Parsix-Devel
mailing list