4 if [ $(t/root-status) != root ]; then
5 echo 'Not root: skipping restore --map-* tests.'
6 exit 0 # FIXME: add WVSKIP.
9 top="$(WVPASS pwd)" || exit $?
10 tmpdir="$(WVPASS wvmktempdir)" || exit $?
11 export BUP_DIR="$tmpdir/bup"
13 bup() { "$top/bup" "$@"; }
15 uid=$(WVPASS id -u) || exit $?
16 user=$(WVPASS id -un) || exit $?
17 gid=$(WVPASS id -g) || exit $?
18 group=$(WVPASS id -gn) || exit $?
20 other_uinfo=$(WVPASS t/id-other-than --user "$user") || exit $?
21 other_user="${other_uinfo%%:*}"
22 other_uid="${other_uinfo##*:}"
24 other_ginfo=$(WVPASS t/id-other-than --group "$group") || exit $?
25 other_group="${other_ginfo%%:*}"
26 other_gid="${other_ginfo##*:}"
31 WVSTART "restore --map-user/group/uid/gid (control)"
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
43 WVSTART "restore --map-user/group/uid/gid (user/group)"
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
56 WVSTART "restore --map-user/group/uid/gid (user/group trumps uid/gid)"
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
68 WVSTART "restore --map-user/group/uid/gid (uid/gid)"
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
80 WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
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
90 WVPASS rm -rf "$tmpdir"