4in1_ws_web/deploy/util/build_common.sh
2025-05-18 00:33:25 +03:00

67 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
set -e
#set -x
INDIR=
OUTDIR=
PRESERVE_OUTPUT=0
error() {
>&2 echo "error: $*"
}
warning() {
>&2 echo "warning: $*"
}
die() {
error "$*"
exit 1
}
usage() {
code="$1"
[ -z "$code" ] && code=0
cat <<EOF
usage: $PROGNAME [OPTIONS]
Options:
-o output directory
-i input directory
-p preserve output directory (don't clear it)
-h show this help
EOF
exit "$code"
}
input_args() {
[ -z "$1" ] && usage
while [ $# -gt 0 ]; do
case $1 in
-o) OUTDIR="$2"; shift ;;
-i) INDIR="$2"; shift ;;
-p) PRESERVE_OUTPUT=1 ;;
-h) usage ;;
*) die "unexpected argument: $1" ;;
esac
shift
done
}
check_args() {
[ -z "$OUTDIR" ] && {
error "output directory not specified"
usage 1
}
[ -z "$INDIR" ] && {
error "input directory not specified"
usage 1
}
if [ ! -d "$OUTDIR" ]; then
mkdir "$OUTDIR"
elif [ "$PRESERVE_OUTPUT" -eq 0 ]; then
find "$OUTDIR" -mindepth 1 -delete
fi
}