source: live-build/trunk/fuentes/scripts/build/lb_chroot_hacks @ 900

Last change on this file since 900 was 900, checked in by kbut, 3 years ago

add original source

  • Property svn:executable set to *
File size: 8.5 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
5##
6## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7## This is free software, and you are welcome to redistribute it
8## under certain conditions; see COPYING for details.
9
10
11set -e
12
13# Including common functions
14( . "${LIVE_BUILD}/scripts/build.sh" > /dev/null 2>&1 || true ) || . /usr/lib/live/build.sh
15
16# Setting static variables
17DESCRIPTION="$(Echo 'execute hacks in chroot')"
18HELP=""
19USAGE="${PROGRAM} [--force]"
20
21Arguments "${@}"
22
23# Reading configuration files
24Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25Set_defaults
26
27Echo_message "Begin executing hacks..."
28
29# Requiring stage file
30Require_stagefile .build/config .build/bootstrap
31
32# Checking stage file
33Check_stagefile .build/chroot_hacks
34
35# Checking lock file
36Check_lockfile .lock
37
38# Creating lock file
39Create_lockfile .lock
40
41case "${LB_PARENT_DISTRIBUTION}" in
42        squeeze)
43                if echo "${LB_TASKS}" | grep -qs lxde ||
44                        echo "${LB_TASKS}" | grep -qs xfce
45                then
46                        GDM="gdm"
47                else
48                        GDM="gdm3"
49                fi
50                ;;
51
52        *)
53                GDM="gdm3"
54                ;;
55esac
56
57# Handling default desktop configuration
58case "${LB_MODE}" in
59        debian*)
60                # disable kexec-tools
61                if [ -e chroot/sbin/kexec ]
62                then
63                        echo "kexec-tools kexec-tools/load_kexec boolean false" > chroot/root/preseed
64                        Chroot chroot "debconf-set-selections /root/preseed"
65                        rm -f chroot/root/preseed
66                        Chroot chroot "dpkg-reconfigure kexec-tools"
67                fi
68                ;;
69esac
70
71for TASK in ${LB_TASKS}
72do
73        case "${TASK}" in
74                gnome-desktop)
75                        # gnome is the only desktop environment in this image
76                        if [ -z "$(echo ${LB_TASKS} | sed -e 's|gnome-desktop||' -e 's| desktop ||' | grep desktop)" ]
77                        then
78                                # set display manager
79                                echo "${GDM} shared/default-x-display-manager select ${GDM}" > chroot/root/preseed
80                                Chroot chroot "debconf-set-selections /root/preseed"
81                                rm -f chroot/root/preseed
82                                Chroot chroot "dpkg-reconfigure ${GDM}"
83                                echo "/usr/bin/${GDM}" > chroot/etc/X11/default-display-manager
84
85                                # set session manager
86                                Chroot chroot "update-alternatives --set x-session-manager /usr/bin/gnome-session"
87                        fi
88                        ;;
89
90                kde-desktop)
91                        # kde is the only desktop-environment in this image
92                        if [ -z "$(echo ${LB_TASKS} | sed -e 's|kde-desktop||' -e 's| desktop ||' | grep desktop)" ]
93                        then
94                                # set display manager
95                                echo "kdm shared/default-x-display-manager select kdm" > chroot/root/preseed
96                                Chroot chroot "debconf-set-selections /root/preseed"
97                                rm -f chroot/root/preseed
98                                Chroot chroot "dpkg-reconfigure kdm"
99                                echo "/usr/bin/kdm" > chroot/etc/X11/default-display-manager
100
101                                # set session manager
102                                Chroot chroot "update-alternatives --set x-session-manager /usr/bin/startkde"
103
104                                # get rid of resolvconf
105                                Chroot chroot "dpkg -P resolvconf"
106                        fi
107                        ;;
108
109                lxde-desktop)
110                        # lxde is the only desktop environment in this image
111                        if [ -z "$(echo ${LB_TASKS} | sed -e 's|lxde-desktop||' -e 's| desktop ||' | grep desktop)" ]
112                        then
113                                # set display manager
114                                echo "${GDM} shared/default-x-display-manager select ${GDM}" > chroot/root/preseed
115                                Chroot chroot "debconf-set-selections /root/preseed"
116                                rm -f chroot/root/preseed
117                                Chroot chroot "dpkg-reconfigure ${GDM}"
118                                echo "/usr/bin/${GDM}" > chroot/etc/X11/default-display-manager
119
120                                # set session manager
121                                Chroot chroot "update-alternatives --set x-session-manager /usr/bin/startlxde"
122                        fi
123                        ;;
124
125                xfce-desktop)
126                        # xfce is the only desktop environment in this image
127                        if [ -z "$(echo ${LB_TASKS} | sed -e 's|xfce-desktop||' -e 's| desktop ||' | grep desktop)" ]
128                        then
129                                # set display manager
130                                echo "${GDM} shared/default-x-display-manager select ${GDM}" > chroot/root/preseed
131                                Chroot chroot "debconf-set-selections /root/preseed"
132                                rm -f chroot/root/preseed
133                                Chroot chroot "dpkg-reconfigure ${GDM}"
134                                echo "/usr/bin/${GDM}" > chroot/etc/X11/default-display-manager
135
136                                # set session manager
137                                Chroot chroot "update-alternatives --set x-session-manager /usr/bin/xfce4-session"
138                        fi
139                        ;;
140        esac
141done
142
143case "${LB_BINARY_IMAGES}" in
144        netboot)
145                if [ ! -f chroot/sbin/mount.cifs ]
146                then
147                        Apt chroot install cifs-utils
148                fi
149
150                if [ ! -d chroot/etc/initramfs-tools ]
151                then
152                        mkdir chroot/etc/initramfs-tools
153                fi
154
155                # Configuring initramfs for NFS
156                if ! grep -qs "BOOT=nfs" chroot/etc/initramfs-tools/initramfs.conf
157                then
158                        echo "BOOT=nfs" >> chroot/etc/initramfs-tools/initramfs.conf
159                fi
160
161                if ! grep -qs "NFSROOT=auto" chroot/etc/initramfs-tools/initramfs.conf
162                then
163                        echo "NFSROOT=auto" >> chroot/etc/initramfs-tools/initramfs.conf
164                fi
165                ;;
166esac
167
168# Update initramfs (always, because of udev rules in initrd)
169case "${LB_INITRAMFS}" in
170        casper)
171                UPDATE_INITRAMFS_OPTIONS="CASPER_GENERATE_UUID=1"
172                ;;
173
174        live-boot)
175                #UPDATE_INITRAMFS_OPTIONS="LIVE_GENERATE_UUID=1"
176                ;;
177esac
178
179case "${SUBPROJECT}" in
180        wubi)
181                UPDATE_INITRAMFS_OPTIONS="$UPDATE_INITRAMFS_OPTIONS FRAMEBUFFER=y"
182                ;;
183esac
184
185if [ "${LB_INITRAMFS}" != "none" ]
186then
187        Chroot chroot "${UPDATE_INITRAMFS_OPTIONS} update-initramfs -k all -t -u"
188fi
189
190# We probably ought to use COMPRESS= in a temporary file in
191# /etc/initramfs-tools/conf.d/ instead, but it's hard to pass options that
192# way.
193case "${LB_INITRAMFS_COMPRESSION}" in
194        gzip)
195                ;;
196
197        bzip2)
198                for INITRAMFS in $(find chroot/boot -name 'initrd*'); do
199                        zcat "${INITRAMFS}" | bzip2 -c ${BZIP2_OPTIONS} > "${INITRAMFS}.new"
200                        mv "${INITRAMFS}.new" "${INITRAMFS}"
201                done
202                ;;
203
204        lzma)
205                # We probably ought to use COMPRESS= in a temporary file in
206                # /etc/initramfs-tools/conf.d/ instead, but it's hard to
207                # pass options that way.
208                for INITRAMFS in $(find chroot/boot -name 'initrd*'); do
209                        zcat "${INITRAMFS}" | lzma -c ${LZMA_OPTIONS} > "${INITRAMFS}.new"
210                        mv "${INITRAMFS}.new" "${INITRAMFS}"
211                done
212                ;;
213esac
214
215# Ensure readable permissions on initramfs. loop-aes-utils sets umask to
216# protect GPG keys, which live-build does not support.
217# Note: Use find rather than chmod on the wildcard, one never knows what
218# people might do in local hooks, and there might be no initrds at all.
219find chroot/boot -name 'initrd*' -print0 | xargs -r -0 chmod go+r
220
221# Remove cruft
222rm -f chroot/boot/initrd*bak*
223rm -f chroot/etc/apt/trusted.gpg~
224rm -f chroot/etc/group- chroot/etc/passwd-
225rm -f chroot/etc/gshadow- chroot/etc/shadow-
226rm -f chroot/var/cache/debconf/*-old
227rm -f chroot/var/lib/dpkg/*-old
228rm -f chroot/var/log/apt/term.log
229rm -f chroot/etc/adjtime
230
231# Delete and re-create temporary directories
232TEMP_DIRS="/tmp /var/tmp"
233for DIR in ${TEMP_DIRS}
234do
235        rm -rf "chroot/${DIR}"
236        install -d -m 1777 "chroot/${DIR}"
237done
238
239if [ -n "${LB_ROOT_COMMAND}" ]
240then
241        ${LB_ROOT_COMMAND} chown -R --quiet $(whoami):$(whoami) chroot
242fi
243
244case "${LB_INITRAMFS}" in
245        casper)
246                ID="999"
247                ;;
248
249        live-boot)
250                ID="1000"
251                ;;
252
253        *)
254                ID=""
255                ;;
256esac
257
258if [ "${LB_DEBIAN_INSTALLER}" = "live" ]
259then
260        # This is a temporary hack to get rid of fstab;
261        # needs cleanup in live-boot first to proper fix.
262        rm -f chroot/etc/fstab
263        touch chroot/etc/fstab
264fi
265
266if [ "${LB_EXPOSED_ROOT}" = "true" ]
267then
268        # Make sure RW dirs exist so that the initramfs script has
269        # a directory in which to bind the tmpfs filesystems
270        COW_DIRECTORIES="/home /live /tmp /var/lib/live /var/lock /var/log /var/run /var/tmp /var/spool"
271
272        for DIRECTORY in ${COW_DIRECTORIES}
273        do
274                mkdir -p chroot/"${DIRECTORY}"
275        done
276
277        # Config files which need to be RW
278        COW_FILES="/etc/fstab /etc/hostname /etc/hosts /etc/live.conf /etc/network/interfaces /etc/resolv.conf /etc/udev/rules.d/*persistent-net.rules /etc/udev/rules.d/*persistent-cd.rules /etc/X11/xorg.conf"
279
280        # Where we will store RW config files
281        RW_DIRECTORY="/var/lib/live"
282
283        for FILE in ${COW_FILES}
284        do
285                DIRECTORY="$(dirname ${FILE})"
286                FILE="$(basename ${FILE})"
287                RELATIVE_PATH="$(echo ${DIRECTORY} | sed 's|[^/]\+|..|g; s|^/||g')"
288
289                # Touch files in case they don't yet exist
290                mkdir -p chroot/${DIRECTORY}
291                touch chroot/${DIRECTORY}/${FILE}
292
293                # Move files to the read-write directory
294                mkdir -p chroot/${RW_DIRECTORY}/${DIRECTORY}
295                mv chroot/${DIRECTORY}/${FILE} chroot/${RW_DIRECTORY}/${DIRECTORY}
296
297                # Create a symbolic link to RW config file
298                ln -s ${RELATIVE_PATH}/${RW_DIRECTORY}/${DIRECTORY}/${FILE} chroot/${DIRECTORY}/${FILE}
299        done
300
301        # Mount doesn't write to a symlink so use /proc/mounts instead,
302        # see debian bug #154438 for more info
303        rm -f chroot/etc/mtab
304        ln -s /proc/mounts chroot/etc/mtab
305fi
306
307if [ "${LB_SWAP_FILE_PATH}" ]; then
308        dd if=/dev/zero of="chroot/${LB_SWAP_FILE_PATH}" bs=1024k count="${LB_SWAP_FILE_SIZE}"
309        mkswap "chroot/${LB_SWAP_FILE_PATH}"
310fi
311
312# Creating stage file
313Create_stagefile .build/chroot_hacks
Note: See TracBrowser for help on using the repository browser.