[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: finishing up the /usr/share/doc transition



Attached is my conversion script. It's parameterized at the top, so you
can make copies of /usr/doc and /usr/share doc and point it at them
instead. I have done that in my testing and it seems to work perfectly.

It should handle all the edge cases except:

1. /usr/share mounted elsewhere and not big enough to contain all of
   /usr/doc. One of the mv or cp's will fail, and the script will die.
   Is this sufficient?
2. If /usr/doc/foo is a link to ../share/doc/bar, and /usr/share/doc/foo
   does not exist, it ends up with /usr/share/doc/foo being a link to
   ../share/doc/bar, which will not work. I could add some complex code
   to deal with this, but it seems unlikely and a bug in any package
   that did that anyway.
3. Relative links from /usr/doc/foo/bar to elsewhere will break. I just
   thought of this one, and it probably needs to be fixed.

-- 
see shy jo
NEWDOC=/usr/share/doc
OLDDOC=/usr/doc

set -e

# Remove all symlinks in OLDDOC that correspond to
# symlinks or directories with the same names in NEWDOC
for link in `find $OLDDOC -maxdepth 1 -type l -printf '%P\n'`; do
	if [ "$link" -a -e "$NEWDOC/$link" ]; then
		rm -f "$OLDDOC/$link"
	fi
done

# Remove all symlinks in NEWDOC that correspond to directories with the
# same name in OLDDOC. No, this should not happen. Yes, it does. Sigh.
for link in `find $NEWDOC -maxdepth 1 -type l -printf '%P\n'`; do
	if [ "$link" -a -e "$OLDDOC/$link" ]; then
		rm -f "$NEWDOC/$link"
	fi
done

# If there are any directories with the same names in OLDDOC and  
# NEWDOC, merge them. (And whine about it, since that's a bug.)
for dir in `find $OLDDOC -maxdepth 1 -type d -printf '%P\n'`; do
	if [ "$dir" -a -d "$NEWDOC/$dir" ]; then
		echo "Both /usr/doc/$dir and /usr/share/doc/$dir exist; merging." >&2
		cp -a $OLDDOC/$dir $NEWDOC/$dir
		rm -rf $OLDDOC/$dir
	fi
done

# Move any remaining directories and symlinks from OLDDOC to NEWDOC.
for item in `find $OLDDOC -maxdepth 1 \( -type d -or -type l \) -printf '%P\n'`; do
	if [ "$item" -a -e "$NEWDOC/$item" ]; then
		echo "$item exists in $NEWDOC too; should never happen" >&2
		exit 1
	fi
	mv -f $OLDDOC/$item $NEWDOC
done

# If there are any files left in OLDDOC, move those too if we can.
# This will probably only happen if the admin (or something broken)
# put them there.
for file in `find $OLDDOC -maxdepth 1 -type f -printf '%P\n'`; do
	if [ -e "$NEWDOC/$file" ]; then
		# TODO: deal with this somehow instead of bailing?
		# It is a fairly unlikely edge case though.
		echo "$item exists in $NEWDOC too. Please delete one of them." >&2
		exit 1
	fi
	mv -f $OLDDOC/$file $NEWDOC
done

# Try to delete OLDDOC now; it should be empty.
rmdir $OLDDOC || ( echo "rmdir $OLDDOC failed" >&2 && exit 1)

# Now make the symlink. 
ln -sf share/doc $OLDDOC

Reply to: