Moving partial python rewrite to separate branch, let's do it in the jessie+1 cycle...
[debian-live-build.git] / scripts / build / chroot_resolv
blob5f5b0650eb5ac9906a7b5b00430419b452bc9175
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
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.
11 set -e
13 # Including common functions
14 [ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
16 # Setting static variables
17 DESCRIPTION="$(Echo 'manage /etc/resolv.conf')"
18 HELP=""
19 USAGE="${PROGRAM} {install|remove} [--force]"
21 Arguments "${@}"
23 # Reading configuration files
24 Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
25 Set_defaults
27 # Requiring stage file
28 Require_stagefile .build/config .build/bootstrap
30 case "${1}" in
31 install)
32 Echo_message "Configuring file /etc/resolv.conf"
34 # Checking stage file
35 Check_stagefile .build/chroot_resolv
37 # Checking lock file
38 Check_lockfile .lock
40 # Creating lock file
41 Create_lockfile .lock
43 if [ -e chroot/etc/resolv.conf ]
44 then
45 # Save resolv file or symlink
46 mv chroot/etc/resolv.conf chroot/etc/resolv.conf.orig
48 # Also truncate it, otherwise we'll end up with the one
49 # created by debootstrap in the final image.
51 # If you want to have a custom resolv.conf, please
52 # overwrite it with normal local_includes mechanism.
53 Truncate chroot/etc/resolv.conf.orig
54 elif [ -L chroot/etc/resolv.conf ]
55 then
56 # Move resolv.conf aside if it's a symlink (likely resolvconf)
57 mv chroot/etc/resolv.conf chroot/etc/resolv.conf.orig
60 if [ -f /etc/resolv.conf ]
61 then
62 # Copy resolv file
63 cp /etc/resolv.conf chroot/etc/resolv.conf
66 # Creating stage file
67 Create_stagefile .build/chroot_resolv
70 remove)
71 Echo_message "Deconfiguring file /etc/resolv.conf"
73 # Checking lock file
74 Check_lockfile .lock
76 # Creating lock file
77 Create_lockfile .lock
79 if [ -e config/includes.chroot/etc/resolv.conf ]
80 then
81 # Copying local resolv.conf
82 cp -a config/includes.chroot/etc/resolv.conf chroot/etc/resolv.conf
83 rm -f chroot/etc/resolv.conf.orig
84 elif [ -e chroot/etc/resolv.conf.orig ] || [ -L chroot/etc/resolv.conf.orig ]
85 then
86 # Restoring resolv file or symlink
87 mv chroot/etc/resolv.conf.orig chroot/etc/resolv.conf
88 else
89 # Truncating resolv file
90 Truncate chroot/etc/resolv.conf
93 # Clean up resolvconf's pollution
94 if [ -e chroot/etc/resolvconf/resolv.conf.d ]
95 then
96 rm -f chroot/etc/resolvconf/resolv.conf.d/original
97 rm -f chroot/etc/resolvconf/resolv.conf.d/tail
100 # Removing stage file
101 rm -f .build/chroot_resolv
105 Usage
107 esac