libreoffice/link-to-ooo-home

60 lines
1.4 KiB
Plaintext
Raw Normal View History

#! /bin/sh
usage()
{
echo "This script (un)links or unlinks the given to/from OOo home"
echo
echo "Usage: ${0##*/} [--unlink] filelist"
}
datadir=/usr/share
# FIXME: It is hard to predict if 32-bit or 64-bit OOo is installed on x86_64
libdir_list="/usr/lib"
if test "`uname -m`" = "x86_64" ; then
libdir_list="$libdir_list /usr/lib64"
fi
if test "$1" = "--unlink" ; then
link_mode=false
shift
else
link_mode=true
fi
test "$1" = "--help" && usage && exit 0
test ! -f "$1" -o -n "$2" && usage && exit 1
filelist="$1"
for libdir in $libdir_list ; do
if $link_mode ; then
for dir in `grep "%dir" $filelist | sed "s|%dir ||"` ; do
linkdir=`echo $dir | sed "s|$datadir|$libdir|"`
mkdir -p $linkdir
done
fi
for file in `grep -v "%dir" $filelist | sed "s|%config ||"` ; do
linkedfile=`echo $file | sed "s|$datadir|$libdir|"`
if $link_mode ; then
ln -sf $file $linkedfile
else
# do not remove still valid symlinks
# they might have another meaning; they might be another package...
test -L $linkedfile -a ! -r $linkedfile && rm -f $linkedfile
fi
done
# FIXME: do not remove empty directories
# they might be in another package that is not longer noarch, ...
# if ! $link_mode ; then
# for dir in `grep "%dir" $filelist | sed "s|%dir ||" | sort -r` ; do
# linkdir=`echo $dir | sed "s|$datadir|$libdir|"`
# rmdir $linkdir 2>/dev/null || true
# done
# fi
done