Elliott Hughes | 50d3207 | 2015-01-14 03:43:49 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | [ -f testing.sh ] && . testing.sh |
| 4 | |
| 5 | if [ "$(id -u)" -ne 0 ] |
| 6 | then |
Rob Landley | 3f3049c | 2016-01-31 16:28:43 -0600 | [diff] [blame] | 7 | echo "$SHOWSKIP: chown (not root)" |
Elliott Hughes | 50d3207 | 2015-01-14 03:43:49 -0600 | [diff] [blame] | 8 | continue 2>/dev/null |
| 9 | exit |
| 10 | fi |
| 11 | |
| 12 | # We chown between user "root" and the last user in /etc/passwd, |
| 13 | # and group "root" and the last group in /etc/group. |
| 14 | |
| 15 | USR="$(sed -n '$s/:.*//p' /etc/passwd)" |
| 16 | GRP="$(sed -n '$s/:.*//p' /etc/group)" |
| 17 | |
| 18 | # Set up a little testing hierarchy |
| 19 | |
| 20 | rm -rf testdir && |
| 21 | mkdir testdir && |
| 22 | touch testdir/file |
| 23 | F=testdir/file |
| 24 | |
| 25 | # Wrapper to reset groups and return results |
| 26 | |
| 27 | OUT="&& echo \$(ls -l testdir/file | awk '{print \$3,\$4}')" |
| 28 | |
| 29 | #testing "name" "command" "result" "infile" "stdin" |
| 30 | |
| 31 | # Basic smoketest |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 32 | testing "initial" "chown root:root $F $OUT" "root root\n" "" "" |
| 33 | testing "usr:grp" "chown $USR:$GRP $F $OUT" "$USR $GRP\n" "" "" |
| 34 | testing "root" "chown root $F $OUT" "root $GRP\n" "" "" |
Elliott Hughes | 50d3207 | 2015-01-14 03:43:49 -0600 | [diff] [blame] | 35 | # TODO: can we test "owner:"? |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 36 | testing ":grp" "chown root:root $F && chown :$GRP $F $OUT" \ |
Elliott Hughes | 50d3207 | 2015-01-14 03:43:49 -0600 | [diff] [blame] | 37 | "root $GRP\n" "" "" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 38 | testing ":" "chown $USR:$GRP $F && chown : $F $OUT" \ |
Elliott Hughes | 50d3207 | 2015-01-14 03:43:49 -0600 | [diff] [blame] | 39 | "$USR $GRP\n" "" "" |
| 40 | |
| 41 | rm -rf testdir |