#!/bin/sh

set -e
set -u
set -x

[ $# -eq 1 ] || exit 1

PROFILE="$1"
[ -n "$PROFILE" ] || exit 2
[ -f "$PROFILE" ] || exit 3

if egrep -q 'flags=\(.*\) {' "$PROFILE"; then
    # Deal with existing flags, but need to account for multiple
    # profiles in one file and not all of them having the same
    # flags.
    grep -q 'flags=(complain)' "$PROFILE" && continue
    sed -i -e 's/flags=(\(.*\)) {$/flags=(complain,\1) {/' -e 's/ {$/ flags=(complain) {/' -e 's/) flags=(complain) {/) {/' "$PROFILE"
else
   # No existing flags
   sed -i 's/ {$/ flags=(complain) {/' "$PROFILE"
fi
