Enhance entrypoint script to support legacy COMMAND_INIT and COMMAND_EXIT variables, allowing for backward compatibility and execution of multiple user-defined exit and initialization commands in order.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ameer Hamza Khan
2025-08-07 09:04:50 +00:00
parent 828a0d72c4
commit a299d285e6

View File

@@ -28,7 +28,20 @@ term_handler() {
fi
# Run user-defined exit commands
eval "$COMMAND_EXIT"
# First run the legacy COMMAND_EXIT for backward compatibility
if [[ -n "$COMMAND_EXIT" ]]; then
eval "$COMMAND_EXIT"
fi
# Then run numbered COMMAND_EXIT variables in order
for i in {01..99}; do
var_name="COMMAND_EXIT$i"
var_value="${!var_name}"
if [[ -n "$var_value" ]]; then
echo "Running $var_name..."
eval "$var_value"
fi
done
echo "Cleanup completed, exiting..."
exit 0
@@ -53,7 +66,20 @@ echo "Starting SSH service..."
sudo service ssh start
# Run initialization commands
eval "$COMMAND_INIT"
# First run the legacy COMMAND_INIT for backward compatibility
if [[ -n "$COMMAND_INIT" ]]; then
eval "$COMMAND_INIT"
fi
# Then run numbered COMMAND_INIT variables in order
for i in {01..99}; do
var_name="COMMAND_INIT$i"
var_value="${!var_name}"
if [[ -n "$var_value" ]]; then
echo "Running $var_name..."
eval "$var_value"
fi
done
# Start the main process loop
if [[ $LOG_FILE == "/dev/null" ]]; then