dev-env/script/foreachSystem/runScript
2024-12-21 15:43:08 +01:00

38 lines
1021 B
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/denv_msg
# Check if .systems configuration exists
if [ ! -f "$CONFIG_FILE" ]; then
denv_error_msg "$CONFIG_FILE not found."
exit 1
fi
denv_info_msg "[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
denv_error_msg "$COMMAND_PATH not found."
continue
fi
denv_info_msg "[$IDENTIFIER]: $COMMAND"
$COMMAND_PATH
denv_success_msg "[$IDENTIFIER]: $COMMAND completed successfully"
echo ""
done < "$CONFIG_FILE"