Initial checkin
[live-initramfs-grml.git] / bin / live-reconfigure
1 #! /bin/sh
2
3 set -e
4
5 export PATH=/usr/bin:/usr/sbin:/sbin:/bin
6
7 frontend=noninteractive
8
9 findcommandinroot ()
10 {
11         ROOT="${1}/"
12         shift
13
14         while [ "${#}" -ge 1 ]
15         do
16                 P="${PATH}"
17
18                 while [ "${P}" ]
19                 do
20                         D=${P%%:*}
21                         P=${P#*:}
22
23                         if [ "${D}" = "${P}" ]
24                         then
25                                 P=
26                         fi
27
28                         if [ -z "${D}" ]
29                         then
30                                 D=.
31                         fi
32
33                         if [ -x "${ROOT}${D}/${1}" ]
34                         then
35                                 echo "${D}/${1}"
36                                 return 0
37                         fi
38                 done
39
40                 shift
41         done
42
43         return 1
44 }
45
46 runcommandinroot ()
47 {
48         C=$(findcommandinroot "${1}" "${2}")
49         ROOT="${1}"
50
51         shift
52         shift
53
54         [ -n "${C}" ] && chroot "${ROOT}" "${C}" "${@}"
55 }
56
57 root="${1}"
58 package="${2}"
59
60 version=$(runcommandinroot "${root}" dpkg-query -W --showformat='${Version}' "${package}" 2>/dev/null) || version=""
61
62 if [ -z "${version}" ]
63 then
64         echo >&2 "${0}: package '${package}' is not installed"
65         exit 0
66 fi
67
68 runcommandinroot "${root}" dpkg-reconfigure -fnoninteractive --no-reload "${package}"
69
70 exit 0