File: postinst

package info (click to toggle)
wdm 1.28-26
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,516 kB
  • sloc: ansic: 11,439; sh: 1,033; makefile: 377; perl: 32; cpp: 10
file content (138 lines) | stat: -rw-r--r-- 4,267 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
# Debian wdm package post-installation script
# Copyright 2001 Branden Robinson.
# Copyright 2005 Vladimir Shakhov.
# Licensed under the GNU General Public License, version 2.  See the file
# /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.

set -e

# source debconf library
. /usr/share/debconf/confmodule

THIS_PACKAGE=wdm
THIS_DISPLAY_MANAGER=/usr/bin/wdm
DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager

message () {
  # pretty-print messages of arbitrary length
  echo "$*" | fold -s -w ${COLUMNS:-80} >&2;
}

message_nonl () {
  # pretty-print messages of arbitrary length (no trailing newline)
  echo -n "$*" | fold -s -w ${COLUMNS:-80} >&2;
}

errormsg () {
  # exit script with error
  message "$*"
  exit 1;
}

# debconf is not a registry, so we only fiddle with the default file if it
# does not exist
DEFAULT_DISPLAY_MANAGER_FILE=/etc/X11/default-display-manager
if [ ! -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
  DEFAULT_DISPLAY_MANAGER=
  if db_get shared/default-x-display-manager; then
    DEFAULT_DISPLAY_MANAGER="$RET"
  fi
  if [ -n "$DEFAULT_DISPLAY_MANAGER" ]; then
    DAEMON_NAME=
    if db_get "$DEFAULT_DISPLAY_MANAGER"/daemon_name; then
      DAEMON_NAME="$RET"
    fi
    if [ -z "$DAEMON_NAME" ]; then
      # if we were unable to determine the name of the selected daemon (for
      # instance, if the selected default display manager doesn't provide a
      # daemon_name question), guess
      DAEMON_NAME=$(which "$DEFAULT_DISPLAY_MANAGER" 2>/dev/null)
      if [ -z "$DAEMON_NAME" ]; then
        echo "WARNING: unable to determine path to default X display manager" \
             "$DEFAULT_DISPLAY_MANAGER; not updating" \
             "$DEFAULT_DISPLAY_MANAGER_FILE"
      fi
    fi
    if [ -n "$DAEMON_NAME" ]; then
      echo "committing change of default X display manager"
      echo "$DAEMON_NAME" > "$DEFAULT_DISPLAY_MANAGER_FILE"
    fi
  fi
else
  DEFAULT_DISPLAY_MANAGER=$(cat "$DEFAULT_DISPLAY_MANAGER_FILE")
fi

# remove the displaced old default display manager file if it exists
if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE.dpkg-tmp" ]; then
  rm "$DEFAULT_DISPLAY_MANAGER_FILE.dpkg-tmp"
fi

DEFAULT_SERVICE=/etc/systemd/system/display-manager.service
# set default-display-manager systemd service link according to our config
if [ "$1" = configure ] && [ -d /etc/systemd/system/ ]; then
  if [ -e "$DEFAULT_DISPLAY_MANAGER_FILE" ]; then
    SERVICE=/lib/systemd/system/$(basename $(cat "$DEFAULT_DISPLAY_MANAGER_FILE")).service
    if [ -h "$DEFAULT_SERVICE" ] && [ $(readlink "$DEFAULT_SERVICE") = /dev/null ]; then
      echo "Display manager service is masked" >&2
    elif [ -e "$SERVICE" ]; then
      ln -sf "$SERVICE" "$DEFAULT_SERVICE"
    else
      echo "WARNING: $SERVICE is the selected default display manager but does not exist" >&2
      rm -f "$DEFAULT_SERVICE"
    fi
  else
    rm -f "$DEFAULT_SERVICE"
  fi
fi


NOSTART=
WDM_RUNNING=
# don't start wdm if we are upgrading without stopping it
if [ -e /var/run/wdm.upgrade ]; then
  NOSTART=yes
fi
# or if we're currently in X on the display it attempts to manage by default
for HOST_NAME in "" "localhost" "$(hostname)" "$(hostname -f)"; do
  if echo $DISPLAY | grep -q "^${HOST_NAME}:0.*"; then
    NOSTART=yes
  fi
done
# or if it's already running
if start-stop-daemon --stop --quiet --signal 0 --pidfile /var/run/wdm.pid --exec /usr/bin/wdm; then
  NOSTART=yes
  WDM_RUNNING=yes
fi
# or if the options file says not to
if ! grep -qs ^restart-on-upgrade /etc/X11/wdm/wdm.options; then
  NOSTART=yes
fi

if [ -n "$WDM_RUNNING" ]; then
  if [ -d /var/state/wdm ]; then
    message "Note: obsolete directory /var/state/wdm cannot be removed" \
            "because wdm is still running.  Reinstall the wdm package" \
            "(or remove the directory manually) when wdm is not running."
  fi
else
  if [ -d /var/state/wdm ]; then
    rm -r /var/state/wdm
  fi
fi

update_wdm_wmlist
update-rc.d wdm defaults 99 01 > /dev/null 2>&1

# redirect stdout to /dev/tty so debconf doesn't choke on it
[ -n "$NOSTART" ] || if which invoke-rc.d >/dev/null 2>&1; then
    invoke-rc.d package start
  else
    /etc/init.d/package start
fi  > /dev/tty || true

#DEBHELPER#

exit 0

# vim:set ai et sts=2 sw=2 tw=0: