after discussion - use spaces instead of tabs

This commit is contained in:
Jakub Klinkovský 2012-09-12 19:30:38 +02:00
parent 277ed46ee8
commit 1bb3691d37
3 changed files with 136 additions and 136 deletions

182
src/cdm
View File

@ -42,30 +42,30 @@ exitnormal() { exit 0; }
exiterror() { sleep 1; exit 1; } exiterror() { sleep 1; exit 1; }
yesno() yesno()
{ {
[ -z "$1" ] && return 1 [ -z "$1" ] && return 1
eval value=\$${1} eval value=\$${1}
case "$value" in case "$value" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; [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;; [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;;
*) warn "Invalid value for \`$1'; falling back to \`no' for now.";; *) warn "Invalid value for \`$1'; falling back to \`no' for now.";;
esac esac
} }
# Source cdm configurations. # Source cdm configurations.
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
if [[ -f "$1" ]] if [[ -f "$1" ]]
then then
source "$1" source "$1"
else else
error "config file \`$1' does not exist." error "config file \`$1' does not exist."
exiterror exiterror
fi fi
elif [[ -f "$HOME/.cdmrc" ]]; then elif [[ -f "$HOME/.cdmrc" ]]; then
source "$HOME/.cdmrc" source "$HOME/.cdmrc"
elif [[ -f /etc/cdmrc ]]; then elif [[ -f /etc/cdmrc ]]; then
source /etc/cdmrc source /etc/cdmrc
fi fi
# Default options. # Default options.
@ -86,103 +86,103 @@ cktimeout=${cktimeout:-30}
# if binlist if not explicitly set in cdmrc. # if binlist if not explicitly set in cdmrc.
if [[ "${#binlist[@]}" == 0 ]]; then if [[ "${#binlist[@]}" == 0 ]]; then
binlist=($(ls /etc/X11/Sessions)) binlist=($(ls /etc/X11/Sessions))
flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!flaglist[*]})) flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!flaglist[*]}))
namelist=(${binlist[@]^}) namelist=(${binlist[@]^})
fi fi
# Generate the main menu. # Generate the main menu.
menu=() menu=()
for ((count = 0; count < ${#namelist[@]}; count++)); do for ((count = 0; count < ${#namelist[@]}; count++)); do
menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}") menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}")
done done
# Override dialog display if only one option is available. # Override dialog display if only one option is available.
if [[ "$count" == 1 ]]; then if [[ "$count" == 1 ]]; then
binindex=0 binindex=0
else else
# Display selection dialog. # Display selection dialog.
binindex=$( binindex=$(
DIALOGRC="$dialogrc" dialog --colors --stdout \ DIALOGRC="$dialogrc" dialog --colors --stdout \
--backtitle "${longname} v${ver}" \ --backtitle "${longname} v${ver}" \
--ok-label ' Select ' --cancel-label ' Exit ' \ --ok-label ' Select ' --cancel-label ' Exit ' \
--menu 'Select session' 0 0 0 "${menu[@]}" --menu 'Select session' 0 0 0 "${menu[@]}"
) )
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
clear clear
exitnormal exitnormal
fi fi
fi fi
# Run $bin according to its flag. # Run $bin according to its flag.
let binindex-=countfrom let binindex-=countfrom
bin="${binlist[${binindex}]}" bin="${binlist[${binindex}]}"
case ${flaglist[$binindex]} in case ${flaglist[$binindex]} in
# *C*onsole programs. # *C*onsole programs.
[Cc]) [Cc])
clear clear
# If $bin is a login shell, it might `exec' cdm again, causing an endless # If $bin is a login shell, it might `exec' cdm again, causing an endless
# loop. To solve this problem, export $CDM_SPAWN when `exec'ing $bin and # loop. To solve this problem, export $CDM_SPAWN when `exec'ing $bin and
# only let the shell automatically `exec' cdm when $CDM_SPAWN is not set. # only let the shell automatically `exec' cdm when $CDM_SPAWN is not set.
# See also the example shell profile file shipped with the cdm package. # See also the example shell profile file shipped with the cdm package.
CDM_SPAWN=$$ exec $bin CDM_SPAWN=$$ exec $bin
;; ;;
# *X* programs. # *X* programs.
[Xx]) [Xx])
clear clear
# If X is already running and locktty=yes, activate it # If X is already running and locktty=yes, activate it
if $(yesno locktty); then if $(yesno locktty); then
if xdpyinfo -display ":$display.0" &> /dev/null; then if xdpyinfo -display ":$display.0" &> /dev/null; then
chvt "$((display+xtty))" chvt "$((display+xtty))"
exitnormal exitnormal
fi fi
fi fi
# Get the first empty display. # Get the first empty display.
display=0 display=0
while ((display < 7)); do while ((display < 7)); do
if dpyinfo=$(xdpyinfo -display ":$display.0" 2>&1 1>/dev/null) || if dpyinfo=$(xdpyinfo -display ":$display.0" 2>&1 1>/dev/null) ||
# Display is in use by another user. # Display is in use by another user.
[[ "$dpyinfo" == 'No protocol specified'* ]] || [[ "$dpyinfo" == 'No protocol specified'* ]] ||
# Invalid MIT cookie. # Invalid MIT cookie.
[[ "$dpyinfo" == 'Invalid MIT'* ]] [[ "$dpyinfo" == 'Invalid MIT'* ]]
then then
let display+=1 let display+=1
else else
break break
fi fi
done done
# run X in current tty # run X in current tty
if [[ $xtty == "keep" ]]; then if [[ $xtty == "keep" ]]; then
vt=$(tty) vt=$(tty)
vt=${vt#/dev/} vt=${vt#/dev/}
if [[ $vt != tty* ]]; then if [[ $vt != tty* ]]; then
error "error: invalid TTY" error "error: invalid TTY"
exiterror exiterror
fi fi
vt=${vt#tty} vt=${vt#tty}
else else
vt=$((xtty+display)) vt=$((xtty+display))
fi fi
serverargs=":${display} $serverargs vt$vt" serverargs=":${display} $serverargs vt$vt"
$(yesno consolekit) && launchflags="-c -t $cktimeout" $(yesno consolekit) && launchflags="-c -t $cktimeout"
if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then
warn "\`cdm-xlaunch' exited unsuccessfully." warn "\`cdm-xlaunch' exited unsuccessfully."
exiterror exiterror
else else
exitnormal exitnormal
fi fi
;; ;;
*) *)
error "unknown flag: \`${flaglist[$binindex]}'." error "unknown flag: \`${flaglist[$binindex]}'."
exiterror exiterror
;; ;;
esac esac
# vim:set ts=4 sw=4 noet: # vim:set ts=4 sw=4 et:

View File

@ -39,41 +39,41 @@ args=$(getopt -n "$name" -o ct: -l consolekit,timeout: -- "$@") || exit 1
eval set -- "$args" eval set -- "$args"
for arg in "$@" for arg in "$@"
do do
case $arg in case $arg in
'--consolekit' | '-c') '--consolekit' | '-c')
consolekit=true; shift consolekit=true; shift
;; ;;
'--timeout' | '-t') '--timeout' | '-t')
shift shift
cktimeout=$1; shift cktimeout=$1; shift
;; ;;
'--') '--')
shift shift
break break
;; ;;
esac esac
done done
# Do first to avoid race conditions. # Do first to avoid race conditions.
if $consolekit; then if $consolekit; then
info "waiting for ConsoleKit to register X session." info "waiting for ConsoleKit to register X session."
sleep "$cktimeout" & clockpid=$! sleep "$cktimeout" & clockpid=$!
dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX) dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX)
if ! mkfifo "$dbuspidfifo"; then if ! mkfifo "$dbuspidfifo"; then
error "failed to create FIFO \`$fifo'." error "failed to create FIFO \`$fifo'."
exit 1 exit 1
fi fi
(dbus-monitor --system 'type=signal,interface=org.freedesktop.ConsoleKit.Seat,member=SessionAdded' & echo $! > "$dbuspidfifo") | (dbus-monitor --system 'type=signal,interface=org.freedesktop.ConsoleKit.Seat,member=SessionAdded' & echo $! > "$dbuspidfifo") |
sed -un 's@[[:space:]]*object path \"\(/[a-zA-Z0-9/]*\)\"@\1@p' | while read object; do sed -un 's@[[:space:]]*object path \"\(/[a-zA-Z0-9/]*\)\"@\1@p' | while read object; do
if dbus-send --system --print-reply --dest='org.freedesktop.ConsoleKit' "$object" 'org.freedesktop.ConsoleKit.Session.GetX11Display' | if dbus-send --system --print-reply --dest='org.freedesktop.ConsoleKit' "$object" 'org.freedesktop.ConsoleKit.Session.GetX11Display' |
grep -qF "$display" grep -qF "$display"
then then
kill "$clockpid" kill "$clockpid"
break break
fi fi
done & done &
dbuspid=$(<"$dbuspidfifo"); rm -f "$dbuspidfifo" dbuspid=$(<"$dbuspidfifo"); rm -f "$dbuspidfifo"
fi fi
# Conform to POSIX and do not use `>&' here. # Conform to POSIX and do not use `>&' here.
@ -82,18 +82,18 @@ nohup startx $* > /dev/null 2>&1 &
# If wait(1) returns with a value >128, it was interrupted by kill(1), # If wait(1) returns with a value >128, it was interrupted by kill(1),
# so registration was sucessful. # so registration was sucessful.
if $consolekit; then if $consolekit; then
if [[ -n "$clockpid" ]]; then if [[ -n "$clockpid" ]]; then
if wait "$clockpid" >& /dev/null if wait "$clockpid" >& /dev/null
then then
kill "$dbuspid" kill "$dbuspid"
error "ConsoleKit registration timed out." error "ConsoleKit registration timed out."
exit 1 exit 1
else else
kill "$dbuspid" kill "$dbuspid"
info "ConsoleKit registration succeeded." info "ConsoleKit registration succeeded."
exit 0 exit 0
fi fi
fi fi
fi fi
# vim:set ts=4 sw=4 noet: # vim:set ts=4 sw=4 et:

View File

@ -1,5 +1,5 @@
if [[ "$(tty)" == /dev/tty* ]]; then if [[ "$(tty)" == /dev/tty* ]]; then
[[ -n "$CDM_SPAWN" ]] && return [[ -n "$CDM_SPAWN" ]] && return
[[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm [[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm
fi fi