#!/bin/sh

# Adjust links that begin with former path component $1 to instead use $2.
# Works on all files found by recursive descent (not following links)
# from current directory.

# Made fixes from georg to xenon with
# relink /home/rig/ ~
# relink /home/othercgi/ ~/public_html/cgi-write/
# relink /home/webpages/faculty/rig/ ~/public_html/

find . -lname "$1*" -ls \
     | sed -n 's+.* \([^ ]*\) -> \([^ ]*\).*+\2 \1+p' \
     | sed -n "s+$1\(.* \)+$2\1+p" \
     | sed 's+.* \([^ ]*\)$+rm \1; ln -s &+' \
     | /bin/sh -x
