#!/usr/bin/env bash
-. ./wvtest-bup.sh
+. ./wvtest-bup.sh || exit $?
+. t/lib.sh || exit $?
-if [ $(t/root-status) != root ]; then
+root_status="$(t/root-status)" || exit $?
+
+if [ "$root_status" != root ]; then
echo 'Not root: skipping restore --map-* tests.'
exit 0 # FIXME: add WVSKIP.
fi
other_user="${other_uinfo%%:*}"
other_uid="${other_uinfo##*:}"
-other_ginfo=$(WVPASS t/id-other-than --group "$group") || exit $?
+other_ginfo=$(WVPASS t/id-other-than --group "$group" 0) || exit $?
other_group="${other_ginfo%%:*}"
other_gid="${other_ginfo##*:}"
WVPASS grep -qE "^group: $other_group\$" foo-xstat
WVPASS grep -qE "^gid: $other_gid\$" foo-xstat
-WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
-WVPASS rm -rf dest
-WVPASS bup restore -C dest \
- --map-user "$user=$other_user" --map-group "$group=$other_group" \
- --map-uid "$uid=0" --map-gid "$gid=0" \
- "src/latest/$(pwd)/src/"
-WVPASS bup xstat dest/foo > foo-xstat
-WVPASS grep -qE "^uid: 0\$" foo-xstat
-WVPASS grep -qE "^gid: 0\$" foo-xstat
+has_uid_gid_0=$(WVPASS bup-python -c "
+import grp, pwd
+try:
+ pwd.getpwuid(0)
+ grp.getgrgid(0)
+ print('yes')
+except KeyError as ex:
+ pass
+") || exit $?
+if [ "$has_uid_gid_0" == yes ]
+then
+ WVSTART "restore --map-user/group/uid/gid (zero uid/gid trumps all)"
+ WVPASS rm -rf dest
+ WVPASS bup restore -C dest \
+ --map-user "$user=$other_user" --map-group "$group=$other_group" \
+ --map-uid "$uid=0" --map-gid "$gid=0" \
+ "src/latest/$(pwd)/src/"
+ WVPASS bup xstat dest/foo > foo-xstat
+ WVPASS grep -qE "^uid: 0\$" foo-xstat
+ WVPASS grep -qE "^gid: 0\$" foo-xstat
-WVPASS rm -rf "$tmpdir"
+ WVPASS rm -rf "$tmpdir"
+fi