tazlito rev 468
tazlito: rework mergefs
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Oct 08 15:23:08 2017 +0200 (2017-10-08) |
parents | 993ff26f3328 |
children | 986e96c1ff6e |
files | tazlito |
line diff
1.1 --- a/tazlito Sun Oct 08 11:24:18 2017 +0200 1.2 +++ b/tazlito Sun Oct 08 15:23:08 2017 +0200 1.3 @@ -7,7 +7,7 @@ 1.4 # and/or a new ISO. Most commands must be run by root, except the stats 1.5 # and the configuration file manipulation. 1.6 # 1.7 -# (C) 2007-2016 SliTaz - GNU General Public License. 1.8 +# (C) 2007-2017 SliTaz - GNU General Public License. 1.9 # 1.10 # Authors: see the AUTHORS file 1.11 # 1.12 @@ -307,7 +307,7 @@ 1.13 done 1.14 dd if=$2/md5sum of=$1 conv=notrunc bs=2k \ 1.15 seek=$(stat -m /tmp/mnt$$/md5sum | sed q) 2> /dev/null 1.16 - umount -d //tmp/mnt$$ 1.17 + umount -d /tmp/mnt$$ 1.18 rmdir /tmp/mnt$$ 1.19 1.20 if [ -s '/etc/tazlito/info' ]; then 1.21 @@ -670,6 +670,36 @@ 1.22 1.23 # Remove duplicate files 1.24 1.25 +files_match() { 1.26 + if [ -d "$1" ]; then 1.27 + return 1 1.28 + 1.29 + elif [ -L "$1" ] && [ -L "$2" ]; then 1.30 + [ "$(readlink "$1")" == "$(readlink "$2")" ] && return 0 1.31 + 1.32 + elif [ -f "$1" ] && [ -f "$2" ]; then 1.33 + cmp -s "$1" "$2" && return 0 1.34 + 1.35 + [ "$(basename "$3")" == 'volatile.cpio.gz' ] && 1.36 + [ "$(dirname $(dirname "$3"))" == ".$INSTALLED" ] && 1.37 + return 0 1.38 + 1.39 + elif [ "$(ls -l "$1"|cut -c1-10)$(stat -c '%a:%u:%g:%t:%T' "$1")" == \ 1.40 + "$(ls -l "$2"|cut -c1-10)$(stat -c '%a:%u:%g:%t:%T' "$2")" ] && 1.41 + return 0 1.42 + 1.43 + fi 1.44 + return 1 1.45 +} 1.46 + 1.47 +remove_with_path() { 1.48 + dir="$(dirname $1)" 1.49 + rm -f "$1" 1.50 + while rmdir "$dir" 2> /dev/null; do 1.51 + dir="$(dirname $dir)" 1.52 + done 1.53 +} 1.54 + 1.55 mergefs() { 1.56 # Note, many packages have files with spaces in the name 1.57 IFS=$'\n' 1.58 @@ -681,37 +711,8 @@ 1.59 # merge symlinks files and devices 1.60 ( cd "$1"; find ) | \ 1.61 while read file; do 1.62 - if [ -L "$1/$file" ]; then 1.63 - [ -L "$2/$file" -a "$(readlink "$1/$file")" == "$(readlink "$2/$file")" ] && 1.64 - rm -f "$2/$file" 1.65 - 1.66 - elif [ -f "$1/$file" ]; then 1.67 - [ -f "$2/$file" ] && cmp -s "$1/$file" "$2/$file" && 1.68 - rm -f "$2/$file" 1.69 - 1.70 - [ -f "$2/$file" ] && 1.71 - [ "$(basename "$file")" == 'volatile.cpio.gz' ] && 1.72 - [ "$(dirname $(dirname "$file"))" == ".$INSTALLED" ] && 1.73 - rm -f "$2/$file" 1.74 - 1.75 - elif [ -b "$1/$file" ]; then 1.76 - [ -b "$2/$file" ] && 1.77 - [ "$(stat -c '%a:%u:%g:%t:%T' "$1/$file")" == \ 1.78 - "$(stat -c '%a:%u:%g:%t:%T' "$2/$file")" ] && 1.79 - rm -f "$2/$file" 1.80 - 1.81 - elif [ -c "$1/$file" ]; then 1.82 - [ -c "$2/$file" ] && 1.83 - [ "$(stat -c '%a:%u:%g:%t:%T' "$1/$file")" == \ 1.84 - "$(stat -c '%a:%u:%g:%t:%T' "$2/$file")" ] && 1.85 - rm -f "$2/$file" 1.86 - fi 1.87 - done 1.88 - 1.89 - # cleanup directories; TODO: simplify 1.90 - ( cd "$1"; find . -type d ) | sed '1!G;h;$!d' | \ 1.91 - while read file; do 1.92 - [ -d "$2/$file" ] && rmdir "$2/$file" 2>/dev/null 1.93 + files_match "$1/$file" "$2/$file" "$file" && 1.94 + remove_with_path "$2/$file" 1.95 done 1.96 1.97 unset IFS 1.98 @@ -2136,9 +2137,8 @@ 1.99 fi 1.100 done 1.101 1.102 - rm -f /etc/tazlito/rootfs.list 1.103 - grep -q '^Rootfs list' description && 1.104 - grep '^Rootfs list' description | sed 's/.*: \(.*\)$/\1/' > /etc/tazlito/rootfs.list 1.105 + sed '/^Rootfs list/!d;s/.*: //' description > /etc/tazlito/rootfs.list 1.106 + [ -s /etc/tazlito/rootfs.list ] || rm -f /etc/tazlito/rootfs.list 1.107 1.108 action 'Updating %s...' 'tazlito.conf' 1.109 [ -f tazlito.conf ] || cp /etc/tazlito/tazlito.conf .