3 # Copyright (c) 2004 Matthias S. Benkmann <article AT winterdrache DOT de>
4 # You may do everything with this code except misrepresent its origin.
5 # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND!
7 # Copyright (C) 2014 Steve Youngs <steve@steveyoungs.com>
8 ## Loads of minor tweaks --SY.
10 # The following list should contain the mount points of all
11 # filesystems that are to be scanned as a space-separated list within
12 # parentheses. / will usually be in this list and if you have /usr on
13 # a separate partition, it will also be in this list. Other
14 # non-special filesystems where package users could own files should
15 # also be put in this list. Mount points whose filesystems are
16 # special, such as procfs or sysfs must not be in this list. While a
17 # simple find on those special filesystems should be harmless,
18 # operations such as "-exec grep something" are NOT SAFE and may have
19 # HARMFUL SIDE-EFFECTS, especially when performed as root.
22 # fs_to_scan=(/ /opt /usr /var)
26 # Files with a path prefix found in the following list are ignored. This
27 # list will usually contain the parent directory of your package users'
28 # home directories, because normally you don't want to scan those. You
29 # can also add other directories that will never contain package user
30 # files, such as /home. This reduces scan time.
32 # Directories that are on separate filesystems (separate from the ones
33 # listed in fs_to_scan above) don't need to be listed here because of
34 # the -xdev option used in the find command.
37 ## My /usr/src is NOT included here because it is on a separate
40 # /{,*/{,*/}}lost+found \
41 # /etc/apache/ssl.key \
42 # /etc/audisp/plugins.d \
45 # /etc/mail/{auth,spamassassin} \
47 # /etc/polkit-1/rules.d \
52 # /opt/sql-ledger/{spool,templates,users,css} \
54 # /usr/lib/deprecated \
56 # /usr/share/polkit-1/rules.d \
57 # /var/{cache,chroot,db,run,snmp,spool} \
58 # /var/lib/{bluetooth,xdm} \
59 # /var/lib/{sasl,sudo,net-snmp,udisks{,2},NetworkManager} \
60 # /var/lib/{sshd,nfs,spamassassin,portables,private,pulse,machines} \
61 # /var/lib/colord/.cache \
63 # /var/tmp) #NO TRAILING SLASHES!!!!
69 /usr/src) #NO TRAILING SLASHES!!!!
72 # If you are scanning MS-DOS, CD-ROM, or AFS volumes you need
73 # to set $NOLEAF here to '-noleaf'. Setting this does significantly
74 # slow down the search so only do so if you really need to.
79 if [ $# -lt 1 -o "$1" = "--help" ]; then
81 echo 1>&2 'USAGE: '"${0##*/}"' <user_or_group_name> [<find-commands>]'
83 echo 1>&2 ' If <find-commands> contains no action other than -prune, -print will be'
84 echo 1>&2 ' executed for all matching files.'
85 echo 1>&2 ' Entries will be matched if group and/or user equals <user_or_group_name>'
86 echo 1>&2 ' (numeric UID/GID allowed).'
87 echo 1>&2 ' All matching entries will be acted on, including device special files, so'
88 echo 1>&2 ' you should be extra careful with the <find-commands> you provide!'
93 # suppress ugly debug output from shell
97 shift 1 # remove user_or_group_name from argument list
100 # test if find accepts ugname as a user, and append to ugmatcher if it does
101 if find / -maxdepth 0 -user "$ugname" >/dev/null 2>&1 ; then
102 ugmatcher[${#ugmatcher[@]}]="-or"
103 ugmatcher[${#ugmatcher[@]}]="-user"
104 ugmatcher[${#ugmatcher[@]}]="$ugname"
106 # test if find accepts ugname as a group, and append to ugmatcher if it does
107 if find / -maxdepth 0 -group "$ugname" >/dev/null 2>&1 ; then
108 ugmatcher[${#ugmatcher[@]}]="-or"
109 ugmatcher[${#ugmatcher[@]}]="-group"
110 ugmatcher[${#ugmatcher[@]}]="$ugname"
113 # if find accepted ugname as neither user nor group, then exit
114 if [ "${#ugmatcher[@]}" = 1 ]; then
115 echo 1>&2 'find does not accept `'"$ugname'"' as group or user name'
119 # construct find commands that match the prune_prefixes. Each prefix will be
120 # matched as -path <prefix> -or -path <prefix>/*
121 # so that the directory itself and all subdirectories are matched.
123 for ((i=0; $i<${#prune_prefixes[@]}; i=$i+1))
127 y[${#y[@]}]="${prune_prefixes[$i]}"
130 y[${#y[@]}]="${prune_prefixes[$i]}/*"
134 # The uninstall_package script sets this to `-ignore_readdir_race' so
135 # that find doesn't print errors when things it is searching for
137 # IGNORE_READDIR_RACE='-ignore_readdir_race'
140 # In the following find command, the part
141 # -not ( ( "${y[@]}" -prune ) -or "${y[@]}" )
142 # is responsible for preventing the files that match prune_prefixes from
143 # being processed. The 2nd "${y[@]}" may seem redundant, but it isn't, because
144 # -prune has no effect and is always false when -depth is used.
145 # The -true before "$@" ensures that -depth can be passed as only parameter.
147 find "${fs_to_scan[@]}" -xdev $NOLEAF $IGNORE_READDIR_RACE \
148 -not \( \( "${y[@]}" -prune \) -or "${y[@]}" \) \
149 -and \( "${ugmatcher[@]}" \) -and \( -true "$@" \)