#!/bin/bash

set -e

PYTHON=$($(dirname $0)/get-system-python)

# This script takes the bin dir as an argument
if [ $# -ne 1 ]; then
    echo "Usage: $0 bindir"
    echo
    echo "Where 'bindir' is a directory containing scripts with #!/usr/bin/env python"
    exit 1
fi

# Update the matching files in that directory
for f in "$1"/*; do
    if grep -E "^#!/usr/bin/env python" $f >/dev/null 2>&1; then
        echo "Updating #! line of $f"
        perl -p -i -e "s|^#!/usr/bin/env python.*|#!$PYTHON|g" "$f"
    fi
done

