All ProjectsHome
csb
csb/src/libexec/csb-new
csb-new Raw
#!/bin/bash
set -euo pipefail

HELP="Create new csb sites and subsites

Usage: 
  $(basename $0) <path> <type> [options]
  $(basename $0) (-h|--help)

Options:
  -h, --help                   show this message and exit
  -s SOURCE, --source SOURCE   source location of code for the repository
  -t PATH, --templates PATH    use PATH as root directory for templates
  -c PATH, --content PATH      use PATH as root directory for dynamic content
  --static PATH                use PATH as root directory for static content"

args=$(echo "$HELP" | csb-optparse "$@")
trap "rm -rf $args" EXIT

[[ $(< "${args}/--help") == "true" ]] && echo "$HELP" && exit 0

TARGET="$(<${args}/PATH)"
TYPE="$(<${args}/TYPE)"

mkdir -p "${TARGET}"

set_if_provided() {
    if [[ -e "${args}/--$1" ]]; then
        local v="$(<${args}/--$1)"
        csb-config set "$1" "$v" "$TARGET"
        echo $v
    fi
}

csb-config new "${TARGET}"
csb-config set type "${TYPE}" "${TARGET}"

set_if_provided source >/dev/null
mkdir -p "$TARGET/$(set_if_provided templates)"
mkdir -p "$TARGET/$(set_if_provided content)"
mkdir -p "$TARGET/$(set_if_provided static)"

CONTENT="$TARGET"
[[ -e "${args}/--content" ]] && CONTENT="$TARGET/$(<$args/--content)"

touch "${CONTENT}/index.md"