diff options
Diffstat (limited to 'etc/setup.d/20copyfiles')
-rwxr-xr-x | etc/setup.d/20copyfiles | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/etc/setup.d/20copyfiles b/etc/setup.d/20copyfiles index bbeb2482..2c01af9e 100755 --- a/etc/setup.d/20copyfiles +++ b/etc/setup.d/20copyfiles @@ -34,64 +34,64 @@ copy_file() { if [ -e "$1" ]; then - COPY="true" + COPY="true" - if [ -e "$2" ]; then + if [ -e "$2" ]; then # Device and inode - da=$(/usr/bin/stat --format="%d %i" "$1") - # This one can fail since it might not exist yet - db=$(/usr/bin/stat --format="%d %i" "$2" 2>/dev/null || :) + da=$(/usr/bin/stat --format="%d %i" "$1") + # This one can fail since it might not exist yet + db=$(/usr/bin/stat --format="%d %i" "$2" 2>/dev/null || :) - if [ "$da" = "$db" ]; then - COPY="false" - elif [ -L "$2" ]; then - # Copy if destination is a symlink - : - elif [ -f "$1" ] && [ -f "$2" ]; then + if [ "$da" = "$db" ]; then + COPY="false" + elif [ -L "$2" ]; then + # Copy if destination is a symlink + : + elif [ -f "$1" ] && [ -f "$2" ]; then # Content - ca=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') - cb=$(/usr/bin/md5sum "$2" 2>/dev/null || :) - cb=$(echo "$cb" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') - # Copy only if file contents differ - if [ "$ca" = "$cb" ]; then - COPY="false" - fi - fi - fi + ca=$(/usr/bin/md5sum "$1" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + cb=$(/usr/bin/md5sum "$2" 2>/dev/null || :) + cb=$(echo "$cb" | sed -e 's/\(^[0-9a-f][0-9a-f]*\).*$/\1/') + # Copy only if file contents differ + if [ "$ca" = "$cb" ]; then + COPY="false" + fi + fi + fi - # Copy only if files are different - if [ "$COPY" = "true" ]; then - if [ -f "$1" ]; then - cp --preserve=all $CP_VERBOSE "$1" "$2" - else - # Copy non-regular file directly - cp -a $CP_VERBOSE "$1" "$2" - fi - fi + # Copy only if files are different + if [ "$COPY" = "true" ]; then + if [ -f "$1" ]; then + cp --preserve=all $CP_VERBOSE "$1" "$2" + else + # Copy non-regular file directly + cp -a $CP_VERBOSE "$1" "$2" + fi + fi else - fatal "Not copying nonexistent file: $file" + fatal "Not copying nonexistent file: $file" fi } if [ $STAGE = "setup-start" ] || [ $STAGE = "setup-recover" ]; then if [ -n "$SETUP_COPYFILES" ]; then - if [ -f "$SETUP_COPYFILES" ]; then - while read file; do - if echo "$file" | egrep -q '^(#|$)' ; then - continue - fi - if echo "$file" | grep -q '^/'; then - copy_file "$file" "${CHROOT_PATH}$file" - else - warn "Not copying file with relative path: $file" - fi - done < "$SETUP_COPYFILES" - else - fatal "copyfiles file '$SETUP_COPYFILES' does not exist" - fi + if [ -f "$SETUP_COPYFILES" ]; then + while read file; do + if echo "$file" | egrep -q '^(#|$)' ; then + continue + fi + if echo "$file" | grep -q '^/'; then + copy_file "$file" "${CHROOT_PATH}$file" + else + warn "Not copying file with relative path: $file" + fi + done < "$SETUP_COPYFILES" + else + fatal "copyfiles file '$SETUP_COPYFILES' does not exist" + fi fi fi |