You are not logged in.

#1 2004-12-04 22:12:40

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Alternate ctrl alt del behavior

I've wirtten a script to be used instead of "shutdown -t -r now" in inittab.

If you are in runlevel 3 or 5:
When you pres ctrl + alt del it will reboot.
If you press ctrlaltdel within next 3 seconds the computer will halt
if you press ctrlaltdel within next 3 seconds the halt will be cancelled. nothing will happen.

If you are in another runlevel the computer will reboot.

Whenever the computer is rebooting or halting you can press ctrlaltdel to cancel the shutdown and restore previous runlevel.

the file must be named /sbin/controlaltdel

#!/bin/bash

if [ "$1" != "background" ]; then
    /sbin/controlaltdel background &
    exit
fi

ecoeco (){
    /bin/echo -e '33[1;33m'$1'33[0m'
}

init6 (){
    ecoeco 'We are on init '${RUNLEV[$ACTUAL]}': Rebooting in 3 seconds...'
    /bin/touch /tmp/rebooting
    /usr/bin/sleep 3
    if [ -f /tmp/rebooting ]; then
        /bin/rm /tmp/rebooting
        /sbin/shutdown -t3 -r now
    fi
}

ecoeco '33[1;32mControl + Alt + Del has been pressed...'

ACTUAL=1
PREVIOUS=0

for i in $(runlevel); do
    if [ "$RUNLEV" = "" ]; then
        RUNLEV[$PREVIOUS]=$i
    else
        RUNLEV[$ACTUAL]=$i
    fi
done

if [ -f /tmp/rebooting ]; then
    ecoeco '33[1;31mWe were going to reboot: Shutting down in 3 seconds...'
    /bin/rm /tmp/rebooting
    /bin/touch /tmp/halting
    /usr/bin/sleep 3
    if [ -f /tmp/halting ]; then
        /bin/rm /tmp/halting
        /sbin/shutdown -t3 -h now
    fi
elif [ -f /tmp/halting ]; then
    ecoeco '33[1;34mWe were going to halt: Cancelled.'
    /bin/rm /tmp/halting
elif [ "${RUNLEV[$ACTUAL]}" = "5" ]; then
    init6
elif [ "${RUNLEV[$ACTUAL]}" = "3" ]; then
    init6
elif [ "${RUNLEV[$ACTUAL]}" = "6" ]; then
    ecoeco '33[1;34mWe are on init 6: restoring previous init ('${RUNLEV[$PREVIOUS]}')'
    /sbin/init ${RUNLEV[$PREVIOUS]}
elif [ "${RUNLEV[$ACTUAL]}" = "0" ]; then
    ecoeco '33[1;34mWe are on init 0: restoring previous init ('${RUNLEV[$PREVIOUS]}')'
    /sbin/init ${RUNLEV[$PREVIOUS]}
else
    ecoeco 'Unknown situation: rebooting...'
    shutdown -t3 -r now
fi

Offline

#2 2004-12-04 22:15:12

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: Alternate ctrl alt del behavior

It was originally in catalan. Maybe something went wrong while translating. I cannot reboot my computer right now. If something's wrong please tell me.

Offline

#3 2004-12-04 22:54:46

IceRAM
Member
From: Bucharest, Romania
Registered: 2004-03-04
Posts: 772
Website

Re: Alternate ctrl alt del behavior

Thanks.
Might be better if you'd put it in the Wiki.

Offline

#4 2004-12-04 23:47:31

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: Alternate ctrl alt del behavior

My english not so good, but I encouraged myself to post in the wiki and i've found that i cannot write brackets [ ] in the wiki. How should I scape them?

Offline

Board footer

Powered by FluxBB