Files
env-docker/bin/create.sh
T

45 lines
767 B
Bash
Executable File

#!/bin/bash
# 2022-08-05 Hyperling
# Create new container template.
# usage: create.sh PROJECT_NAME
## Setup ##
DIR="`dirname $0`"
PROG=`basename $0`
if [[ $DIR == *"."* ]]; then
DIR="`pwd`"
fi
if [[ -z $DOCKER_HOME ]]; then
DOCKER_HOME="$DIR/.."
fi
## Validation ##
[[ -z $1 ]] && {
echo "ERROR: A project name must be specified."
exit 1
}
[[ ! -z $2 ]] && {
echo "ERROR: Program does not accept a 2nd parameter. Please quote project names with spaces if you insist on using them."
exit 2
}
## Variables ##
dir="$1"
file="$dir/compose.yml"
## Main ##
cd $DOCKER_HOME
mkdir -pv "$dir"
[[ ! -f "$file" ]] && echo -e "# Comment.\nservices:\n" >> "$file" ||
echo "File already exists, leaving contents alone."
echo "${file}:"
cat "$file"
exit 0