#!/bin/bash
# This script is a gem from the Wordpress 2.0.2-2.0.3 upgrade that
# calculates the URL a given path will have on scripts. It does three
# things:
#   1. Resolves all symbolic links
#   2. Splits the path on web_scripts to home and path
#   3. Use home to ldap search for the name of the locker we're serving
#   4. Build the URL from the kaboodle
readlink -f $1 | sed 's,/web_scripts, ,' | (read home path; user=$(ldapsearch -LLL -h scripts.mit.edu -x -b ou=People,dc=scripts,dc=mit,dc=edu "homeDirectory=$home" uid | sed -n 's/^uid: // p'); [ -n "$user" ] && echo "http://$user.scripts.mit.edu$path")
