summaryrefslogtreecommitdiff
path: root/src/samizdat-diff-root
blob: ea9bb85273d9ef334ff87779a134a92078660f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
mp=/mnt/root.tmp
fs=/

excludes='--exclude /var/log/ --exclude /tmp/'

devs()
{
  btrfs fi sh "$fs"  | sed -ne 's?^[ \t]*devid[ \t].*/dev?/dev?p'
}

[ $(id -u) = 0 ] || exec sudo "$0" "$@" || exit

if ! [ -e "$mp" ] || ! mountpoint -q "$mp"
then
  mkdir -p "$mp"
  dev=$(devs | tail -n1) || exit
  mount -t btrfs "$dev" -o subvol=/ "$mp" || exit
fi

case $# in
  0) run()
     {
       rsync -xani $excludes "$mp"/root/ "$mp"/root~orig/
     }
     ;;
  *) run()
     {
       for f
       do
         diff "$mp"/root/"$f" "$mp"/root~orig/"$f"
       done
     }
     ;;
esac
if [ -t 0 ]
then
  run "$@" | less
else
  run "$@"
fi

umount "$mp"