Debian Codegraph @

etc/setup.d/20copyfiles

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 6 — not the installed (fully patched) source.
6 Debian patches touch this file
1 #!/bin/sh
2 # Copyright © 2005-2007 Roger Leigh <[email protected]>
3 #
4 # schroot is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # schroot is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see
16 # <http://www.gnu.org/licenses/>.
17 #
18 #####################################################################
19
20 set -e
21
22 . "$SETUP_DATA_DIR/common-data"
23 . "$SETUP_DATA_DIR/common-functions"
24 . "$SETUP_DATA_DIR/common-config"
25
26 if [ "$VERBOSE" = "verbose" ]; then
27 CP_VERBOSE="--verbose"
28 fi
29
30 # Copy a file if the source and destination differ
31 # $1: source file
32 # $2: destination file
33 copy_file()
34 {
35 if [ -e "$1" ]; then
36
37 COPY="true"
38
39 if [ -e "$2" ]; then
40
41 # Device and inode
42 da=$(/usr/bin/stat --format="%d %i" "$1")
43 # This one can fail since it might not exist yet
44 db=$(/usr/bin/stat --format="%d %i" "$2" 2>/dev/null || :)
45
46 if [ "$da" = "$db" ]; then
47 COPY="false"
48 elif [ -L "$2" ]; then
49 # Copy if destination is a symlink
50 :
51 elif [ -f "$1" ] && [ -f "$2" ]; then
52 # Content
53 ca=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/')
54 cb=$(/usr/bin/md5sum "$2" 2>/dev/null || :)
55 cb=$(echo "$cb" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/')
56 # Copy only if file contents differ
57 if [ "$ca" = "$cb" ]; then
58 COPY="false"
59 fi
60 fi
61 fi
62
63 # Copy only if files are different
64 if [ "$COPY" = "true" ]; then
65 if [ -f "$1" ]; then
66 cp --preserve=all $CP_VERBOSE "$1" "$2"
67 else
68 # Copy non-regular file directly
69 cp -a $CP_VERBOSE "$1" "$2"
70 fi
71 fi
72
73 else
74 fatal "Not copying nonexistent file: $file"
75 fi
76 }
77
78 if [ $STAGE = "setup-start" ] || [ $STAGE = "setup-recover" ]; then
79
80 if [ -n "$SETUP_COPYFILES" ]; then
81 if [ -f "$SETUP_COPYFILES" ]; then
82 while read file; do
83 if echo "$file" | egrep -q '^(#|$)' ; then
84 continue
85 fi
86 if echo "$file" | grep -q '^/'; then
87 copy_file "$file" "${CHROOT_PATH}$file"
88 else
89 warn "Not copying file with relative path: $file"
90 fi
91 done < "$SETUP_COPYFILES"
92 else
93 fatal "copyfiles file '$SETUP_COPYFILES' does not exist"
94 fi
95 fi
96
97 fi
98