]> arthur.barton.de Git - bup.git/blob - t/test-restore-map-owner.sh
Add --map-user --map-group --map-uid and --map-gid options to restore.
[bup.git] / t / test-restore-map-owner.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3
4 if [ $(t/root-status) != root ]; then
5     echo 'Not root: skipping restore --map-* tests.'
6     exit 0 # FIXME: add WVSKIP.
7 fi
8
9 top="$(WVPASS pwd)" || exit $?
10 tmpdir="$(WVPASS wvmktempdir)" || exit $?
11 export BUP_DIR="$tmpdir/bup"
12
13 bup() { "$top/bup" "$@"; }
14
15 uid=$(WVPASS id -u) || exit $?
16 user=$(WVPASS id -un) || exit $?
17 gid=$(WVPASS id -g) || exit $?
18 group=$(WVPASS id -gn) || exit $?
19
20 other_uinfo=$(WVPASS t/id-other-than --user "$user") || exit $?
21 other_user="${other_uinfo%%:*}"
22 other_uid="${other_uinfo##*:}"
23
24 other_ginfo=$(WVPASS t/id-other-than --group "$group") || exit $?
25 other_group="${other_ginfo%%:*}"
26 other_gid="${other_ginfo##*:}"
27
28 WVPASS bup init
29 WVPASS cd "$tmpdir"
30
31 WVSTART "restore --map-user/group/uid/gid (control)"
32 WVPASS mkdir src
33 WVPASS touch src/foo
34 WVPASS bup index src
35 WVPASS bup save -n src src
36 WVPASS bup restore -C dest "src/latest/$(pwd)/src/"
37 WVPASS bup xstat dest/foo > foo-xstat
38 WVPASS grep -qE "^user: $user\$" foo-xstat
39 WVPASS grep -qE "^uid: $uid\$" foo-xstat
40 WVPASS grep -qE "^group: $group\$" foo-xstat
41 WVPASS grep -qE "^gid: $gid\$" foo-xstat
42
43 WVSTART "restore --map-user/group/uid/gid (user/group)"
44 WVPASS rm -rf dest
45 # Have to remap uid/gid too because we're root and 0 would win).
46 WVPASS bup restore -C dest \
47     --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
48     --map-user "$user=$other_user" --map-group "$group=$other_group" \
49     "src/latest/$(pwd)/src/"
50 WVPASS bup xstat dest/foo > foo-xstat
51 WVPASS grep -qE "^user: $other_user\$" foo-xstat
52 WVPASS grep -qE "^uid: $other_uid\$" foo-xstat
53 WVPASS grep -qE "^group: $other_group\$" foo-xstat
54 WVPASS grep -qE "^gid: $other_gid\$" foo-xstat
55
56 WVSTART "restore --map-user/group/uid/gid (user/group trumps uid/gid)"
57 WVPASS rm -rf dest
58 WVPASS bup restore -C dest \
59     --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
60     "src/latest/$(pwd)/src/"
61 # Should be no changes.
62 WVPASS bup xstat dest/foo > foo-xstat
63 WVPASS grep -qE "^user: $user\$" foo-xstat
64 WVPASS grep -qE "^uid: $uid\$" foo-xstat
65 WVPASS grep -qE "^group: $group\$" foo-xstat
66 WVPASS grep -qE "^gid: $gid\$" foo-xstat
67
68 WVSTART "restore --map-user/group/uid/gid (uid/gid)"
69 WVPASS rm -rf dest
70 WVPASS bup restore -C dest \
71     --map-user "$user=" --map-group "$group=" \
72     --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
73     "src/latest/$(pwd)/src/"
74 WVPASS bup xstat dest/foo > foo-xstat
75 WVPASS grep -qE "^user: $other_user\$" foo-xstat
76 WVPASS grep -qE "^uid: $other_uid\$" foo-xstat
77 WVPASS grep -qE "^group: $other_group\$" foo-xstat
78 WVPASS grep -qE "^gid: $other_gid\$" foo-xstat
79
80 WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
81 WVPASS rm -rf dest
82 WVPASS bup restore -C dest \
83     --map-user "$user=$other_user" --map-group "$group=$other_group" \
84     --map-uid "$uid=0" --map-gid "$gid=0" \
85     "src/latest/$(pwd)/src/"
86 WVPASS bup xstat dest/foo > foo-xstat
87 WVPASS grep -qE "^uid: 0\$" foo-xstat
88 WVPASS grep -qE "^gid: 0\$" foo-xstat
89
90 WVPASS rm -rf "$tmpdir"