File: udev.preinst

package info (click to toggle)
udev 164-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,336 kB
  • ctags: 1,738
  • sloc: ansic: 18,516; sh: 11,378; perl: 1,725; xml: 1,286; makefile: 692; python: 34
file content (297 lines) | stat: -rw-r--r-- 7,407 bytes parent folder | download
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/bin/sh -e

# Hack to get the dpkg process' PID despite using debconf
if [ -z "$PARENT_PID" ]; then
  export PARENT_PID=$PPID
fi

. /usr/share/debconf/confmodule

supported_kernel() {
  local version
  if [ "$1" ]; then
    version="$1"
  else
    version="$(uname -r)"
  fi

  case "$version" in
    2.[012345].*|2.6.[0-9]|2.6.[0-9][!0-9]*) return 1 ;;
    2.6.1[0-9]|2.6.1[0-9][!0-9]*) return 1 ;;
    2.6.2[0-5]|2.6.2[0-5][!0-9]*) return 1 ;;
  esac
  return 0
}

check_installed_kernel() {
  for ver in /lib/modules/*; do
    ver=${ver##*/}
    [ "$ver" = '*' ] && return 1
    supported_kernel "$ver" && return 0
  done
  return 1
}

check_installing_kernel() {
  for pkg in $(ps hp $PARENT_PID -o args); do
    ver=$(echo $pkg | sed -nr "s/^.*linux-image-(2\.6\.[0-9]+)-([0-9]+|trunk)-.*_.*_.*\.deb$/\1/p")
    [ "$ver" ] && supported_kernel "$ver" && return 0
  done
  return 1
}

check_kernel_version() {
  # skip the check if udev is not already active
  [ -d /dev/.udev/ ] || return 0

  supported_kernel && return

  if [ -e /etc/udev/kernel-upgrade ]; then
    echo "This version of udev requires a kernel >= 2.6.26, but the upgrade was forced."
    # restart udevd which was killed by the old prerm
    udevd -d || true
    return 0
  fi
  
  db_settitle udev/title/upgrade

  if check_installed_kernel || check_installing_kernel; then
    db_fset udev/reboot_needed seen false
    db_input high udev/reboot_needed || true
    db_go
    db_stop
    echo "A reboot is needed, but proceeding with the upgrade."
    touch /etc/udev/kernel-upgrade
    # restart udevd which was killed by the old prerm
    udevd -d || true
    return 0
  fi

  db_fset udev/new_kernel_needed seen false
  db_reset udev/new_kernel_needed
  db_input critical udev/new_kernel_needed || true
  db_go
  db_get udev/new_kernel_needed
  if [ "$RET" = true ]; then
    db_stop
    echo "This version of udev requires a kernel >= 2.6.26, but the upgrade was forced."
    touch /etc/udev/kernel-upgrade
    # restart udevd which was killed by the old prerm
    udevd -d || true
    return 0
  fi
  db_stop
  exit 1
}

check_kernel_features() {
  # skip the check if udev is not already active
  [ -d /dev/.udev/ ] || return 0

  # skip the check if check_kernel_version() decided that a new kernel is
  # being installed
  [ -e /etc/udev/kernel-upgrade ] && return 0

  local abort_install=0

  if [ -e /proc/kallsyms ]; then

  local needed_symbols='sys_inotify_init sys_signalfd'
  local missing_symbol=0
  for symbol in $needed_symbols; do
    if ! egrep -q "^[a-fA-F0-9]+ T \.?${symbol}$" /proc/kallsyms; then
      missing_symbol=1
      abort_install=1
      break
    fi
  done

  fi

  local sysfs_deprecated=0
  if [ -d /sys/class/mem/null -a ! -L /sys/class/mem/null ]; then
    sysfs_deprecated=1
  fi

  if [ "$missing_symbol" -eq 1 ]; then
    cat <<END
Since release 146, udev requires support for the following features in
the running kernel:

- inotify(2)       (CONFIG_INOTIFY_USER)
- signalfd(2)      (CONFIG_SIGNALFD)
END
  fi

  if [ "$sysfs_deprecated" -eq 1 ]; then
    db_input critical udev/sysfs_deprecated_incompatibility || true
  fi

  if [ "$abort_install" -eq 0 ]; then
    return 0
  fi

  cat <<END

Please upgrade your kernel before or while upgrading udev.

AT YOUR OWN RISK, you can force the installation of this version of udev
WHICH DOES NOT WORK WITH YOUR RUNNING KERNEL AND WILL BREAK YOUR SYSTEM
AT THE NEXT REBOOT by creating the /etc/udev/kernel-upgrade file.
There is always a safer way to upgrade, do not try this unless you
understand what you are doing!


END

  db_stop
  exit 1
}

check_devfs_names() {
  [ -e /etc/udev/rules.d/devfs.rules ] || return 0

  cat <<END
Since release 0.124-1 udev does not support anymore devfs-like names.
Please convert to standard names before upgrading:

rm -f /etc/udev/rules.d/devfs.rules /etc/udev/rules.d/compat-full.rules /etc/udev/rules.d/compat.rules
ln -s ../udev.rules /etc/udev/rules.d/

END
  exit 1
}

rm_conffile() {
  mv_conffile "$1" "$1.dpkg-bak"
}

mv_conffile() {
  local package='udev'
  local name="$1"
  local newname="$2"

  [ -e "$name" ] || return 0

  local md5="$(md5sum $name | sed -e 's/ .*//')"
  oldmd5="$(dpkg-query -W -f='${Conffiles}' $package | \
    sed -n -e "\' $name ' { s/ obsolete$//; s/.* //; p }")"

  if [ "$md5" = "$oldmd5" ]; then
    rm -f "$name"
  else
    mv "$name" "$newname"
  fi
}

replace_sysfs_attr() {
  local file=$1
  [ -f $file ] || return 0
  egrep '^[^#].+\<SYSFS\{' $file || return 0

  sed -r -e '/^#/!s/\<SYSFS(\{[^}]+}==)/ATTR\1/g' < $file > $file.tmp
  mv $file.tmp $file
}

check_version() {
  # $2 is non-empty when installing from the "config-files" state
  [ "$2" ] || return 0

  if dpkg --compare-versions $2 lt 157-1; then

  if dpkg --compare-versions $2 lt 150-1; then

  # these must be checked first to allow aborting before changing anything
  check_kernel_version
  check_kernel_features

  if dpkg --compare-versions $2 lt 0.140-1; then
  if dpkg --compare-versions $2 lt 0.124-1; then

  # this must be checked first to allow aborting before changing anything
  check_devfs_names

  if dpkg --compare-versions $2 lt 0.098-1; then
    echo 'Upgrading udev from packages older than 0.098-1 is not supported.'
    echo 'Please purge the package and then reinstall it.'
    exit 1
  fi

  # lt 0.124-1
  rm_conffile /etc/udev/cd-aliases-generator.rules
  rm_conffile /etc/udev/compat-full.rules
  rm_conffile /etc/udev/compat.rules
  rm_conffile /etc/udev/devfs.rules
  rm_conffile /etc/udev/hotplug.rules
  rm_conffile /etc/udev/permissions.rules
  rm_conffile /etc/udev/persistent-input.rules
  rm_conffile /etc/udev/persistent-net-generator.rules
  rm_conffile /etc/udev/persistent.rules
  rm_conffile /etc/udev/run.rules
  rm_conffile /etc/udev/udev.rules
  # removed in 0.113-1
  rm_conffile /etc/udev/hotplugd.rules

  (
  cd /etc/udev/rules.d/

  # delete dangling symlinks
  find -L . -type l -print0 | xargs --no-run-if-empty --null rm

  # rename the generated files
  if [ -e z25_persistent-cd.rules  -a ! -e 70-persistent-cd.rules  ]; then
    mv z25_persistent-cd.rules  70-persistent-cd.rules
  fi
  if [ -e z25_persistent-net.rules -a ! -e 70-persistent-net.rules ]; then
    mv z25_persistent-net.rules 70-persistent-net.rules
  fi
  )

  fi # 0.124-1

  # lt 0.140-1
  rm_conffile /etc/modprobe.d/display_class
  rm_conffile /etc/modprobe.d/pnp-hotplug
  mv_conffile /etc/modprobe.d/blacklist /etc/modprobe.d/blacklist.conf

  for file in 50-udev 60-persistent-input 60-persistent-storage \
      60-persistent-storage-tape 60-persistent-v4l 91-permissions 80-drivers \
      75-cd-aliases-generator 75-persistent-net-generator 95-late; do
    rm_conffile /etc/udev/rules.d/$file.rules
  done

  # SYSFS is equivalent to ATTRS, and multiple ATTRS attributes do not match
  # when the keys are from different kobjects like in this case.
  replace_sysfs_attr /etc/udev/rules.d/70-persistent-net.rules

  fi # 0.140-1

  # lt 146-1
  rm_conffile /etc/scsi_id.config

  fi # 146-1

  # suppress errors when the new rules files contain options not supported by
  # the old daemon
  udevadm control --log-priority=0 || true

  fi # 157-1
}

case "$1" in
    install)
    check_version "$@"
    ;;

    upgrade|abort-upgrade)
    check_version "$@"
    ;;

    *)
    echo "$0 called with unknown argument '$1'" >&2
    exit 1
    ;;
esac

#DEBHELPER#