Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ 1 2 3 [4] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: CD-eject after shutdown., How do I disable it?< Next Oldest | Next Newest >
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: June 15 2006,17:59 QUOTE

Ok. finally I managed to bypass the "press any kay to continue" -phase.

Code Sample
#!/bin/sh
#/etc/init.d/knoppix-reboot

PATH=/sbin:/bin:/usr/bin:/usr/sbin
export PATH

exec >/dev/console 2>&1 </dev/console

NORMAL=""
RED=""
GREEN=""
YELLOW=""
BLUE=""
MAGENTA=""
CYAN=""
WHITE=""

stringinstring(){
 case "$2" in *$1*) return 0;; esac
 return 1
}

INSTALLED=""
TORAM=""
FRUGAL=""
[ -e /KNOPPIX/bin/ash ] || INSTALLED=yes

if [ -e /etc/sysconfig/toram ]; then
 INSTALLED=yes
 TORAM=yes
fi
if [ -e /etc/sysconfig/frugal ]; then
 INSTALLED=yes
 FRUGAL=yes
fi

case "$0" in
 *halt)
message="
${YELLOW}DSL halted.${NORMAL}"
command="halt"
options="-p -d -i -f"
;;
 *reboot)
message="${GREEN}Preparing for reboot...${NORMAL}"
command="reboot"
options="-r -d -i -f"
;;
 *)
echo "$0: call this script as \"halt\" or \"reboot\" please!"
exit 1
;;
esac

[ -n "$INSTALLED" ] || options="$options -n"

mysleep() {
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
do
usleep 75000
echo -n "$1.${NORMAL}"
done
echo ""
}

if [ -x /opt/powerdown.sh ]; then
 /opt/powerdown.sh
fi

echo "0" > /proc/sys/kernel/printk

if pidof cardmgr >/dev/null 2>&1; then
echo -n "${BLUE}Shutting down PCMCIA devices...${NORMAL}"
cardctl eject >/dev/null 2>&1
sleep 2
echo ""
fi

killall5 -15
sleep 2
echo -n "${BLUE}Sent all processes the TERM signal...${NORMAL}"
mysleep "$BLUE"

killall5 -9
sleep 2
echo -n "${RED}Sent all processes the KILL signal...${NORMAL}"
mysleep "$RED"

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

NETDEVICES="$(awk -F: '/eth.:/{print $1}' /proc/net/dev 2>/dev/null)"
if [ -n "$NETDEVICES" ]; then
pidof pump >/dev/null 2>&1 && { 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

NOPROMPT=""
read CMDLINE <<EOT
$(cat /proc/cmdline 2>/dev/null)
EOT
case "$CMDLINE" in *noprompt*) NOPROMPT="yes";;; esac
FINALCMD="/sbin/$command"
if [ -z "$INSTALLED" -a -z "$NOPROMPT" ]; then
[ -x /etc/init ] || cp -p /sbin/init /etc/
[ -x /etc/init ] && FINALCMD="/etc/init"
fi

if [ -n "$FRUGAL" ]; then
  stringinstring "KNOPPIX" "$FINALCMD" || FINALCMD="/KNOPPIX$FINALCMD"
fi
if [ -n "$TORAM" ]; then
  stringinstring "KNOPPIX" "$FINALCMD" || FINALCMD="/KNOPPIX$FINALCMD"
fi

swapoff -a >/dev/null 2>&1

echo "${BLUE}Unmounting file systems.${NORMAL}"
NOEJECT="yes"
read CMDLINE <<EOT
$(cat /proc/cmdline 2>/dev/null)
EOT
case "$CMDLINE" in *noeject*) NOEJECT="yes";;; esac
for dev in /proc/sys/dev/cdrom*/lock; do [ -f "$dev" ] && echo 0 > "$dev"; done
if [ -z "$NOEJECT" ]; then
for dev in /proc/sys/dev/cdrom*/autoeject; do [ -f "$dev" ] && echo 1 > "$dev"; done
fi


cd /

umount -arvf 2>/dev/null
if [ "$?" != "0" ]; then
for i in /dev/loop*; do losetup -d $i 2>/dev/null; done
umount -arf 2>/dev/null
fi

rmmod -a >/dev/null 2>&1

[ -n "$INSTALLED" ] && mount -o remount,ro / 2>/dev/null

echo "$message" >/dev/console

if [ -z "$INSTALLED" ]; then
 # echo -n "${CYAN}Wait for CD to eject, then remove CD, close cdrom drive and press enter.${NORMAL}"
 echo "${CYAN}No CD eject when rebooting.${NORMAL}"
fi

case "$0" in
 *halt)
 exec $FINALCMD $options 2>/dev/null
 ;;
 *reboot)
 echo "Executing \"${RED}$FINALCMD $options${NORMAL}\"."
 $FINALCMD $options
 ;;
esac


I don't know what 2>/dev/null does, but I tested and leaving it was the solution...
Ok It's not the best wat to bypass it but it worked on my Compac Armada E500.

It tries to unmount cd two times. At the third time it gives up and tells you to reset. My laptop reseted automatically. There might be cases where you must do it manually.

Anyone care to test?


--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: June 15 2006,20:13 QUOTE

2>/dev/null nullifies any error messages sent by the preceding command.  It's done here simply to give the user a false sense of calm and to confuse him when something goes wrong =o).

A more suitable use for it would be when setting a variable from the output of a command, when the only time you want that variable to have a value is if the command succeeds.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
Zucca Offline





Group: Members
Posts: 524
Joined: Feb. 2006
Posted: June 19 2006,02:29 QUOTE

Ok. Then it must be the exec command...

--------------
Do you have it? - http://dy.fi/mak
Back to top
Profile PM WEB ICQ MSN 
17 replies since June 12 2006,08:19 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ 1 2 3 [4] >/
reply to topic new topic new poll
Quick Reply: CD-eject after shutdown.

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code