New Script -- run-parts main
authorSteve Youngs <steve@steveyoungs.com>
Wed, 23 Jun 2021 02:09:54 +0000 (12:09 +1000)
committerSteve Youngs <steve@steveyoungs.com>
Wed, 23 Jun 2021 02:09:54 +0000 (12:09 +1000)
A script to use with cron / systemd-timers.  It runs all executables
in a directory.

* usr/bin/run-parts: New.

Signed-off-by: Steve Youngs <steve@steveyoungs.com>
usr/bin/run-parts [new file with mode: 0755]

diff --git a/usr/bin/run-parts b/usr/bin/run-parts
new file mode 100755 (executable)
index 0000000..53e6134
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright © 2021 Steve Youngs. All rights reserved.
+# SPDX-License-Identifier: BSD-3-Clause
+
+# Author:     Steve Youngs <steve@sxemacs.org>
+# Maintainer: Steve Youngs <steve@sxemacs.org>
+# Created:    <2021-06-23>
+# Time-stamp: <Wednesday 23 Jun 2021 12:01:33 (steve)>
+# Homepage:   https://git.sxemacs.org/pkgusr
+# Keywords:   pkgusr package-management tools
+
+## This file is part of pkgusr
+
+### Commentary:
+#
+# Runs all the executable scripts found in a directory, but not
+# "backup" files (*.bak, *.orig, *.new, *.rej, *~)
+#
+# This script is based on the one that Pat Volkerding ships with
+# Slackware.
+
+# keep going when something fails
+set +e
+
+if [ $# -lt 1 ]; then
+    echo "Usage: run-parts <directory>"
+    exit 1
+fi
+
+if [ ! -d $1 ]; then
+    echo "Not a directory: $1"
+    echo "Usage: run-parts <directory>"
+    exit 1
+fi
+
+# Main loop:
+for SCRIPT in $1/* ; do
+    # Skip backup, non-regular, non-executable files
+    if [[ "$SCRIPT" =~ ^.*(~|#|\.(bak|orig|new|rej))$ ||
+           ! -f $SCRIPT || ! -x $SCRIPT ]]; then
+       continue
+    fi
+    # Run what makes it this far.
+    $SCRIPT || echo "$SCRIPT failed."
+done
+
+exit 0
+
+### run-parts ends here
+# Local variables:
+# coding: utf-8
+# end: