From 251003985b21cf99d35e7861306d853df7a2a8a1 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Thu, 5 Oct 2023 23:58:26 +0500 Subject: [PATCH] file check --- README.md | 14 +++++++++++- container-compose | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 container-compose diff --git a/README.md b/README.md index a03901d..f5836a0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ # container-compose -neither docker-compose or podman-compose supports building multi arch images and push them to registrar. this is a bash script to attempt to fix it and add support for it. \ No newline at end of file +neither docker-compose or podman-compose supports building multi arch images and push them to registrar. this is a bash script to attempt to fix it and add support for it. + + +This script checks if current dir has one of these files, in this oder +```text +compose.yaml +compose.yml +docker-compose.yaml +docker-compose.yml +podman-compose.yaml +container-compose.yaml +container-compose.yml +``` diff --git a/container-compose b/container-compose new file mode 100755 index 0000000..1a0fa4c --- /dev/null +++ b/container-compose @@ -0,0 +1,54 @@ +#!/bin/bash + +check_file() { + local file="" + local opt + local OPTARG + local OPTIND=1 + + # Check if -f flag is provided + while getopts ":f:" opt; do + case $opt in + f) + file="$OPTARG" + ;; + \?) + echo "Usage: $0 [-f file]" + 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 "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.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 + + # Output the file being used + echo "Using $file" +} +check_file "$@"