dev-env/script/foreachSystem/runScript
2025-05-25 22:21:05 +02:00

39 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd )
CONFIG_FILE="$ENV_DIR/.systems"
COMMAND="$@"
source $ENV_DIR/bin/messages
# Check if .systems configuration exists
if [ ! -f "$CONFIG_FILE" ]; then
errormsg "$CONFIG_FILE not found."
exit 1
fi
importantmsg "[dev-env]: Execute $COMMAND for all systems"
# Iterate through all lines in .systems configuration
while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do
# Skip comments and emtpy lines
if [[ "$IDENTIFIER" =~ ^#.* ]] || [ -z "$IDENTIFIER" ]; then
continue
fi
SYSTEM_SCRIPT_DIRECTORY=$(realpath "$ENV_DIR/systems/$DIRECTORY/bin/script")
COMMAND_PATH="$SYSTEM_SCRIPT_DIRECTORY/$COMMAND"
# Check if system directory already exists
if [ ! -f "$COMMAND_PATH" ]; then
errormsg "$COMMAND_PATH not found."
continue
fi
importantmsg "[$IDENTIFIER]: $COMMAND"
$COMMAND_PATH
successmsg "[$IDENTIFIER]: $COMMAND completed successfully"
echo ""
done < "$CONFIG_FILE"
successmsg "[dev-env]: Executed $COMMAND for all systems"