2 . ./wvtest-bup.sh || exit $?
5 if [ $(t/root-status) != root ]; then
6 echo 'Not root: skipping restore --map-* tests.'
7 exit 0 # FIXME: add WVSKIP.
10 top="$(WVPASS pwd)" || exit $?
11 tmpdir="$(WVPASS wvmktempdir)" || exit $?
12 export BUP_DIR="$tmpdir/bup"
14 bup() { "$top/bup" "$@"; }
16 uid=$(WVPASS id -u) || exit $?
17 user=$(WVPASS id -un) || exit $?
18 gid=$(WVPASS id -g) || exit $?
19 group=$(WVPASS id -gn) || exit $?
21 other_uinfo=$(WVPASS t/id-other-than --user "$user") || exit $?
22 other_user="${other_uinfo%%:*}"
23 other_uid="${other_uinfo##*:}"
25 other_ginfo=$(WVPASS t/id-other-than --group "$group" 0) || exit $?
26 other_group="${other_ginfo%%:*}"
27 other_gid="${other_ginfo##*:}"
32 WVSTART "restore --map-user/group/uid/gid (control)"
35 # Some systems assign the parent dir group to new paths.
36 WVPASS chgrp -R "$group" src
38 WVPASS bup save -n src src
39 WVPASS bup restore -C dest "src/latest/$(pwd)/src/"
40 WVPASS bup xstat dest/foo > foo-xstat
41 WVPASS grep -qE "^user: $user\$" foo-xstat
42 WVPASS grep -qE "^uid: $uid\$" foo-xstat
43 WVPASS grep -qE "^group: $group\$" foo-xstat
44 WVPASS grep -qE "^gid: $gid\$" foo-xstat
46 WVSTART "restore --map-user/group/uid/gid (user/group)"
48 # Have to remap uid/gid too because we're root and 0 would win).
49 WVPASS bup restore -C dest \
50 --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
51 --map-user "$user=$other_user" --map-group "$group=$other_group" \
52 "src/latest/$(pwd)/src/"
53 WVPASS bup xstat dest/foo > foo-xstat
54 WVPASS grep -qE "^user: $other_user\$" foo-xstat
55 WVPASS grep -qE "^uid: $other_uid\$" foo-xstat
56 WVPASS grep -qE "^group: $other_group\$" foo-xstat
57 WVPASS grep -qE "^gid: $other_gid\$" foo-xstat
59 WVSTART "restore --map-user/group/uid/gid (user/group trumps uid/gid)"
61 WVPASS bup restore -C dest \
62 --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
63 "src/latest/$(pwd)/src/"
64 # Should be no changes.
65 WVPASS bup xstat dest/foo > foo-xstat
66 WVPASS grep -qE "^user: $user\$" foo-xstat
67 WVPASS grep -qE "^uid: $uid\$" foo-xstat
68 WVPASS grep -qE "^group: $group\$" foo-xstat
69 WVPASS grep -qE "^gid: $gid\$" foo-xstat
71 WVSTART "restore --map-user/group/uid/gid (uid/gid)"
73 WVPASS bup restore -C dest \
74 --map-user "$user=" --map-group "$group=" \
75 --map-uid "$uid=$other_uid" --map-gid "$gid=$other_gid" \
76 "src/latest/$(pwd)/src/"
77 WVPASS bup xstat dest/foo > foo-xstat
78 WVPASS grep -qE "^user: $other_user\$" foo-xstat
79 WVPASS grep -qE "^uid: $other_uid\$" foo-xstat
80 WVPASS grep -qE "^group: $other_group\$" foo-xstat
81 WVPASS grep -qE "^gid: $other_gid\$" foo-xstat
83 has_uid_gid_0=$(WVPASS bup-python -c "
91 " 2>/dev/null) || exit $?
92 if [ "$has_uid_gid_0" == yes ]
94 WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
96 WVPASS bup restore -C dest \
97 --map-user "$user=$other_user" --map-group "$group=$other_group" \
98 --map-uid "$uid=0" --map-gid "$gid=0" \
99 "src/latest/$(pwd)/src/"
100 WVPASS bup xstat dest/foo > foo-xstat
101 WVPASS grep -qE "^uid: 0\$" foo-xstat
102 WVPASS grep -qE "^gid: 0\$" foo-xstat
104 WVPASS rm -rf "$tmpdir"