dev-env/script/foreachSystem
2024-12-21 02:10:36 +01:00

39 lines
1012 B
Bash
Executable File

#!/bin/bash
COMMAND="$@"
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
CONFIG_FILE="$ENV_DIR/.systems"
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 foreach System"
# 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
denv_info_msg "System $IDENTIFIER"
SYSTEM_SCRIPT_DIRECTORY=$(realpath "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."
exit 1
else
denv_echo_msg "Executing $COMMAND..."
$COMMAND_PATH
fi
denv_info_msg "System $IDENTIFIER done"
echo ""
done < "$CONFIG_FILE"