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