Debian Codegraph @

scripts/bin/drbl-check-dm

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: To get the display manager of server
5
6 # The following is borrowed from Mandrake 9.2
7 # we have to assume that /$SYSCONF_PATH/desktop has two variables, DESKTOP
8 # and DISPLAYMANAGER because administors may prefer a specific DM regardless
9 # of desktops.
10 # DISPLAYMANAGER is referenced by this script, and DESKTOP is referenced
11 # as system-wide default by /etc/X11/Xsession script only when X-session
12 # is opened by "startx" command.
13 # when DMs open an X-session, they send DESKTOP, which is in this case
14 # directly selected by users, as a commandline argument of /etc/X11/Xsession.
15 # actually Xsession script is only able to know by existance of its first
16 # argument whether it is called by DM or "startx". see the logic
17 # in /etc/X11/Xsession.
18 # If DISPLAYMANAGER is not defined, then assume that it is the same as DESKTOP
19
20 # Load DRBL setting and functions
21 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
22
23 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
24
25 #
26 usage() {
27 echo "Usage:"
28 echo "To get the default display manager:"
29 echo "`basename $0` [OPTION]"
30 echo " Options:"
31 echo " -h, --host IP_ADDRESS: get the default display manager of the host with IP_ADDRESS."
32 echo " -v, --verbose prints out verbose information"
33 }
34
35 # Parse command-line options
36 while [ $# -gt 0 ]; do
37 case "$1" in
38 -h|--host)
39 shift; specified_host="$1"
40 if [ -z "$specified_host" ]; then
41 usage >& 2
42 exit 2
43 fi
44 shift
45 ;;
46 -v|--verbose)
47 shift; VERBOSE="on"
48 ;;
49 -*) echo "${0}: ${1}: invalid option" >&2
50 usage >& 2
51 exit 2 ;;
52 *) break ;;
53 esac
54 done
55
56 #
57 if [ -z "$specified_host" ]; then
58 hpath=""
59 else
60 hpath="$drblroot/$specified_host"
61 fi
62
63 preferred=
64 if [ -e $hpath/etc/debian_version ]; then
65 # Debian
66 if [ -e $hpath/etc/X11/default-display-manager ]; then
67 # Debian
68 default_dm="$(cat $hpath/etc/X11/default-display-manager 2> /dev/null)"
69 [ -n "$default_dm" ] && preferred="$(basename $default_dm)"
70 fi
71 elif [ -e $hpath/etc/SuSE-release ]; then
72 # SuSE
73 if [ -e $hpath/$SYSCONF_PATH/displaymanager ]; then
74 # SuSE
75 . $hpath/$SYSCONF_PATH/displaymanager &>/dev/null
76 if [ "$DISPLAYMANAGER" = "GDM" -o "$DISPLAYMANAGER" = "gdm" -o "$DISPLAYMANAGER" = "GNOME" -o "$DISPLAYMANAGER" = "gnome" -o "$DISPLAYMANAGER" = "Gnome" ]; then
77 preferred=gdm
78 elif [ "$DISPLAYMANAGER" = "KDE" -o "$DISPLAYMANAGER" = "kde" ]; then
79 preferred=mdkkdm
80 elif [ "$DISPLAYMANAGER" = "KDM" -o "$DISPLAYMANAGER" = "kdm" ]; then
81 preferred=kdm
82 elif [ "$DISPLAYMANAGER" = "XDM" -o "$DISPLAYMANAGER" = "xdm" ] ; then
83 preferred=xdm
84 fi
85 fi
86 else
87 # RH-like
88 if [ -e $hpath/$SYSCONF_PATH/desktop ]; then
89 . $hpath/$SYSCONF_PATH/desktop &>/dev/null
90 [ -z "$DISPLAYMANAGER" ] && DISPLAYMANAGER=$DESKTOP
91 if [ "$DISPLAYMANAGER" = "GDM" -o "$DISPLAYMANAGER" = "gdm" -o "$DISPLAYMANAGER" = "GNOME" -o "$DISPLAYMANAGER" = "gnome" -o "$DISPLAYMANAGER" = "Gnome" ]; then
92 preferred=gdm
93 elif [ "$DISPLAYMANAGER" = "KDE" -o "$DISPLAYMANAGER" = "kde" ]; then
94 preferred=mdkkdm
95 elif [ "$DISPLAYMANAGER" = "KDM" -o "$DISPLAYMANAGER" = "kdm" ]; then
96 preferred=kdm
97 elif [ "$DISPLAYMANAGER" = "XDM" -o "$DISPLAYMANAGER" = "xdm" ] ; then
98 preferred=xdm
99 fi
100 fi
101 fi
102
103 # if the preferred dm is not found, set the default one
104 # For Redhat/FC, the default dm is gdm, for Mandrake, the default dm is kdm
105 if [ -z "$preferred" ]; then
106 # /etc/redhat-release & /etc/fedora-release should be the last one to test, since like MDV, it also has /etc/redhat-release.
107 if [ -e $hpath/etc/mandrakelinux-release -o \
108 -e $hpath/etc/mandrake-release -o \
109 -e $hpath/etc/mandriva-release ]; then
110 # For Mandrake, the default dm is kdm or mdkkdm, make sure it exists
111 if type kdm &>/dev/null; then
112 preferred="kdm"
113 elif type mdkkdm &>/dev/null; then
114 preferred="mdkkdm"
115 fi
116 elif [ -e $hpath/etc/debian_version ]; then
117 # For Debian, the default gdm, then kdm or xdm
118 if type gdm &>/dev/null; then
119 preferred="gdm"
120 elif type kdm &>/dev/null; then
121 preferred="kdm"
122 elif type xdm &>/dev/null; then
123 preferred="xdm"
124 fi
125 elif [ -e $hpath/etc/SuSE-release ]; then
126 # For SuSE, the default kdm, then gdm or xdm
127 if type kdm &>/dev/null; then
128 preferred="kdm"
129 elif type gdm &>/dev/null; then
130 preferred="gdm"
131 elif type xdm &>/dev/null; then
132 preferred="xdm"
133 fi
134 elif [ -e $hpath/etc/redhat-release -o -e $hpath/etc/fedora-release ]; then
135 # /etc/redhat-release & /etc/fedora-release should be the last one to test, since like MDV, it also has /etc/redhat-release.
136 # For Redhat/FC, the default dm is gdm, make sure it exists
137 type gdm &>/dev/null && preferred="gdm"
138 else
139 # echo "Unsupported distribution! Can NOT decide which dm is used in your system...Program terminated!"
140 exit 1
141 fi
142 fi
143
144 # output the results.
145 if [ -n "$preferred" ]; then
146 echo $preferred
147 exit 0
148 else
149 # echo "The gdm, kdm or xdm is NOT found in your system!"
150 exit 1
151 fi