2014-01-03 22:05:27 +01:00
|
|
|
#!/usr/bin/env bash
|
2011-09-07 17:41:42 +02:00
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
usage() {
|
|
|
|
echo "This script (un)links or unlinks the given to/from libreoffice home"
|
2011-09-07 17:41:42 +02:00
|
|
|
echo
|
|
|
|
echo "Usage: ${0##*/} [--unlink] filelist"
|
|
|
|
}
|
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
change_linking() {
|
|
|
|
local libdir="$1"
|
|
|
|
local filelist="$2"
|
|
|
|
local linkfile=""
|
|
|
|
local linkdir=""
|
|
|
|
|
|
|
|
# If we are starting up then create the folder structure first
|
|
|
|
if ${link_mode}; then
|
|
|
|
for dir in `grep "%dir" ${filelist} | sed "s|%dir ||"` ; do
|
|
|
|
mkdir -p "${dir/${datadir}/${libdir}}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create link for each regular file or prune the link if removing
|
|
|
|
for file in `grep -v "%dir" ${filelist} | sed "s|%config ||"` ; do
|
|
|
|
linkfile=${file/${datadir}/${libdir}}
|
|
|
|
if ${link_mode}; then
|
|
|
|
ln -sf "${file}" "${linkfile}" || exit 1
|
|
|
|
else
|
|
|
|
# remove only empty (broken links)
|
|
|
|
# there might be multiple deps providing the same
|
|
|
|
if [[ -L "${linkfile}" && ! -r "${linfile}" ]]; then
|
|
|
|
rm -f "${linkfile}" || exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Remove all empty dirs but validate if they do not belong
|
|
|
|
# to some other pkg too
|
|
|
|
if ! ${link_mode}; then
|
|
|
|
for dir in `grep "%dir" ${filelist} | sed "s|%dir ||"` ; do
|
|
|
|
linkdir="${dir/${datadir}/${libdir}}"
|
|
|
|
# Check if dir is empty
|
|
|
|
if [[ -d "${linkdir}" && -z `ls "${linkdir}"/*` ]]; then
|
|
|
|
# check if nothing else owns the dir
|
|
|
|
if [[ $(rpm -qf "${dir}" 2>/dev/null |wc -l) == 0 ]]; then
|
|
|
|
rmdir "${linkdir}" || exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
2011-09-07 17:41:42 +02:00
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
# Global VARS
|
|
|
|
link_mode=true
|
|
|
|
datadir=/usr/share
|
|
|
|
libdirs=(
|
|
|
|
"/usr/lib/"
|
|
|
|
"/usr/lib64/"
|
|
|
|
"/usr/lib32/"
|
|
|
|
)
|
2011-09-07 17:41:42 +02:00
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
if [[ "$1" == "--unlink" ]]; then
|
2011-09-07 17:41:42 +02:00
|
|
|
link_mode=false
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
if [[ "$1" == "--help" ]]; then
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
fi
|
2011-09-07 17:41:42 +02:00
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
# Verify we have just one left argument which is the filelist
|
|
|
|
if [[ $# > 1 || ! -f "$1" ]]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2011-09-07 17:41:42 +02:00
|
|
|
|
2014-01-03 22:05:27 +01:00
|
|
|
for libdir in ${libdirs[@]}; do
|
|
|
|
# for each dir verify there is libreoffice folder, otherwise skip
|
|
|
|
if [[ ! -d "${libdir}/libreoffice/" ]]; then
|
|
|
|
continue
|
2011-09-07 17:41:42 +02:00
|
|
|
fi
|
2014-01-03 22:05:27 +01:00
|
|
|
change_linking ${libdir} $1
|
2011-09-07 17:41:42 +02:00
|
|
|
done
|