#!/bin/sh

# this script updates symlinks to pkg-config files after a Python default
# runtime change

if [ "$#" != 3 ]; then
    echo "Usage: $0 {pre-rtupdate|post-rtupdate|rtupdate} <oldruntime> <newruntime>" >&2
    exit 1
fi

action="$1"
oldruntime="$2"
newruntime="$3"

this="python-gtk2-dev"

pc_files() {
    runtime="$1"

    dpkg -L "$this" | sed -n -e "s#^/usr/lib/pkgconfig/$runtime/##p"
}

case "$action" in
  pre-rtupdate)
  ;;
  post-rtupdate)
  ;;
  rtupdate)
    echo "Updating *.pc symlinks for $this..."

    cd /usr/lib/pkgconfig

    for f in $(pc_files $oldruntime); do
        rm -f "$f"
    done

    for f in $(pc_files $newruntime); do
        ln -s "$newruntime/$f"
    done
  ;;
  *)
    echo "$0 called with unknown argument \`$action'" >&2
    exit 0
  ;;
esac

