You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
4.8 KiB
Bash

#!/bin/bash
#
# CDM: The Console Display Manager
#
# Copyright (C) 2009, Daniel J Griffiths <ghost1227@archlinux.us>
# Thanks to:
# Andrwe..........beta-testing and submitting the fix for the all
# important X incrementation function
# brisbin33.......code cleanup
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
name="Console Display Manager"
ver="0.3.2"
info="\e[1;34m==>\e[1;37m"
error="\e[1;31m==>\e[1;37m"
success="\e[1;32m==>\e[1;37m"
reset="\e[0m"
trap "" 2 20
# Source cdm configuration
if [ -f /etc/cdmrc ]; then
source /etc/cdmrc
else
echo -e "${error} ERROR: A valid cdm configuration was not found!${reset}"
echo -e "${info} Logging out.${reset}"
sleep 3
exit 1
fi
# Source theme file
if [[ ! -z ${theme} ]]; then
if [[ -f /usr/share/cdm/themes/${theme} ]]; then
export DIALOGRC=/usr/share/cdm/themes/${theme}
else
echo -e "${info} Theme file ${theme} is invalid, reverting to default theme.${reset}"
fi
elif [[ -f /usr/share/cdm/themes/default ]]; then
export DIALOGRC=/usr/share/cdm/themes/default
else
echo -e "${info} A valid theme file was not found, using system defaults.${reset}"
fi
# If X is already running and locktty=yes, activate it,
# otherwise, increment.
if [[ ${locktty} == "yes" ]]; then
# Verify display exists
if [ -n "${display//[0-9]/}" ]; then
display=0
fi
# Activate existing X session
if xdpyinfo -display :${display}.0 &> /dev/null; then
let tty=${display}+${xtty}
chvt ${tty}
exit 0
fi
else
# Get the first empty display
display=0
while [ ${display} -lt 7 ]; do
if xdpyinfo -display :${display}.0 &> /dev/null; then
let display=${display}+1
else
break
fi
done
fi
mainmenu() {
# Generate main menu
count=0
menu=$(
while [[ ${count} -lt ${#wmdisplist[@]} ]]; do
echo -ne "${count} ${wmdisplist[${count}]} "
let count=count+1
done
)
# Check if console access is allowed
if [[ ${allowconsole} == "yes" ]]; then
if [[ ${allowshutdown} != "yes" ]]; then
let halt=99
fi
let console=${#wmdisplist[@]}
menu=$(echo -ne "${menu} ${console} Console ")
fi
# Check if shutdown access is allowed
if [[ ${allowshutdown} == "yes" ]]; then
if [[ ${allowconsole} != "yes" ]]; then
let halt=${#wmdisplist[@]}
else
let halt=${#wmdisplist[@]}+1
fi
menu=$(echo -ne "${menu} ${halt} Shutdown ")
fi
echo "halt=${halt} console=${console} wm='${wm}'" > ~/cdm.tmp
# Override dialog display if only one option is available
if [[ ${allowconsole} != "yes" ]] && [[ ${allowshutdown} != "yes" ]] && [[ ${#wmdisplist[@]} == 1 ]]; then
wm=${wmbinlist[@]}
else
# Display selection dialog
wm=$(
dialog --colors --backtitle "${name} v${ver}" --stdout \
--ok-label " Select " --cancel-label " Logout " \
--menu "Select Window Manager" 0 0 0 ${menu}
)
if [[ $? != 0 ]]; then
clear
exit 0
fi
fi
# Set wm_bin
clear
if [[ ${wm} -eq ${console} ]]; then
${SHELL}
exit 0
elif [[ ${wm} -eq ${halt} ]]; then
shutdownmenu
else
export wm_bin="${wmbinlist[${wm}]}"
xstart
fi
}
shutdownmenu() {
haltmenu="0 Shutdown 1 Reboot"
# Check if suspend is enabled
if [[ ${allowsuspend} == "yes" ]]; then
haltmenu=$(echo -n "${haltmenu} 2 Suspend ")
fi
# Display shutdown dialog
haltopt=$(
dialog --colors --backtitle "${name} v${ver}" --stdout \
--ok-label " Select " --cancel-label " Cancel " \
--menu "Shutdown" 0 0 0 ${haltmenu}
)
if [[ $? == 0 ]]; then
clear
if [[ ${haltopt} -eq 0 ]]; then
${shutdowncommand}
elif [[ ${haltopt} -eq 1 ]]; then
${rebootcommand}
else
${suspendcommand}
fi
else
mainmenu
fi
}
xstart() {
# Start X
if [ ${loginshell} == "yes" ]; then
if [ ${wm_bin} == "gnome-session" ]; then
exec bash --login -c "startx /usr/share/cdm/xinitrc -- :${display} &> /dev/null" &
else
exec ck-launch-session bash --login -c "startx /usr/share/cdm/xinitrc -- :${display} &> /dev/null" &
fi
else
if [ ${wm_bin} == "gnome-session" ]; then
exec startx /usr/share/cdm/xinitrc -- :${display} &> /dev/null &
else
exec ck-launch-session startx /usr/share/cdm/xinitrc -- :${display} &> /dev/null &
fi
fi
}
mainmenu