1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash 2*cf5a6c84SAndroid Build Coastguard Worker 3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh 4*cf5a6c84SAndroid Build Coastguard Worker 5*cf5a6c84SAndroid Build Coastguard Workerif [ "$(id -u)" -ne 0 ] 6*cf5a6c84SAndroid Build Coastguard Workerthen 7*cf5a6c84SAndroid Build Coastguard Worker echo "$SHOWSKIP: chgrp (not root)" 8*cf5a6c84SAndroid Build Coastguard Worker return 2>/dev/null 9*cf5a6c84SAndroid Build Coastguard Worker exit 10*cf5a6c84SAndroid Build Coastguard Workerfi 11*cf5a6c84SAndroid Build Coastguard Worker 12*cf5a6c84SAndroid Build Coastguard Worker# We chgrp between "root" and the last group in /etc/group. 13*cf5a6c84SAndroid Build Coastguard WorkerGRP="$(sed -n '$s/:.*//p' /etc/group)" 14*cf5a6c84SAndroid Build Coastguard Worker# Or if that fails, assume we're on Android and pick a well-known group. 15*cf5a6c84SAndroid Build Coastguard Worker: "${GRP:=shell}" 16*cf5a6c84SAndroid Build Coastguard Worker 17*cf5a6c84SAndroid Build Coastguard Worker# Set up a little testing hierarchy 18*cf5a6c84SAndroid Build Coastguard Worker 19*cf5a6c84SAndroid Build Coastguard Workerrm -rf testdir && 20*cf5a6c84SAndroid Build Coastguard Workermkdir -p testdir/dir/dir/dir testdir/dir2 && 21*cf5a6c84SAndroid Build Coastguard Workertouch testdir/dir/file && 22*cf5a6c84SAndroid Build Coastguard Workerln -s ../dir/dir testdir/dir2/dir && 23*cf5a6c84SAndroid Build Coastguard Workerln -s ../dir/file testdir/dir2/file || exit 1 24*cf5a6c84SAndroid Build Coastguard Worker 25*cf5a6c84SAndroid Build Coastguard Worker# Wrapper to reset groups and return results 26*cf5a6c84SAndroid Build Coastguard Worker 27*cf5a6c84SAndroid Build Coastguard WorkerIN="cd testdir && chgrp -R $GRP dir dir2 &&" 28*cf5a6c84SAndroid Build Coastguard WorkerOUT="&& cd .. && echo \$(ls -lR testdir | awk '{print \$4}')" 29*cf5a6c84SAndroid Build Coastguard Worker 30*cf5a6c84SAndroid Build Coastguard Worker# The groups returned by $OUT are, in order: 31*cf5a6c84SAndroid Build Coastguard Worker# dir dir2 dir/dir dir/file dir/dir/dir dir2/dir dir2/file 32*cf5a6c84SAndroid Build Coastguard Worker 33*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin" 34*cf5a6c84SAndroid Build Coastguard Worker 35*cf5a6c84SAndroid Build Coastguard Worker# Basic smoketest 36*cf5a6c84SAndroid Build Coastguard Workertesting "dir" "$IN chgrp root dir $OUT" \ 37*cf5a6c84SAndroid Build Coastguard Worker "root $GRP $GRP $GRP $GRP $GRP $GRP\n" "" "" 38*cf5a6c84SAndroid Build Coastguard Workertesting "file" "$IN chgrp root dir/file $OUT" \ 39*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" 40*cf5a6c84SAndroid Build Coastguard Workertesting "dir and file" "$IN chgrp root dir dir/file $OUT" \ 41*cf5a6c84SAndroid Build Coastguard Worker "root $GRP $GRP root $GRP $GRP $GRP\n" "" "" 42*cf5a6c84SAndroid Build Coastguard Worker 43*cf5a6c84SAndroid Build Coastguard Worker# symlinks (affect target, not symlink) 44*cf5a6c84SAndroid Build Coastguard Workertesting "symlink->file" "$IN chgrp root dir2/file $OUT" \ 45*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" 46*cf5a6c84SAndroid Build Coastguard Workertesting "symlink->dir" "$IN chgrp root dir2/dir $OUT" \ 47*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" 48*cf5a6c84SAndroid Build Coastguard Workertesting "-h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ 49*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" 50*cf5a6c84SAndroid Build Coastguard Worker 51*cf5a6c84SAndroid Build Coastguard Worker# What does -h do (affect symlink, not target) 52*cf5a6c84SAndroid Build Coastguard Workertesting "-h symlink->file" "$IN chgrp -h root dir2/file $OUT" \ 53*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" 54*cf5a6c84SAndroid Build Coastguard Workertesting "-h symlink->dir" "$IN chgrp -h root dir2/dir $OUT" \ 55*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" 56*cf5a6c84SAndroid Build Coastguard Worker 57*cf5a6c84SAndroid Build Coastguard Worker# chgrp -R (note, -h is implied by -R) 58*cf5a6c84SAndroid Build Coastguard Worker 59*cf5a6c84SAndroid Build Coastguard Workertesting "-R dir" "$IN chgrp -R root dir $OUT" \ 60*cf5a6c84SAndroid Build Coastguard Worker "root $GRP root root root $GRP $GRP\n" "" "" 61*cf5a6c84SAndroid Build Coastguard Workertesting "-R dir2" "$IN chgrp -R root dir2 $OUT" \ 62*cf5a6c84SAndroid Build Coastguard Worker "$GRP root $GRP $GRP $GRP root root\n" "" "" 63*cf5a6c84SAndroid Build Coastguard Workertesting "-R symlink->dir" "$IN chgrp -R root dir2/dir $OUT" \ 64*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" 65*cf5a6c84SAndroid Build Coastguard Workertesting "-R symlink->file" "$IN chgrp -R root dir2/file $OUT" \ 66*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" 67*cf5a6c84SAndroid Build Coastguard Worker 68*cf5a6c84SAndroid Build Coastguard Worker# chgrp -RP (same as -R by itself) 69*cf5a6c84SAndroid Build Coastguard Worker 70*cf5a6c84SAndroid Build Coastguard Workertesting "-RP dir2" "$IN chgrp -RP root dir2 $OUT" \ 71*cf5a6c84SAndroid Build Coastguard Worker "$GRP root $GRP $GRP $GRP root root\n" "" "" 72*cf5a6c84SAndroid Build Coastguard Workertesting "-RP symlink->dir" "$IN chgrp -RP root dir2/dir $OUT" \ 73*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP root $GRP\n" "" "" 74*cf5a6c84SAndroid Build Coastguard Workertesting "-RP symlink->file" "$IN chgrp -RP root dir2/file $OUT" \ 75*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP $GRP $GRP $GRP root\n" "" "" 76*cf5a6c84SAndroid Build Coastguard Worker 77*cf5a6c84SAndroid Build Coastguard Worker# chgrp -RH (change target but only recurse through symlink->dir on cmdline) 78*cf5a6c84SAndroid Build Coastguard Worker 79*cf5a6c84SAndroid Build Coastguard Workertesting "-RH dir2" "$IN chgrp -RH root dir2 $OUT" \ 80*cf5a6c84SAndroid Build Coastguard Worker "$GRP root root root $GRP $GRP $GRP\n" "" "" 81*cf5a6c84SAndroid Build Coastguard Workertesting "-RH symlink->dir" "$IN chgrp -RH root dir2/dir $OUT" \ 82*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" 83*cf5a6c84SAndroid Build Coastguard Workertesting "-RH symlink->file" "$IN chgrp -RH root dir2/file $OUT" \ 84*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" 85*cf5a6c84SAndroid Build Coastguard Worker 86*cf5a6c84SAndroid Build Coastguard Worker# chgrp -RL (change target and always recurse through symlink->dir) 87*cf5a6c84SAndroid Build Coastguard Worker 88*cf5a6c84SAndroid Build Coastguard Workertesting "-RL dir2" "$IN chgrp -RL root dir2 $OUT" \ 89*cf5a6c84SAndroid Build Coastguard Worker "$GRP root root root root $GRP $GRP\n" "" "" 90*cf5a6c84SAndroid Build Coastguard Workertesting "-RL symlink->dir" "$IN chgrp -RL root dir2/dir $OUT" \ 91*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP root $GRP $GRP\n" "" "" 92*cf5a6c84SAndroid Build Coastguard Workertesting "-RL symlink->file" "$IN chgrp -RL root dir2/file $OUT" \ 93*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP $GRP root $GRP $GRP $GRP\n" "" "" 94*cf5a6c84SAndroid Build Coastguard Worker 95*cf5a6c84SAndroid Build Coastguard Worker# -HLP are NOPs without -R 96*cf5a6c84SAndroid Build Coastguard Workertesting "-H without -R" "$IN chgrp -H root dir2/dir $OUT" \ 97*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" 98*cf5a6c84SAndroid Build Coastguard Workertesting "-L without -R" "$IN chgrp -L root dir2/dir $OUT" \ 99*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" 100*cf5a6c84SAndroid Build Coastguard Workertesting "-P without -R" "$IN chgrp -P root dir2/dir $OUT" \ 101*cf5a6c84SAndroid Build Coastguard Worker "$GRP $GRP root $GRP $GRP $GRP $GRP\n" "" "" 102*cf5a6c84SAndroid Build Coastguard Worker 103*cf5a6c84SAndroid Build Coastguard Workerrm -rf testdir 104