#!/bin/sh # Copyright (C) 2021 by Achim Leitner # This program is distributable under the terms of the GNU GPL (see COPYING) # # Modern linux systems have the protected_regular feature set to 1 or 2 # See https://www.kernel.org/doc/Documentation/sysctl/fs.txt # Make sure we can still write these files in --inplace mode . "$suitedir/rsync.fns" test -f /proc/sys/fs/protected_regular || test_skipped "Can't find protected_regular setting (only available on Linux)" pr_lvl=`cat /proc/sys/fs/protected_regular 2>/dev/null` || test_skipped "Can't check if fs.protected_regular is enabled" test "$pr_lvl" != 0 || test_skipped "fs.protected_regular is not enabled" workdir="$tmpdir/files" mkdir -p "$workdir" chmod 1777 "$workdir" echo "Source" > "$workdir/src" echo "" > "$workdir/dst" if ! chown 5001 "$workdir/dst" 2>/dev/null; then # Not root - try re-running under unshare with UID mapping if [ -z "$RSYNC_UNSHARED" ] && unshare --user --map-root-user --map-users 5001:100000:1 true 2>/dev/null; then echo "Re-running under unshare with UID mapping..." RSYNC_UNSHARED=1 exec unshare --user --map-root-user --map-users 5001:100000:1 "$SHELL_PATH" $RUNSHFLAGS "$0" fi test_skipped "Can't chown (need root or unshare with uidmap)" fi echo "Contents of $workdir:" ls -al "$workdir" $RSYNC --inplace "$workdir/src" "$workdir/dst" || test_fail exit 0