Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- tmp1=`tempfile`
- tmp2=`tempfile`
- dir=`pwd`
- if [ "$1" != "--run-here" ]; then
- echo "$0 --run-here"
- exit 1
- fi
- cd /opt/dedup
- find -type f | grep -vE '^\./(DEBIAN|dedup)' | xargs -d '\n' sha256sum > $tmp1
- cd "$dir"
- find -type f | grep -vE '^\./(DEBIAN|dedup)' | xargs -d '\n' sha256sum > $tmp2
- cat >dedup_install.sh <<'EOF'
- #!/bin/bash
- dedup()
- {
- local file_source="$1"
- local file_target="$2"
- local uid="$3"
- local gid="$4"
- local mode="$5"
- local mtime="$6"
- cp "$file_source" "$file_target"
- chown $uid:$gid "$file_target"
- chmod $mode "$file_target"
- touch -d @$mtime "$file_target"
- }
- cd /
- echo -n "dedup: installing files... "
- EOF
- cat >dedup_remove.sh <<'EOF'
- #!/bin/bash
- echo -n "dedup: removing files... "
- EOF
- cat $tmp2 | while read line; do
- checksum=${line:0:64}
- filename=${line:68}
- if [ -L "${dir}/${filename}" ]; then
- continue
- fi
- line2=`cat $tmp1 | grep -E "^${checksum} " | head -n 1`
- if [ "$line2" == "" ]; then
- continue
- fi
- filename2=${line2:68}
- uid=`stat --format '%u' "${dir}/${filename}"`
- gid=`stat --format '%g' "${dir}/${filename}"`
- mode=`stat --format '%a' "${dir}/${filename}"`
- mtime=`stat --format '%Y' "${dir}/${filename}"`
- echo "dedup '/opt/dedup/${filename2}' '${filename}' $uid $gid $mode $mtime" >> dedup_install.sh
- echo "rm '${filename}'" >> dedup_remove.sh
- rm "${dir}/${filename}"
- done
- echo "echo \"done.\"" >> dedup_install.sh
- echo "echo \"done.\"" >> dedup_remove.sh
- chmod 700 dedup_remove.sh
- chmod 700 dedup_install.sh
- rm $tmp1
- rm $tmp2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement