#!/bin/bash

# debops-init: create a new DebOps project
# Copyright (C) 2014 Nick Janetakis <nick.janetakis@gmail.com>
# Part of the DebOps project - http://debops.org/

set -e

DEBOPS_SKEL=(
  "$HOME/.local/share/debops/skel"
  "/usr/local/lib/debops/skel"
  "/usr/lib/debops/skel"
)

project="${1:-$PWD}"

if [ -f "$project/.debops.cfg" ]; then
  echo >&2 "$project is already a DebOps project" ; exit 1
fi

for skel_dir in "${DEBOPS_SKEL[@]}"; do
  if [ -d "$skel_dir" ]; then
    cp_source="$skel_dir"
    break
  fi
done

if [ ! -e "$cp_source" ]; then
  echo >&2 "No suitable project skeleton was found" ; exit 1
fi

# Change the cp source to copy into the PWD if it's the PWD.
if [ "$project" = "$PWD" ]; then
  cp_source="$cp_source/."
fi

cp -r ${cp_source} ${project}
echo "Initialized DebOps project in $project"
