New Script -- run-parts
[pkgusr] / usr / bin / run-parts
1 #!/bin/bash
2 # Copyright © 2021 Steve Youngs. All rights reserved.
3 # SPDX-License-Identifier: BSD-3-Clause
4
5 # Author:     Steve Youngs <steve@sxemacs.org>
6 # Maintainer: Steve Youngs <steve@sxemacs.org>
7 # Created:    <2021-06-23>
8 # Time-stamp: <Wednesday 23 Jun 2021 12:01:33 (steve)>
9 # Homepage:   https://git.sxemacs.org/pkgusr
10 # Keywords:   pkgusr package-management tools
11
12 ## This file is part of pkgusr
13
14 ### Commentary:
15 #
16 # Runs all the executable scripts found in a directory, but not
17 # "backup" files (*.bak, *.orig, *.new, *.rej, *~)
18 #
19 # This script is based on the one that Pat Volkerding ships with
20 # Slackware.
21
22 # keep going when something fails
23 set +e
24
25 if [ $# -lt 1 ]; then
26     echo "Usage: run-parts <directory>"
27     exit 1
28 fi
29
30 if [ ! -d $1 ]; then
31     echo "Not a directory: $1"
32     echo "Usage: run-parts <directory>"
33     exit 1
34 fi
35
36 # Main loop:
37 for SCRIPT in $1/* ; do
38     # Skip backup, non-regular, non-executable files
39     if [[ "$SCRIPT" =~ ^.*(~|#|\.(bak|orig|new|rej))$ ||
40             ! -f $SCRIPT || ! -x $SCRIPT ]]; then
41         continue
42     fi
43     # Run what makes it this far.
44     $SCRIPT || echo "$SCRIPT failed."
45 done
46
47 exit 0
48
49 ### run-parts ends here
50 # Local variables:
51 # coding: utf-8
52 # end: