#!/bin/sh

# run this script to include the 'localdeps.utilities.source' snippet
# in the localdeps.*.sh scripts

# running without arguments will (silently) update all localdeps.*.sh
# scripts in this folder.
#    ./update_scripts
# running with arguments, you can check what would happen (or run
# selectively on a single localdeps.sh script
# print the new script to stdout:
#    ./update_scripts path/to/localdeps.linux.sh
# update a single script:
#    ./update_scripts -i path/to/localdeps.linux.sh

localdepsdir="${0%/*}"

update() {
sed \
    -e '/^#@BEGIN_UTILITIES@$/,/^#@END_UTILITIES@$/{//!d;};' \
    -e "/^#@BEGIN_UTILITIES@$/r ${localdepsdir}/localdeps.utilities.source" \
    "$@"
}

if [ $# -gt 0 ]; then
	update "$@"
else
	update -i "${localdepsdir}/"localdeps.*.sh
fi
