change the date
[tools/build.git] / build-pkg-deb
1 #
2 # Debian dpkg specific functions.
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24 #
25 # A wrapper around chroot to set the environment correctly for dpkg and
26 # pre/postinst scripts.
27 #
28 deb_chroot ()
29 {
30     #
31     # to workaround some version of fileutils that doesn't do a 'chdir /'
32     # when doing a 'chroot /' call lets subshell and change dir manually
33     #
34     (
35         cd $1 &&
36             DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical \
37                            DEBCONF_NONINTERACTIVE_SEEN=true \
38                            LC_ALL=C LANGUAGE=C LANG=C \
39                            chroot $*
40     )
41 }
42
43 deb_setup() {
44     mkdir -p "$BUILD_ROOT"/var/lib/dpkg
45     mkdir -p "$BUILD_ROOT"/var/log
46     mkdir -p "$BUILD_ROOT"/etc/default
47     :>> "$BUILD_ROOT"/var/lib/dpkg/status
48     :>> "$BUILD_ROOT"/var/lib/dpkg/available
49     :>> "$BUILD_ROOT"/var/log/dpkg.log
50     :>> "$BUILD_ROOT"/etc/ld.so.conf
51     :>> "$BUILD_ROOT"/etc/default/rcS
52 }
53
54 pkg_initdb_deb() {
55     deb_setup
56     # force dpkg into database to make epoch test work
57     if ! test "$BUILD_ROOT/.init_b_cache/rpms/dpkg.deb" -ef "$BUILD_ROOT/.init_b_cache/dpkg.deb" ; then
58         rm -f "$BUILD_ROOT"/.init_b_cache/dpkg.deb
59         cp "$BUILD_ROOT"/.init_b_cache/rpms/dpkg.deb "$BUILD_ROOT"/.init_b_cache/dpkg.deb || cleanup_and_exit 1
60     fi
61     deb_chroot "$BUILD_ROOT" dpkg --install --force-depends .init_b_cache/dpkg.deb >/dev/null 2>&1
62 }
63
64 pkg_prepare_deb() {
65     :
66 }
67
68 pkg_install_deb() {
69     ( deb_chroot "$BUILD_ROOT" dpkg --install --force-depends .init_b_cache/$PKG.deb 2>&1 || touch "$BUILD_ROOT"/exit ) | \
70         perl -ne '$|=1;/^(Configuration file|Installing new config file|Selecting previously deselected|Selecting previously unselected|\(Reading database|Unpacking |Setting up|Creating config file|Preparing to replace dpkg|Preparing to unpack )/||/^$/||print'
71     # ugly workaround for upstart system. some packages (procps) try
72     # to start a service in their configure phase. As we don't have
73     # a running upstart, we just link the start binary to /bin/true
74     if test -e "$BUILD_ROOT/sbin/start"; then
75         if test "$BUILD_ROOT/sbin/start" -ef "$BUILD_ROOT/sbin/initctl" ; then
76             echo "linking /sbin/start to /bin/true"
77             mv "$BUILD_ROOT/sbin/start" "$BUILD_ROOT/sbin/start.disabled"
78             ln -s "/bin/true" "$BUILD_ROOT/sbin/start"
79         fi
80     fi
81     # another workaround, see bug bnc#733699
82     rm -f "$BUILD_ROOT/var/run/init.upgraded"
83 }
84
85 pkg_erase_deb() {
86     deb_chroot "$BUILD_ROOT" dpkg --purge --force-depends $PKG 2>&1 | {
87       local retry
88       while read line; do
89           case "$line" in
90               subprocess\ installed\ *script\ returned\ error\ exit\ status*)
91                  chroot "$BUILD_ROOT" rm -f /var/lib/dpkg/info/$PKG.{pre,post}rm
92                  retry=1
93               ;;
94               *) echo "$line" ;;
95           esac
96       done
97       if test -n "$retry"; then
98           echo "re-try deleting $PKG without post/pre remove scripts"
99           deb_chroot "$BUILD_ROOT" dpkg --purge --force-depends $PKG 2>&1 || touch "$BUILD_ROOT"/exit
100       fi
101     } | perl -ne '$|=1;/^(\(Reading database|Removing |Purging configuration files for )/||/^$/||print'
102 }
103
104 pkg_cumulate_deb() {
105     return 1
106 }
107
108 pkg_verify_installed_deb() {
109     return 1
110 }
111
112 pkg_finalize_deb() {
113     echo "configuring all installed packages..."
114     # configure all packages after complete installation, not for each package like rpm does
115     # We need to run this twice, because of cyclic dependencies as it does not succeed on most
116     # debian based distros in the first attempt.
117     if ! deb_chroot "$BUILD_ROOT" dpkg --configure --pending  2>&1; then
118          echo "first configure attempt failed, trying again..."
119          deb_chroot "$BUILD_ROOT" dpkg --configure --pending  2>&1 || cleanup_and_exit 1
120     fi
121 }
122
123 pkg_preinstall_deb() {
124     ar x "$BUILD_ROOT/.init_b_cache/rpms/$PKG.deb"
125     mkdir -p .init_b_cache/scripts/control
126     $TAR -C .init_b_cache/scripts/control -z -f control.tar.gz
127     if test -f "data.tar.gz" ; then
128         $TAR -z -f data.tar.gz
129     elif test -f "data.tar.xz" ; then
130         $TAR -J -f data.tar.xz
131     fi
132     if test -e ".init_b_cache/scripts/$PKG.run" ; then
133         test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst ".init_b_cache/scripts/$PKG.pre"
134         test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst ".init_b_cache/scripts/$PKG.post"
135     fi
136     rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.{g,x}z
137 }
138
139 pkg_runscripts_deb() {
140     if ! test -e "$BUILD_ROOT"/var/lib/dpkg/status ; then
141         deb_setup
142     fi
143     if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
144         echo "running $PKG preinstall script"
145         deb_chroot "$BUILD_ROOT" ".init_b_cache/scripts/$PKG.pre" install \
146                    < /dev/null
147         rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
148     fi
149     if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
150         echo "running $PKG postinstall script"
151         deb_chroot "$BUILD_ROOT" ".init_b_cache/scripts/$PKG.post" configure '' \
152                    < /dev/null
153         rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
154     fi
155 }
156
157 # Local Variables:
158 # mode: Shell-script
159 # End: