This repository has been archived on 2023-05-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
neo/man
2022-12-05 15:13:59 +01:00

139 lines
No EOL
4.3 KiB
Bash
Executable file

#!/bin/sh
PROJECT_NAME=${PROJECT_NAME:-neo}
LIST=docker-compose.*.yml
alias dc="docker-compose -p $PROJECT_NAME"
# alias dc="echo docker-compose -p $PROJECT_NAME"
fatal() {
echo "FATAL: $@"
exit 1
}
default() {
fopts=""
for f in $LIST; do
fopts="$fopts -f $f"
done
dc $fopts $*
}
includechain=0
handleFallthrough() {
cmd=${1:-}; shift
case $cmd in
delete-project-files|dpf)
[ -n "$1" ] || fatal "no directory specified"
[ -d /srv/$1 ] || fatal "directory doesn't exist"
ls /srv/$1
printf "Are you sure? (yes/no) [no]: "
read answer
[ "$answer" = "yes" ] && sudo rm -rf /srv/$1 || fatal "cancelled"
;;
-i) #include
if [ $includechain -eq 0 ]; then
LIST="docker-compose.$1.yml"
includechain=1
else
LIST="$LIST docker-compose.$1.yml"
fi
shift
handleFallthrough $@
;;
-x) #exclude
LIST=$(echo $LIST | sed "s/docker-compose.$1.yml//")
shift
handleFallthrough $@
;;
make:*)
WHAT=`echo $cmd | cut -c6-`
case $WHAT in
dc|docker-compose)
[ -n "$1" ] || fatal "no name specified"
FILE="docker-compose.$1.yml"
[ -f $FILE ] && fatal "file exists"
echo -e "version: '2.2'\n" > $FILE
echo -e "services: \n" >> $FILE
;;
backup)
[ -n "$1" ] || fatal "no name specified"
FILE="$1.tar.gz"
[ -f $FILE ] && fatal "file exists"
tar cvf $FILE /srv .
;;
*) fatal "not supported" ;;
esac
;;
setup:*|s:*)
WHAT=`echo $cmd | cut -c8-`
case $WHAT in
ports) sudo ./utils/setup-ports.sh up ./utils/rulelist.rules ;;
def) sudo ./utils/setup.sh ;;
all|a)
sudo ./utils/setup.sh
sudo ./utils/setup-ports.sh up ./utils/rulelist.rules
;;
*) fatal "not supported" ;;
esac
;;
# preference
logs) default logs --tail=20 -f $@ ;;
up) default up -d $@ ;;
upr) default up -d --remove-orphans $@ ;;
--help|-h)
__() {
colsep="$1"
cmd="$2"
desc="$3"
aliases="$4"
printf "%s %-20s %s %-64s %s %-40s %s \n" "$colsep" "$cmd" "$colsep" "$desc" "$colsep" "$aliases" "$colsep"
}
_hr() {
repchar() {
printf "%$1s" | tr " " "$2"
}
__ "*" ${1:-$(repchar 20 -)} ${2:-$(repchar 64 -)} ${3:-$(repchar 40 -)}
}
_r() {
__ "|" "$1" "$2" "$3"
}
_hr
_r $0 Description Aliases
_hr
_hr "Flags" " " " "
_hr
_r "-x" "Excludes a docker-compose file from the list." " "
_r "-i" "Includes a docker-compose file from the list." " "
_hr
_hr "Commands" " " " "
_hr
_r "dpf" "Delete project files." "delete-project-files <name>"
_r "setup:ports" "Setup ports." "setup:ports"
_r "setup:def" "Setup default." "setup:def"
_r "setup:all" "Setup all." "setup:all"
_r "make:dc <name>" "Make docker-compose file." "make:docker-compose <name>"
_r "make:backup <name>" "Make backup file." "tar cvf <name>.tar.gz /srv"
_hr
_hr "Commands/aliases" "(shortcuts)" " "
_hr
_r "up" "Bring up services. (-d)" "$0 default up -d"
_r "upr" "Bring up services and remove orphans." "$0 default up -d --remove-orphans"
_r "logs" "View logs and follow with a tail of 20." "$0 default logs --tail=20 -f"
_hr
_r "default" "fallback to the main docker-compose command with fileopts." "docker-compose"
_hr
;;
default) default $@ ;;
*|'') default $cmd $@ ;;
esac
}
handleFallthrough $@