From 6eb00db5626b397e11eaee9bdd6f35f6b2b61f8b Mon Sep 17 00:00:00 2001 From: "Casper Ti. Vector" Date: Thu, 23 Aug 2012 12:46:18 +0800 Subject: [PATCH] Convert Gentoo-specific code to more universal form. --- src/cdm | 21 ++++++++++++++++----- src/cdm-xlaunch | 15 +++++++++------ src/cdmrc | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/cdm b/src/cdm index cfb21f2..d90ca42 100755 --- a/src/cdm +++ b/src/cdm @@ -33,12 +33,23 @@ longname='Console Display Manager' ver='0.6' trap '' SIGINT SIGTSTP -source /etc/init.d/functions.sh -# Exit functions. +# Helper functions. +warn() { printf ' \033[01;33m*\033[00m '; echo "$name: $*" > /dev/stderr; } +error() { printf ' \033[01;31m*\033[00m '; echo "$name: $*" > /dev/stderr; } exitnormal() { exit 0; } exiterror() { sleep 1; exit 1; } +yesno() +{ + [ -z "$1" ] && return 1 + + case "$1" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + *) warn "\`$1' is not a valid argument for \`yesno'; using \`no' for now." + esac +} # Source cdm configurations. @@ -47,7 +58,7 @@ if [[ -n "$1" ]]; then then source "$1" else - eerror "$name: config file \`$1' does not exist." + error "config file \`$1' does not exist." exiterror fi elif [[ -f "$HOME/.cdmrc" ]]; then @@ -146,13 +157,13 @@ case ${flaglist[$binindex]} in $(yesno consolekit) && launchflags="-c -t $cktimeout" if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then - ewarn "$name: \`cdm-xlaunch' exited unsuccessfully." + warn "\`cdm-xlaunch' exited unsuccessfully." exiterror fi ;; *) - eerror "$name: unknown flag: \`${flaglist[$binindex]}'." + error "unknown flag: \`${flaglist[$binindex]}'." exiterror ;; esac diff --git a/src/cdm-xlaunch b/src/cdm-xlaunch index 75b1423..8ea553c 100755 --- a/src/cdm-xlaunch +++ b/src/cdm-xlaunch @@ -31,7 +31,9 @@ name=$(basename "$0") consolekit=false cktimeout=30 -source /etc/init.d/functions.sh + +info() { printf ' \033[01;32m*\033[00m '; echo "$name: $*"; } +error() { printf ' \033[01;31m*\033[00m '; echo "$name: $*" > /dev/stderr; } args=$(getopt -n "$name" -o ct: -l consolekit,timeout: -- "$@") || exit 1 eval set -- "$args" @@ -54,11 +56,11 @@ done # Do first to avoid race conditions. if $consolekit; then - ebegin "$name: waiting for ConsoleKit to register X session" + info "waiting for ConsoleKit to register X session." sleep "$cktimeout" & clockpid=$! dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX) if ! mkfifo "$dbuspidfifo"; then - eend "$name: failed to create FIFO \`$fifo'." + error "failed to create FIFO \`$fifo'." exit 1 fi @@ -77,16 +79,17 @@ fi # Conform to POSIX and do not use `>&' here. sh -i -c "(startx $* > /dev/null 2>&1 &)" -# If wait(1) returns with a value >128, it was interrupted by kill(1), so registration was sucessful. +# If wait(1) returns with a value >128, it was interrupted by kill(1), so +# registration was sucessful. if [[ -n "$clockpid" ]]; then if wait "$clockpid" >& /dev/null then kill "$dbuspid" - eend "$name: ConsoleKit registration timed out." + error "ConsoleKit registration timed out." exit 1 else kill "$dbuspid" - eend 0 + info "ConsoleKit registration succeeded." exit 0 fi fi diff --git a/src/cdmrc b/src/cdmrc index bd7c689..067bbed 100644 --- a/src/cdmrc +++ b/src/cdmrc @@ -38,7 +38,7 @@ countfrom=0 # Set default display. display=0 -# Where should first X tty be spawned? +# Where should the first X tty be spawned? xtty=7 # Should cdm(1) stick to the specified display?