From d4a5c5ef402ca7315e5429eaccb0748e38b964af Mon Sep 17 00:00:00 2001 From: Judd Vinet Date: Thu, 19 Feb 2004 18:50:09 +0000 Subject: added cleanups by Leif Askeland --- functions | 80 ++++++++++++++++++++++++++++++++----------------------------- rc.shutdown | 28 ++++++---------------- rc.single | 9 ++----- rc.sysinit | 21 +++++----------- 4 files changed, 57 insertions(+), 81 deletions(-) diff --git a/functions b/functions index 8425b2e..ec3e986 100644 --- a/functions +++ b/functions @@ -5,38 +5,57 @@ STAT_COL=$[`stty size | awk 'BEGIN { RS=" " }; END { print $1 }'` - 13] +# colors: + +if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then + + C_MAIN="\033[1;37m" # main text + C_OTHER="\033[1;34m" # prefix & brackets + C_SEPARATOR="\033[1;30m" # separator + + C_BUSY="\033[0;36m" # busy + C_FAIL="\033[1;31m" # failed + C_DONE="\033[1;37m" # completed + + C_H1="\033[1;37m" # highlight text 1 + C_H2="\033[1;36m" # highlight text 2 + + C_CLEAR="\033[1;0m" +fi + +# prefixes: + +PREFIX_REG="::" +PREFIX_HL=" >" + +# functions: + deltext() { echo -ne "\033[$(($STAT_COL+4))G" } +printhl() { + echo -e "$C_OTHER$PREFIX_HL $C_H1$1$C_CLEAR " +} + +printsep() { + echo -e "\n$C_SEPARATOR ------------------------------\n" +} + stat_busy() { - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -ne "\033[1;32m| \033[1;37m$1\033[1;0m " - awk "BEGIN { for (j=length(\"$1\"); j<$STAT_COL; j++) printf \" \" }" - echo -ne " \033[1;34m[\033[1;33mbusy\033[1;34m]\033[1;0m " - else - echo -n "| $1 " - awk "BEGIN { for (j=length(\"$1\"); j<$STAT_COL; j++) printf \" \" }" - echo -n " [busy] " - fi + echo -ne "$C_OTHER$PREFIX_REG $C_MAIN$1$C_CLEAR " + deltext + echo -ne " $C_OTHER[${C_BUSY}BUSY$C_OTHER]$C_CLEAR " } stat_done() { deltext - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e " \033[1;34m[\033[1;32mdone\033[1;34m] \033[1;0m" - else - echo " [done] " - fi + echo -e " $C_OTHER[${C_DONE}DONE$C_OTHER]$C_CLEAR " } stat_fail() { deltext - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e " \033[1;34m[\033[1;31mfail\033[1;34m] \033[1;0m" - else - echo " [fail] " - fi + echo -e " $C_OTHER[${C_FAIL}FAIL$C_OTHER]$C_CLEAR " } stat_die() { @@ -46,20 +65,6 @@ stat_die() { exit $retval } -# -# here for legcay reasons: use 'status' instead -# -checkret() { - $* >/dev/null 2>&1 - if [ $? -gt 0 ]; then - stat_fail - return 0 - else - stat_done - return 1 - fi -} - status() { stat_busy "$1" shift @@ -73,6 +78,8 @@ status() { fi } +# daemons: + add_daemon() { [ -d /var/run/daemons ] || mkdir -p /var/run/daemons touch /var/run/daemons/$1 @@ -83,11 +90,8 @@ rm_daemon() { } ck_daemon() { - if [ -f /var/run/daemons/$1 ]; then - return 1 - else - return 0 - fi + [ -f /var/run/daemons/$1 ] && return 1 + return 0 } # End of file diff --git a/rc.shutdown b/rc.shutdown index 4f6b6d6..9bf8c2d 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -9,13 +9,9 @@ # avoid staircase effect /bin/stty onlcr -if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\033[1;32m| \033[1;37mInitiating Shutdown...\033[1;0m" - echo -e "\033[1;32m|\033[1;0m" -else - echo "| Initiating Shutdown..." - echo "|" -fi +echo " " +printhl "Initiating Shutdown..." +echo " " if [ "$PREVLEVEL" = "3" -o "$PREVLEVEL" = "5" ]; then # Shutdown daemons @@ -74,22 +70,12 @@ stat_done # Power off or reboot if [ "$RUNLEVEL" = "0" ]; then - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\033[1;32m|\033[1;0m" - echo -e "\033[1;31m| \033[1;33mPOWER OFF\033[1;0m" - else - echo "|" - echo "| POWER OFF" - fi + printsep + printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -i else - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\033[1;32m|\033[1;0m" - echo -e "\033[1;31m| \033[1;33mREBOOTING\033[1;0m" - else - echo "|" - echo "| REBOOTING" - fi + printsep + printhl "${C_H2}REBOOTING.." /sbin/reboot -d -f -i fi diff --git a/rc.single b/rc.single index 3b0e610..b826959 100755 --- a/rc.single +++ b/rc.single @@ -41,13 +41,8 @@ if [ "$PREVLEVEL" != "N" ]; then fi if [ "$RUNLEVEL" = "1" ]; then - if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\033[1;32m|\033[1;0m" - echo -e "\033[1;31m| \033[1;33mEntering single-user mode...\033[1;0m" - else - echo "|" - echo "| Entering single-user mode..." - fi + printsep + printhl "Entering single-user mode..." exec /sbin/init -t1 S fi diff --git a/rc.sysinit b/rc.sysinit index a5f5f78..6c21182 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -6,21 +6,12 @@ . /etc/rc.conf . /etc/rc.d/functions -if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then - echo -e "\n\033[1;32mArch Linux v0.6 \033[1;37m(\033[1;33mWidget\033[1;37m)" - echo -e "\033[1;32m|\033[1;0m" - echo -e "\033[1;32m|\033[1;37m http://www.archlinux.org\033[1;0m" - echo -e "\033[1;32m|\033[1;0m Copyright 2002-2004 Judd Vinet" - echo -e "\033[1;32m|\033[1;0m Distributed under the GNU General Public License (GPL)" - echo -e "\033[1;32m|\033[1;0m" -else - echo -e "\nArch Linux v0.6 (Widget)" - echo "|" - echo "| http://www.archlinux.org" - echo "| Copyright 2002-2003 Judd Vinet" - echo "| Distributed under the GNU General Public License (GPL)" - echo "|" -fi +echo " " +printhl "Arch Linux v0.6 $C_OTHER(${C_H2}Widget$C_OTHER)\n" +printhl "${C_H2}http://www.archlinux.org" +printhl "Copyright 2002-2004 Judd Vinet" +printhl "Distributed under the GNU General Public License (GPL)" +printsep # start up our mini logger until syslog takes over /sbin/minilogd -- cgit v1.2.3