]> arthur.barton.de Git - bup.git/blob - t/test-restore-map-owner.sh
Change remaining uses of python to bup-python
[bup.git] / t / test-restore-map-owner.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3 . t/lib.sh || exit $?
4
5 if [ $(t/root-status) != root ]; then
6     echo 'Not root: skipping restore --map-* tests.'
7     exit 0 # FIXME: add WVSKIP.
8 fi
9
10 top="$(WVPASS pwd)" || exit $?
11 tmpdir="$(WVPASS wvmktempdir)" || exit $?
12 export BUP_DIR="$tmpdir/bup"
13
14 bup() { "$top/bup" "$@"; }
15
16 uid=$(WVPASS id -u) || exit $?
17 user=$(WVPASS id -un) || exit $?
18 gid=$(WVPASS id -g) || exit $?
19 group=$(WVPASS id -gn) || exit $?
20
21 other_uinfo=$(WVPASS t/id-other-than --user "$user") || exit $?
22 other_user="${other_uinfo%%:*}"
23 other_uid="${other_uinfo##*:}"
24
25 other_ginfo=$(WVPASS t/id-other-than --group "$group" 0) || exit $?
26 other_group="${other_ginfo%%:*}"
27 other_gid="${other_ginfo##*:}"
28
29 WVPASS bup init
30 WVPASS cd "$tmpdir"
31
32 WVSTART "restore --map-user/group/uid/gid (control)"
33 WVPASS mkdir src
34 WVPASS touch src/foo
35 # Some systems assign the parent dir group to new paths.
36 WVPASS chgrp -R "$group" src
37 WVPASS bup index 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
45
46 WVSTART "restore --map-user/group/uid/gid (user/group)"
47 WVPASS rm -rf dest
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
58
59 WVSTART "restore --map-user/group/uid/gid (user/group trumps uid/gid)"
60 WVPASS rm -rf dest
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
70
71 WVSTART "restore --map-user/group/uid/gid (uid/gid)"
72 WVPASS rm -rf dest
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
82
83 has_uid_gid_0=$(WVPASS bup-python -c "
84 import grp, pwd
85 try:
86   pwd.getpwuid(0)
87   grp.getgrgid(0)
88   print 'yes'
89 except KeyError, ex:
90   pass
91 " 2>/dev/null) || exit $?
92 if [ "$has_uid_gid_0" == yes ]
93 then
94     WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
95     WVPASS rm -rf dest
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
103
104     WVPASS rm -rf "$tmpdir"
105 fi