Major restructuring.

classify menu items into console programs and X programs.
Console programs are directly `exec'ed.
X programs are run with cdm-xlaunch(1).
$allowconsole, $usexinit, shutdownmenu(), etc., are removed.
pull/7/head
Casper Ti. Vector 12 years ago
parent f54e4a2ccd
commit 4b0e9825eb

@ -12,3 +12,4 @@ else
install -Dm755 zzz-cdm-profile.sh /etc/profile.d/zzz-cdm-profile.sh install -Dm755 zzz-cdm-profile.sh /etc/profile.d/zzz-cdm-profile.sh
cp -Rf themes /usr/share/cdm/ cp -Rf themes /usr/share/cdm/
fi fi

@ -27,18 +27,13 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA. # MA 02110-1301, USA.
name="Console Display Manager" name=$(basename "$0")
ver="0.5.3" longname='Console Display Manager'
ver='0.5.3'
trap '' SIGINT SIGTSTP trap '' SIGINT SIGTSTP
source /etc/init.d/functions.sh source /etc/init.d/functions.sh
dialogrc=${dialogrc:-}
userclientrc=$HOME/.xinitrc
sysclientrc=/etc/X11/xinit/xinitrc
# userserverrc=$HOME/.xserverrc
# sysserverrc=/etc/X11/xinit/xserverrc
# Source cdm configurations. # Source cdm configurations.
if [[ -n "$1" ]]; then if [[ -n "$1" ]]; then
@ -49,159 +44,108 @@ elif [[ -f /etc/cdmrc ]]; then
source /etc/cdmrc source /etc/cdmrc
fi fi
# Offer all available sessions in /etc/X11/Sessions # Default options.
# if wmbinlist if not explicitly set in cdmrc
if [[ "${#wmbinlist[@]}" -eq 0 ]]; then dialogrc=${dialogrc:-}
wmbinlist=($(ls /etc/X11/Sessions)) countfrom=${countfrom:-0}
wmdisplist=($(echo ${wmbinlist[@]^})) binlist=${binlist:-()}
fi namelist=${namelist:-()}
xtty=${xtty:-7}
mainmenu() { locktty=${locktty:-no}
# Generate main menu display=${display:-0}
count=0 consolekit=${consolekit:-yes}
menu=$( cktimeout=${cktimeout:-30}
while [[ ${count} -lt ${#wmdisplist[@]} ]]; do serverargs=${serverargs:-'-nolisten tcp'}
echo -ne "$((count+countfrom)) ${wmdisplist[${count}]} "
let count=count+1 # Exit functions.
exitnormal() { exit 0; }
exiterror() { sleep 1; exit 1; }
# Offer all available sessions in /etc/X11/Sessions,
# 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[@]^})
fi
# Generate the main menu.
menu=()
for ((count=0; count<${#namelist[@]}; count++)); do
menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}")
done done
)
# Check if console access is allowed
if $(yesno allowconsole); then
if ! $(yesno allowshutdown); then
let halt=99
fi
let console=${#wmdisplist[@]}+countfrom
menu="${menu} ${console} Console "
fi
# Check if shutdown access is allowed # Override dialog display if only one option is available.
if $(yesno allowshutdown); then if [[ "$count" == 1 ]]; then
if ! $(yesno allowconsole); then binindex=0
let halt=${#wmdisplist[@]}
else else
let halt=${#wmdisplist[@]}+1 # Display selection dialog.
fi binindex=$(
let halt=halt+countfrom DIALOGRC="$dialogrc" dialog --colors --stdout \
menu="${menu} ${halt} Shutdown " --backtitle "${longname} v${ver}" \
fi --ok-label ' Select ' --cancel-label ' Exit ' \
--menu 'Select session' 0 0 0 "${menu[@]}"
# Override dialog display if only one option is available
if ! $(yesno allowconsole) && ! $(yesno allowshutdown) && [[ ${#wmdisplist[@]} == 1 ]]; then
wm=$countfrom
else
# Display selection dialog
wm=$(
DIALOGRC="$dialogrc" dialog --colors \
--backtitle "${name} v${ver}" --stdout \
--ok-label " Select " --cancel-label " Logout " \
--menu "Select Window Manager" 0 0 0 ${menu}
) )
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
clear clear
exit 0 exitnormal
fi fi
fi fi
# Set wm_bin # Run $bin according to its flag.
let binindex-=countfrom
bin="${binlist[${binindex}]}"
case ${flaglist[$binindex]} in
# *C*onsole programs.
[Cc])
clear clear
if [[ ${wm} -eq ${console} ]]; then # If $bin is a login shell, it might `exec' cdm again, causing an endless
exit 2 #2 signals to the profile file to not exit. # loop. To solve this problem, export $CDM_SPAWN when `exec'ing $bin and
elif [[ ${wm} -eq ${halt} ]]; then # only let the shell automatically `exec' cdm when $CDM_SPAWN is not set.
shutdownmenu # See also the example shell profile file shipped with this cdm package.
else CDM_SPAWN=$$ exec $bin
let wm=wm-countfrom ;;
wm_bin="${wmbinlist[${wm}]}"
xstart # *X* programs.
fi [Xx])
}
shutdownmenu() {
count=$countfrom
haltmenu=$(
for opt in Shutdown Reboot Suspend Hibernate; do
# Check if suspend/hibernate is enabled
if ([[ $opt != Suspend ]] && [[ $opt != Hibernate ]]) ||
([[ $opt == Suspend ]] && $(yesno allowsuspend)) ||
([[ $opt == Hibernate ]] && $(yesno allowhibernate)); then
echo -ne "$count $opt "
let count=count+1
fi
done
)
# Display shutdown dialog
haltopt=$(
DIALOGRC="$dialogrc" dialog --colors \
--backtitle "${name} v${ver}" --stdout \
--ok-label " Select " --cancel-label " Cancel " \
--menu "Shutdown" 0 0 0 ${haltmenu}
)
if [[ $? == 0 ]]; then
clear clear
if [[ ${haltopt} -eq $countfrom ]]; then
${shutdowncommand}
elif [[ ${haltopt} -eq $((countfrom+1)) ]]; then
${rebootcommand}
elif [[ ${haltopt} -eq $((countfrom+2)) ]] && $(yesno allowsuspend); then
${suspendcommand}
else
${hibernatecommand}
fi
else
mainmenu
fi
}
xstart() {
# If X is already running and locktty=yes, activate it, # If X is already running and locktty=yes, activate it,
# otherwise, increment. # otherwise increment.
if $(yesno locktty); then if $(yesno locktty); then
# Verify display exists # Activate existing X session.
if [[ -n "${display//[0-9]/}" ]]; then if xdpyinfo -display ":$display.0" &> /dev/null; then
display=0 chvt "$((display+xtty))"
fi exitnormal
# Activate existing X session
if xdpyinfo -display :${display}.0 &> /dev/null; then
let tty=display+xtty
chvt ${tty}
exit 0
fi fi
else else
# Get the first empty display # Get the first empty display.
display=0 display=0
while [[ ${display} -lt 7 ]]; do while [[ "$display" < 7 ]]; do
if dpyinfo=$(xdpyinfo -display :${display}.0 2>&1 1>/dev/null); then if dpyinfo=$(xdpyinfo -display ":$display.0" 2>&1 1>/dev/null) ||
let display=display+1 # Display is in use by another user.
elif [[ $dpyinfo = No\ protocol\ specified* ]]; then [[ "$dpyinfo" == 'No protocol specified'* ]]
# Display is in use by another user then
let display=display+1 let display+=1
else else
break break
fi fi
done done
fi fi
serverargs=":${display} $serverargs vt$((xtty+display))"
# Start X
if $(yesno usexinit); then
if [[ -f $userclientrc ]]; then
wm_bin="$userclientrc $wm_bin"
elif [[ -f $sysclientrc ]]; then
wm_bin="$sysclientrc $wm_bin"
fi
else
wm_bin="/etc/X11/cdm/xinitrc $wm_bin"
fi
serverargs=":${display} ${serverargs} vt$((xtty+display))"
$(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
ewarn "\`cdm-xlaunch' exited unsuccessfully." ewarn "$self: \`cdm-xlaunch' exited unsuccessfully."
exit 1 exiterror
fi fi
} ;;
mainmenu
*)
eerror "$self: unknown flag: \`${flaglist[$binindex]}'."
exiterror
;;
esac

@ -1,70 +1,51 @@
############################ #!/bin/bash
### GLOBAL CONFIGURATION ### #
############################ # Example config file for cdm(1).
# Values set here is the default as in cdm(1).
# Set CDM theme and dialog options
dialogrc=/usr/share/cdm/themes/cdm # Style for the cdm dialog, which is printed with dialog(1).
countfrom=1 # Default to unset, causing dialog(1) to use the system wide default.
# See /usr/share/cdm/themes for some nice choices.
# List all WM binary names dialogrc=
# If this is not set all sessions in
# /etc/X11/Sessions are offered as choices. # Index of the first item in the menu.
wmbinlist=() countfrom=0
# List all WM display names # List of programs, commands with whitespaces should be quoted or escaped.
wmdisplist=() # If unset, all sessions in /etc/X11/Sessions are offered as choices.
#
# Allow console login? # (An example:)
allowconsole=yes # binlist=("~/.xsession" "/bin/bash --login" "/usr/bin/fbterm")
# Allow shutdown? # List all program display names, one-by-one matched with $binlist.
# Note that this option requires sudo # Names with whitespaces should be quoted or escaped.
# to be installed and properly configured. #
allowshutdown=no # (Continued example:)
shutdowncommand='sudo shutdown -h now' # namelist=(XSession Console FBTerm)
rebootcommand='sudo shutdown -r now'
# Type of the programs, one-by-one matched with $binlist.
# Allow suspend? # `C' for *C*onsole programs, which would be `exec'ed.
# Note that this option requires pm-utils # `X' for *X* programs, which would be run with cdm-xlaunch(1).
# to be installed and properly configured. #
allowsuspend=no # (Continued example:)
suspendcommand='sudo pm-suspend' # flaglist=(X C C)
allowhibernate=no
hibernatecommand='sudo pm-hibernate' # Set default display.
############################
### SYSTEM CONFIGURATION ###
############################
# Set default display
display=0 display=0
# Where should first X tty be spawned? # Where should first X tty be spawned?
xtty=7 xtty=7
# Restrict tty? (By default, cdm increments X tty, this setting # Should cdm(1) stick to the specified display?
# allows administrators to lock users into one specific tty by locktty=yes
# setting the display=N option on a per-user basis.)
locktty=no
# The use of consolekit has recently become manditory with hal. However, # Use consolekit for X session?
# some users might prefer not using either one. If you don't want to
# use consolekit, set the following variable to "no".
consolekit=yes consolekit=yes
# Timeout for waiting for X session to register with consoleKit # Timeout for waiting for X session to register with consolekit.
cktimeout=30 cktimeout=5
# Additional arguments to pass to X server
# When usexinit=yes, we use ~/.xinitrc when it exists or /etc/X11/xinit/xinitrc
# when it doesn't. These are passed the chosen window manager as $1; note that
# the stock /etc/X11/xinit/xinitrc ignores this and always starts twm and three
# xterms. Your custom xinitrc should start the window manager supplied as $1
# instead. There is a sample xinitrc included at /usr/share/cdm/xinitrc.skel.
# If usexinit=no, then we instead call the chosen window manager directly.
usexinit=no
# Additional arguments to pass to X server; it will be called as: # Additional arguments to pass to X server; it will be called as:
# exec /usr/bin/X :$display $serverargs vt$((xtty+display)) # exec /usr/bin/X :$display $serverargs vt$((xtty+display))
serverargs="-nolisten tcp" serverargs='-nolisten tcp'

@ -0,0 +1,7 @@
#!/bin/sh -
if [[ "$(tty)" == /dev/tty1 ]]; then
[[ -n "$CDM_SPAWN" ]] && return
[[ -z "$DISPLAY`pgrep xinit`$SSH_TTY" ]] && exec cdm
fi

@ -1,10 +0,0 @@
#!/bin/sh
#
# If option usexinit is set then this file is not used. Instead ~/.xinitrc
# if it exists or else /etc/X11/xinit/xinitrc is used in it's place.
# Put your configuration above this line.
wm_bin="$1"
exec ${wm_bin}

@ -1,9 +0,0 @@
if [[ -z "$DISPLAY" && -z "$SSH_TTY" && $(tty) = /dev/tty* ]]; then
# Drop root to console
if ! [[ $EUID -eq 0 ]]; then
cdm
if (( $? == 0 )); then
exit 0
fi
fi
fi
Loading…
Cancel
Save