2022-08-06 07:52:11 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# 2022-08-05 Hyperling
|
|
|
|
# Create new container template.
|
|
|
|
# usage: create.sh PROJECT_NAME
|
|
|
|
|
2023-07-23 14:51:48 -07:00
|
|
|
## 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"
|
2023-07-23 14:51:48 -07:00
|
|
|
[[ ! -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
|