84 lines
2.1 KiB
Bash
Executable File
84 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
check_file() {
|
|
local file=""
|
|
local engine=""
|
|
local opt
|
|
local OPTARG
|
|
local OPTIND=1
|
|
|
|
# Manually parse --engine= argument
|
|
for arg in "$@"; do
|
|
case $arg in
|
|
--engine=*)
|
|
engine="${arg#*=}"
|
|
shift # Remove --engine= from positional parameters
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Check if -f flag is provided
|
|
while getopts ":f:" opt; do
|
|
case $opt in
|
|
f)
|
|
file="$OPTARG"
|
|
;;
|
|
\?)
|
|
echo "Usage: $0 [-f file] [--engine=engine_name]"
|
|
return 1
|
|
;;
|
|
:)
|
|
echo "Option -$OPTARG requires an argument."
|
|
return 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Check if file is provided, if not look for default files
|
|
if [ -z "$file" ]; then
|
|
if [ -f "compose.yaml" ]; then
|
|
file="compose.yaml"
|
|
elif [ -f "compose.yml" ]; then
|
|
file="compose.yml"
|
|
elif [ -f "docker-compose.yaml" ]; then
|
|
file="docker-compose.yaml"
|
|
elif [ -f "docker-compose.yml" ]; then
|
|
file="docker-compose.yml"
|
|
elif [ -f "podman-compose.yaml" ]; then
|
|
file="podman-compose.yaml"
|
|
elif [ -f "podman-compose.yml" ]; then
|
|
file="podman-compose.yml"
|
|
elif [ -f "container-compose.yaml" ]; then
|
|
file="container-compose.yaml"
|
|
elif [ -f "container-compose.yml" ]; then
|
|
file="container-compose.yml"
|
|
else
|
|
echo "no compose.yaml, compose.yml, docker-compose.yaml, docker-compose.yml, podman-compose.yml, podman-compose.yaml, container-compose.yaml or container-compose.yml file found, pass files with -f"
|
|
return 1
|
|
fi
|
|
elif [ ! -f "$file" ]; then
|
|
echo "File $file not found."
|
|
return 1
|
|
fi
|
|
|
|
# Set engine based on file if engine is not set
|
|
if [ -z "$engine" ]; then
|
|
case $file in
|
|
docker-compose.yaml|docker-compose.yml)
|
|
engine="docker"
|
|
;;
|
|
podman-compose.yaml|podman-compose.yml)
|
|
engine="podman"
|
|
;;
|
|
*)
|
|
echo "Engine not set and cannot be determined from file name. Specify with --engine=engine_name"
|
|
return 1
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Output the file and engine being used
|
|
echo "Using $file with engine $engine"
|
|
}
|
|
check_file "$@"
|