added support for podman and docker engines

This commit is contained in:
Shihaam Abdul Rahman 2023-10-06 00:17:42 +05:00
parent 251003985b
commit 20d4685a13
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

View File

@ -2,10 +2,21 @@
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
@ -13,7 +24,7 @@ check_file() {
file="$OPTARG"
;;
\?)
echo "Usage: $0 [-f file]"
echo "Usage: $0 [-f file] [--engine=engine_name]"
return 1
;;
:)
@ -23,6 +34,7 @@ check_file() {
esac
done
# Check if file is provided, if not look for default files
if [ -z "$file" ]; then
if [ -f "compose.yaml" ]; then
@ -48,7 +60,23 @@ check_file() {
return 1
fi
# Output the file being used
echo "Using $file"
# 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 "$@"