|
|
|
@ -48,7 +48,7 @@ yesno()
|
|
|
|
|
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.";;
|
|
|
|
|
*) warn "invalid value for \`$1'; falling back to \`no' for now.";;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -70,27 +70,25 @@ fi
|
|
|
|
|
|
|
|
|
|
# Default options.
|
|
|
|
|
|
|
|
|
|
binlist=${binlist:-()}
|
|
|
|
|
namelist=${namelist:-()}
|
|
|
|
|
flaglist=${flaglist:-()}
|
|
|
|
|
dialogrc=${dialogrc:-}
|
|
|
|
|
countfrom=${countfrom:-0}
|
|
|
|
|
display=${display:-0}
|
|
|
|
|
xtty=${xtty:-7}
|
|
|
|
|
locktty=${locktty:-no}
|
|
|
|
|
serverargs=${serverargs:-'-nolisten tcp'}
|
|
|
|
|
consolekit=${consolekit:-yes}
|
|
|
|
|
cktimeout=${cktimeout:-30}
|
|
|
|
|
[[ -z "${binlist[*]}" ]] && binlist=()
|
|
|
|
|
[[ -z "${namelist[*]}" ]] && namelist=()
|
|
|
|
|
[[ -z "${flaglist[*]}" ]] && flaglist=()
|
|
|
|
|
[[ -z "${serverargs[*]}" ]] && serverargs=(-nolisten tcp)
|
|
|
|
|
|
|
|
|
|
# Offer all available sessions in /etc/X11/Sessions,
|
|
|
|
|
# if binlist if not explicitly set in cdmrc.
|
|
|
|
|
# if $binlist if not explicitly set in cdmrc.
|
|
|
|
|
|
|
|
|
|
if [[ "$binlist" == "()" ]]; then
|
|
|
|
|
if [[ "${#binlist[@]}" == 0 ]]; then
|
|
|
|
|
binlist=($(find /etc/X11/Sessions -maxdepth 1 -type f))
|
|
|
|
|
for ((i=0; i<${#binlist[@]}; i++)); do
|
|
|
|
|
declare flaglist[$i]="X"
|
|
|
|
|
declare namelist[$i]=$(basename ${binlist[$i]})
|
|
|
|
|
done
|
|
|
|
|
flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!binlist[@]}))
|
|
|
|
|
namelist=(${binlist[@]##*/})
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Generate the main menu.
|
|
|
|
@ -106,7 +104,7 @@ else
|
|
|
|
|
# Display selection dialog.
|
|
|
|
|
binindex=$(
|
|
|
|
|
DIALOGRC="$dialogrc" dialog --colors --stdout \
|
|
|
|
|
--backtitle "${longname} v${ver}" \
|
|
|
|
|
--backtitle "$longname v$ver" \
|
|
|
|
|
--ok-label ' Select ' --cancel-label ' Exit ' \
|
|
|
|
|
--menu 'Select session' 0 0 0 "${menu[@]}"
|
|
|
|
|
)
|
|
|
|
@ -118,34 +116,33 @@ fi
|
|
|
|
|
|
|
|
|
|
# Run $bin according to its flag.
|
|
|
|
|
let binindex-=countfrom
|
|
|
|
|
bin="${binlist[${binindex}]}"
|
|
|
|
|
bin=($(eval echo "${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.
|
|
|
|
|
|
|
|
|
|
# Also untrap SIGINT and SIGTSTP before spawning process: If this is not
|
|
|
|
|
# done, *ANY* child process of *ANY* child (bash) shell will completely
|
|
|
|
|
# done, any child process of any child (bash) shell will completely
|
|
|
|
|
# ignore SIGINT, which is rather confusing, and cannot be undone.
|
|
|
|
|
|
|
|
|
|
trap - SIGINT SIGTSTP
|
|
|
|
|
CDM_SPAWN=$$ exec $bin
|
|
|
|
|
CDM_SPAWN=$$ exec "${bin[@]}"
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
# *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 X is already running and locktty=yes, activate it.
|
|
|
|
|
if $(yesno locktty) && xdpyinfo -display ":$display.0" &> /dev/null; then
|
|
|
|
|
chvt "$((display+xtty))"
|
|
|
|
|
exitnormal
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Get the first empty display.
|
|
|
|
@ -163,27 +160,27 @@ case ${flaglist[$binindex]} in
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# run X in current tty
|
|
|
|
|
if [[ $xtty == "keep" ]]; then
|
|
|
|
|
vt=$(tty)
|
|
|
|
|
vt=${vt#/dev/}
|
|
|
|
|
if [[ $vt != tty* ]]; then
|
|
|
|
|
error "error: invalid TTY"
|
|
|
|
|
# Support for running X in current tty.
|
|
|
|
|
if [[ $xtty == 'keep' ]]; then
|
|
|
|
|
vt="$(tty)"
|
|
|
|
|
if [[ "$vt" != '/dev/tty'* ]]; then
|
|
|
|
|
error 'invalid TTY.'
|
|
|
|
|
exiterror
|
|
|
|
|
fi
|
|
|
|
|
vt=${vt#tty}
|
|
|
|
|
vt="${vt#/dev/tty}"
|
|
|
|
|
else
|
|
|
|
|
vt=$((xtty+display))
|
|
|
|
|
vt="$((xtty+display))"
|
|
|
|
|
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
|
|
|
|
|
$(yesno consolekit) && launchflags=(-c -t "$cktimeout")
|
|
|
|
|
if cdm-xlaunch "${launchflags[@]}" -- "${bin[@]}" -- "${serverargs[@]}"
|
|
|
|
|
then
|
|
|
|
|
exitnormal
|
|
|
|
|
else
|
|
|
|
|
warn "\`cdm-xlaunch' exited unsuccessfully."
|
|
|
|
|
exiterror
|
|
|
|
|
else
|
|
|
|
|
exitnormal
|
|
|
|
|
fi
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
@ -193,4 +190,4 @@ case ${flaglist[$binindex]} in
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
# vim:set ts=4 sw=4 et:
|
|
|
|
|
# vim:ts=4:sw=4:et
|
|
|
|
|