Updating year in copyright notices to 2015.
[debian-live-build.git] / scripts / build / chroot_hosts
blobab0ea66856cc175f7b5e89e2316682ebd51513cc
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2015 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/hosts')"
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/hosts"
34 # Checking stage file
35 Check_stagefile .build/chroot_hosts
37 # Checking lock file
38 Check_lockfile .lock
40 # Creating lock file
41 Create_lockfile .lock
43 if [ -f chroot/etc/hosts ]
44 then
45 # Save hosts file
46 mv chroot/etc/hosts chroot/etc/hosts.orig
49 # Creating hosts file
51 cat > chroot/etc/hosts << EOF
52 127.0.0.1 localhost localhost.localdomain
53 127.0.1.1 debian
54 EOF
56 if [ -f /etc/hosts ]
57 then
58 # Append hosts file
59 #grep -e "127.0.0.1" -e "127.0.1.1" /etc/hosts >> chroot/etc/hosts
60 cat /etc/hosts >> chroot/etc/hosts
63 # Creating stage file
64 Create_stagefile .build/chroot_hosts
67 remove)
68 Echo_message "Deconfiguring file /etc/hosts"
70 # Checking lock file
71 Check_lockfile .lock
73 # Creating lock file
74 Create_lockfile .lock
76 if [ -e config/includes.chroot/etc/hosts ]
77 then
78 # Copying local hosts
79 cp -a config/includes.chroot/etc/hosts chroot/etc/hosts
80 rm -f chroot/etc/hosts.orig
81 elif [ -f chroot/etc/hosts.orig ]
82 then
83 # Restore hosts file
84 mv chroot/etc/hosts.orig chroot/etc/hosts
85 else
86 # Blank out hosts file, don't remove in case its a symlink
87 Truncate chroot/etc/hosts
90 # Removing stage file
91 rm -f .build/chroot_hosts
95 Usage
97 esac