#!/bin/sh
set -e
SNIPPET="/usr/share/epc670-tofhat-utils/epc670-bashrc-snippet"
BASHRC="${1:-/home/$USER/.bashrc}"

if [ -z "$BASHRC" ]; then
  echo "Usage: epc670-bashrc-append <path-to-.bashrc>" >&2
  exit 1
fi
if [ ! -f "$SNIPPET" ]; then
  echo "Error: snippet not found at $SNIPPET" >&2
  exit 1
fi
if [ ! -f "$BASHRC" ]; then
  echo "Error: bashrc not found at $BASHRC" >&2
  exit 1
fi
if grep -q "BEGIN epc670-tofhat-utils" "$BASHRC"; then
  echo "Block already present in $BASHRC, skipping." >&2
  exit 0
fi

echo "" >> "$BASHRC"
cat "$SNIPPET" >> "$BASHRC"