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

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

add original source

  • Property svn:executable set to *
File size: 2.9 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 hooks 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 hooks..."
28
29# Requiring stage file
30Require_stagefile .build/config .build/bootstrap
31
32# Checking stage file
33Check_stagefile .build/chroot_hooks
34
35# Checking lock file
36Check_lockfile .lock
37
38# Creating lock file
39Create_lockfile .lock
40
41## Processing distribution hooks
42
43# Make build config available to chroot hooks. First, make the bind
44# mount and then make it read-only. This can't happen in one mount
45# command, then the resulting mount will be rw (see mount(8)). Making it
46# ro prevents modifications and prevents accidentally removing the
47# contents of the config directory when removing the chroot.
48mkdir -p chroot/root/config
49mount -o bind config chroot/root/config
50mount -o remount,ro,bind config chroot/root/config
51
52# Copying hooks
53for _HOOK in ${LB_CHROOT_HOOKS}
54do
55        for LOCATION in "${LIVE_BUILD}/hooks" /usr/share/live/build/hooks
56        do
57                for FILE in "${LOCATION}"/???-"${_HOOK}".chroot
58                do
59                        if [ -e "${FILE}" ]
60                        then
61                                mkdir -p chroot/root/lb_chroot_hooks
62                                cp "${FILE}" chroot/root/lb_chroot_hooks
63                        fi
64                done
65        done
66done
67
68# Running hooks
69if ls chroot/root/lb_chroot_hooks/* > /dev/null 2>&1
70then
71        for _HOOK in chroot/root/lb_chroot_hooks/*
72        do
73                Chroot chroot "/root/lb_chroot_hooks/$(basename ${_HOOK})" || { Echo_error "${_HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
74                rm -f chroot/root/lb_chroot_hooks/"$(basename ${_HOOK})"
75        done
76
77        rmdir chroot/root/lb_chroot_hooks
78fi
79
80## Processing local hooks
81
82if Find_files config/hooks/*.chroot
83then
84        # Restoring cache
85        Restore_cache cache/packages.chroot
86
87        for _HOOK in config/hooks/*.chroot
88        do
89                # Copying hook
90                cp "${_HOOK}" chroot/root
91
92                # Making hook executable
93                if [ ! -x chroot/root/"$(basename ${_HOOK})" ]
94                then
95                        chmod +x chroot/root/"$(basename ${_HOOK})"
96                fi
97
98                # Executing hook
99                Chroot chroot "/root/$(basename ${_HOOK})" || { Echo_error "${_HOOK} failed (exit non-zero). You should check for errors."; exit 1 ;}
100
101                # Removing hook
102                rm -f chroot/root/"$(basename ${_HOOK})"
103        done
104
105        # Saving cache
106        Save_cache cache/packages.chroot
107
108        # Creating stage file
109        Create_stagefile .build/chroot_hooks
110fi
111
112# Remove bind mount of build config inside chroot.
113umount chroot/root/config
114rmdir chroot/root/config
115
Note: See TracBrowser for help on using the repository browser.