env-docker/bin/create.sh

45 lines
774 B
Bash
Raw Normal View History

2022-08-06 07:52:11 -05:00
#!/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
2022-08-06 07:52:11 -05:00
## 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/docker-compose.yml"
## Main ##
cd $DOCKER_HOME
mkdir -pv "$dir"
[[ ! -f "$file" ]] && echo -e "# Comment.\nservices:\n" >> "$file" ||
2022-08-06 07:52:11 -05:00
echo "File already exists, leaving contents alone."
echo "${file}:"
cat "$file"
exit 0