1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
| cat /usr/bin/run-parts-debian
set +e
set -o pipefail
usage() { echo "run-parts [--test] [--verbose] [--report] [--umask=umask] [--lsbsysinit] [--regex=REGEX] [--arg=argument] [--exit-on-error] [--help] [--list] [--reverse] [--] DIRECTORY" }
help() { echo " NAME run-parts - run scripts or programs in a directory
SYNOPSIS run-parts [--test] [--verbose] [--report] [--umask=umask] [--lsbsysinit] [--regex=REGEX] [--arg=argument] [--exit-on-error] [--help] [--list] [--reverse] [--] DIRECTORY
DESCRIPTION run-parts runs all the executable files named within constraints described below, found in directory directory. Other files and directories are silently ignored.
If neither the --lsbsysinit option nor the --regex option is given then the names must consist entirely of ASCII upper- and lower-case letters, ASCII digits, ASCII underscores, and ASCII minus-hyphens.
If the --lsbsysinit option is given, then the names must not end in .dpkg-old or .dpkg-dist or .dpkg-new or .dpkg-tmp, and must belong to one or more of the following namespaces: the LANANA-assigned namespace (^[a-z0-9]+$); the LSB hierarchical and reserved namespaces (^_?([a-z0-9_.]+-)+[a-z0-9]+$); and the Debian cron script namespace (^[a-zA- Z0-9_-]+$).
If the --regex option is given, the names must match the custom extended regular expression specified as that option's argument.
Files are run in the lexical sort order of their names unless the --reverse option is given, in which case they are run in the opposite order.
OPTIONS --test print the names of the scripts which would be run, but don't actually run them.
--list print the names of the all matching files (not limited to executables), but don't actually run them. This option cannot be used with --test.
-v, --verbose print the name of each script to stderr before running.
--report similar to --verbose, but only prints the name of scripts which produce output. The script's name is printed to whichever of stdout or stderr the script produces output on. The script's name is not printed to stderr if --verbose also specified.
--reverse reverse the scripts' execution order.
--exit-on-error exit as soon as a script returns with a non-zero exit code.
--umask=umask sets the umask to umask before running the scripts. umask should be specified in octal. By default the umask is set to 022.
--lsbsysinit filename must be in one or more of either the LANANA-assigned namespace, the LSB namespaces - either hierarchical or reserved - or the Debian cron script namespace.
--regex=REGEX validate filenames against custom extended regular expression REGEX
-a, --arg=argument pass argument to the scripts. Use --arg once for each argument you want passed.
-- specifies that this is the end of the options. Any filename after -- will be not be interpreted as an option even if it starts with a hyphen.
-h, --help display usage information and exit. " }
report-and-pipe() { rline="$1" while IFS= read -r line; do echo -en "$rline" ; echo "$line"; unset rline; done; }
if [ $# -lt 1 ]; then usage exit 1 fi
args="" dir="" umask=""
for i in "$@"; do if [ ${append_arg:-0} = 1 ]; then args="$args $i" append_arg=0 continue fi case $i in --list) list=1 ;; --test) test=1 ;; --verbose|-v) verbose=1 ;; --report) report=1 ;; --reverse) reverse=1 ;; --lsbsysinit) lsbsysinit=1 ;; --regex) regex="${i#*=}" ;; --arg=*) args="$args ${i#*=}" ;; -a) append_arg=1 ;; --umask=*) umask="${i#*=}" ;; --help|-h) help exit 0 ;; --exit-on-error) exit_on_error=1 ;; --) ;; -*) echo Unknown argument: $i > /dev/stderr echo Rest of arguments: $* > /dev/stderr usage exit 1 ;; *) dir=$i break ;; esac done
if [[ "x$dir" = "x" && ! -d "$dir" ]]; then echo "Not a directory: '$dir'" usage exit 1 fi
filelist=$(LC_ALL=C; ls -1 "${dir}" | grep -vEe '[~,]$')
if [ ${reverse:-0} = 1 ]; then filelist=$(echo "$filelist" | sort -r) fi
echo "$filelist" | while read bname ; do fpath="${dir%/}/${bname}" [ -d "${fpath}" ] && continue [ "${bname%.disabled}" != "${bname}" ] && continue [ "${bname%.cfsaved}" != "${bname}" ] && continue [ "${bname%.rpmsave}" != "${bname}" ] && continue [ "${bname%.rpmorig}" != "${bname}" ] && continue [ "${bname%.rpmnew}" != "${bname}" ] && continue [ "${bname%.swp}" != "${bname}" ] && continue [ "${bname%,v}" != "${bname}" ] && continue
if [ ${lsbsysinit:-0} = 1 ]; then [ "${bname%.dpkg-old}" != "${bname}" ] && continue [ "${bname%.dpkg-dist}" != "${bname}" ] && continue [ "${bname%.dpkg-new}" != "${bname}" ] && continue [ "${bname%.dpkg-tmp}" != "${bname}" ] && continue [[ ! "${bname}" =~ ^[a-z0-9]+$ ]] && \ [[ ! "${bname}" =~ ^_?([a-z0-9_.]+-)+[a-z0-9]+$ ]] && \ [[ ! "${bname}" =~ ^[a-zA-Z0-9_-]+$ ]] && continue fi
if [ "x$regex" != "x" ]; then [[ ! "${bname}" =~ $regex ]] && continue fi
if [ -e "${fpath}" ]; then if [ -r $dir/whitelist ]; then grep -q "^${bname}$" $dir/whitelist && continue fi
if [ ${list:-0} = 1 ]; then echo "${fpath}" $args; continue fi
if [ -x "${fpath}" ]; then if [ ${test:-0} = 1 ]; then echo "${fpath}" $args; continue fi if [ "$RANDOMIZE" != "" ]; then let "rtime = $RANDOM" if [ "$RANDOMTIME" != "" ]; then let "rtime %= $RANDOMTIME" else let "rtime %= 300" fi sleep $rtime fi
if [ ${verbose:-0} = 1 ]; then echo "${fpath}" $args > /dev/stderr fi
if [ "x$umask" != "x" ]; then umask $umask fi
if [ ${report:-0} = 1 ]; then oline="${fpath}\n" if [ ${verbose:-0} = 1 ]; then eline="" else eline="${fpath}\n" fi { "${fpath}" $args 2>&1 1>&3 3>&- | report-and-pipe "$eline" } 3>&1 1>&2 | report-and-pipe "$oline" else "${fpath}" $args fi
rc=${PIPESTATUS[0]}
if [ ${verbose:-0} = 1 ]; then echo "${fpath}" $args exit status $rc > /dev/stderr fi
if [ ${rc:-0} != 0 ]; then if [ ${exit_on_error:-0} = 1 ]; then exit $rc fi fi fi fi done
exit 0
|