Merge pull request #10 from lahwaacz/master
fixed formatting - use only spaces, no tabs
This commit is contained in:
commit
04d35a5949
129
src/cdm
129
src/cdm
@ -42,30 +42,30 @@ exitnormal() { exit 0; }
|
||||
exiterror() { sleep 1; exit 1; }
|
||||
yesno()
|
||||
{
|
||||
[ -z "$1" ] && return 1
|
||||
eval value=\$${1}
|
||||
[ -z "$1" ] && return 1
|
||||
eval value=\$${1}
|
||||
|
||||
case "$value" 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 "Invalid value for \`$1'; falling back to \`no' for now.";;
|
||||
esac
|
||||
case "$value" 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 "Invalid value for \`$1'; falling back to \`no' for now.";;
|
||||
esac
|
||||
}
|
||||
|
||||
# Source cdm configurations.
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
if [[ -f "$1" ]]
|
||||
then
|
||||
source "$1"
|
||||
else
|
||||
error "config file \`$1' does not exist."
|
||||
exiterror
|
||||
fi
|
||||
if [[ -f "$1" ]]
|
||||
then
|
||||
source "$1"
|
||||
else
|
||||
error "config file \`$1' does not exist."
|
||||
exiterror
|
||||
fi
|
||||
elif [[ -f "$HOME/.cdmrc" ]]; then
|
||||
source "$HOME/.cdmrc"
|
||||
source "$HOME/.cdmrc"
|
||||
elif [[ -f /etc/cdmrc ]]; then
|
||||
source /etc/cdmrc
|
||||
source /etc/cdmrc
|
||||
fi
|
||||
|
||||
# Default options.
|
||||
@ -86,58 +86,58 @@ cktimeout=${cktimeout:-30}
|
||||
# if binlist if not explicitly set in cdmrc.
|
||||
|
||||
if [[ "${#binlist[@]}" == 0 ]]; then
|
||||
binlist=($(ls /etc/X11/Sessions))
|
||||
flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!flaglist[*]}))
|
||||
namelist=(${binlist[@]^})
|
||||
binlist=($(ls /etc/X11/Sessions))
|
||||
flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!flaglist[*]}))
|
||||
namelist=(${binlist[@]^})
|
||||
fi
|
||||
|
||||
# Generate the main menu.
|
||||
menu=()
|
||||
for ((count = 0; count < ${#namelist[@]}; count++)); do
|
||||
menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}")
|
||||
menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}")
|
||||
done
|
||||
|
||||
# Override dialog display if only one option is available.
|
||||
if [[ "$count" == 1 ]]; then
|
||||
binindex=0
|
||||
binindex=0
|
||||
else
|
||||
# Display selection dialog.
|
||||
binindex=$(
|
||||
DIALOGRC="$dialogrc" dialog --colors --stdout \
|
||||
--backtitle "${longname} v${ver}" \
|
||||
--ok-label ' Select ' --cancel-label ' Exit ' \
|
||||
--menu 'Select session' 0 0 0 "${menu[@]}"
|
||||
)
|
||||
if [[ $? != 0 ]]; then
|
||||
clear
|
||||
exitnormal
|
||||
fi
|
||||
# Display selection dialog.
|
||||
binindex=$(
|
||||
DIALOGRC="$dialogrc" dialog --colors --stdout \
|
||||
--backtitle "${longname} v${ver}" \
|
||||
--ok-label ' Select ' --cancel-label ' Exit ' \
|
||||
--menu 'Select session' 0 0 0 "${menu[@]}"
|
||||
)
|
||||
if [[ $? != 0 ]]; then
|
||||
clear
|
||||
exitnormal
|
||||
fi
|
||||
fi
|
||||
|
||||
# Run $bin according to its flag.
|
||||
let binindex-=countfrom
|
||||
bin="${binlist[${binindex}]}"
|
||||
case ${flaglist[$binindex]} in
|
||||
# *C*onsole programs.
|
||||
[Cc])
|
||||
clear
|
||||
# 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
|
||||
# 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.
|
||||
CDM_SPAWN=$$ exec $bin
|
||||
;;
|
||||
# *C*onsole programs.
|
||||
[Cc])
|
||||
clear
|
||||
# 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
|
||||
# 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.
|
||||
CDM_SPAWN=$$ exec $bin
|
||||
;;
|
||||
|
||||
# *X* programs.
|
||||
[Xx])
|
||||
clear
|
||||
# *X* programs.
|
||||
[Xx])
|
||||
clear
|
||||
|
||||
# If X is already running and locktty=yes, activate it
|
||||
if $(yesno locktty); then
|
||||
if xdpyinfo -display ":$display.0" &> /dev/null; then
|
||||
chvt "$((display+xtty))"
|
||||
exitnormal
|
||||
fi
|
||||
if $(yesno locktty); then
|
||||
if xdpyinfo -display ":$display.0" &> /dev/null; then
|
||||
chvt "$((display+xtty))"
|
||||
exitnormal
|
||||
fi
|
||||
fi
|
||||
|
||||
# Get the first empty display.
|
||||
@ -164,24 +164,25 @@ case ${flaglist[$binindex]} in
|
||||
exiterror
|
||||
fi
|
||||
vt=${vt#tty}
|
||||
else
|
||||
else
|
||||
vt=$((xtty+display))
|
||||
fi
|
||||
fi
|
||||
|
||||
serverargs=":${display} $serverargs vt$vt"
|
||||
serverargs=":${display} $serverargs vt$vt"
|
||||
|
||||
$(yesno consolekit) && launchflags="-c -t $cktimeout"
|
||||
if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then
|
||||
warn "\`cdm-xlaunch' exited unsuccessfully."
|
||||
exiterror
|
||||
else
|
||||
exitnormal
|
||||
fi
|
||||
;;
|
||||
$(yesno consolekit) && launchflags="-c -t $cktimeout"
|
||||
if ! eval cdm-xlaunch $launchflags -- $bin -- $serverargs; then
|
||||
warn "\`cdm-xlaunch' exited unsuccessfully."
|
||||
exiterror
|
||||
else
|
||||
exitnormal
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
error "unknown flag: \`${flaglist[$binindex]}'."
|
||||
exiterror
|
||||
;;
|
||||
*)
|
||||
error "unknown flag: \`${flaglist[$binindex]}'."
|
||||
exiterror
|
||||
;;
|
||||
esac
|
||||
|
||||
# vim:set ts=4 sw=4 et:
|
||||
|
@ -39,41 +39,41 @@ args=$(getopt -n "$name" -o ct: -l consolekit,timeout: -- "$@") || exit 1
|
||||
eval set -- "$args"
|
||||
for arg in "$@"
|
||||
do
|
||||
case $arg in
|
||||
'--consolekit' | '-c')
|
||||
consolekit=true; shift
|
||||
;;
|
||||
'--timeout' | '-t')
|
||||
shift
|
||||
cktimeout=$1; shift
|
||||
;;
|
||||
'--')
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
case $arg in
|
||||
'--consolekit' | '-c')
|
||||
consolekit=true; shift
|
||||
;;
|
||||
'--timeout' | '-t')
|
||||
shift
|
||||
cktimeout=$1; shift
|
||||
;;
|
||||
'--')
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Do first to avoid race conditions.
|
||||
if $consolekit; then
|
||||
info "waiting for ConsoleKit to register X session."
|
||||
sleep "$cktimeout" & clockpid=$!
|
||||
dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX)
|
||||
if ! mkfifo "$dbuspidfifo"; then
|
||||
error "failed to create FIFO \`$fifo'."
|
||||
exit 1
|
||||
fi
|
||||
info "waiting for ConsoleKit to register X session."
|
||||
sleep "$cktimeout" & clockpid=$!
|
||||
dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX)
|
||||
if ! mkfifo "$dbuspidfifo"; then
|
||||
error "failed to create FIFO \`$fifo'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(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
|
||||
if dbus-send --system --print-reply --dest='org.freedesktop.ConsoleKit' "$object" 'org.freedesktop.ConsoleKit.Session.GetX11Display' |
|
||||
grep -qF "$display"
|
||||
then
|
||||
kill "$clockpid"
|
||||
break
|
||||
fi
|
||||
done &
|
||||
dbuspid=$(<"$dbuspidfifo"); rm -f "$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
|
||||
if dbus-send --system --print-reply --dest='org.freedesktop.ConsoleKit' "$object" 'org.freedesktop.ConsoleKit.Session.GetX11Display' |
|
||||
grep -qF "$display"
|
||||
then
|
||||
kill "$clockpid"
|
||||
break
|
||||
fi
|
||||
done &
|
||||
dbuspid=$(<"$dbuspidfifo"); rm -f "$dbuspidfifo"
|
||||
fi
|
||||
|
||||
# Conform to POSIX and do not use `>&' here.
|
||||
@ -95,3 +95,5 @@ if $consolekit; then
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# vim:set ts=4 sw=4 et:
|
||||
|
@ -1,5 +1,5 @@
|
||||
if [[ "$(tty)" == /dev/tty* ]]; then
|
||||
[[ -n "$CDM_SPAWN" ]] && return
|
||||
[[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm
|
||||
[[ -n "$CDM_SPAWN" ]] && return
|
||||
[[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user