diff options
author | CoprDistGit <infra@openeuler.org> | 2023-09-20 14:09:18 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2023-09-20 14:09:18 +0000 |
commit | 998a8f29423c352ceac831c9141efc736d610de8 (patch) | |
tree | 834bc4cfe2a92d14fcff4f1e24f898644f5df421 | |
parent | eb148236f227e5974fa8e4d9aff3cc78b0563ff0 (diff) |
automatic import of libreoffice-share-linkeropeneuler23.03openeuler22.09
-rw-r--r-- | libreoffice-share-linker.spec | 29 | ||||
-rw-r--r-- | link-to-ooo-home | 105 | ||||
-rw-r--r-- | sources | 0 |
3 files changed, 134 insertions, 0 deletions
diff --git a/libreoffice-share-linker.spec b/libreoffice-share-linker.spec new file mode 100644 index 0000000..7399bd7 --- /dev/null +++ b/libreoffice-share-linker.spec @@ -0,0 +1,29 @@ +Name: libreoffice-share-linker +Version: 1 +Release: 1 +Summary: Script to link/unlink files to libreoffice home +License: MIT +Group: Productivity/Office/Suite +Url: http://www.opensuse.org/ +Source0: link-to-ooo-home +BuildRoot: %{_tmppath}/%{name}-%{version}-build +BuildArch: noarch + +%description +Script that links and unlinks files from %{_datadir} to libreoffice +home as libreoffice layout is not set up for noarch packages otherwise. + +%prep +: + +%build +: + +%install +install -Dm 755 %{SOURCE0} %{buildroot}%{_bindir}/%{name} + +%files +%defattr(-,root,root) +%{_bindir}/%{name} + +%changelog diff --git a/link-to-ooo-home b/link-to-ooo-home new file mode 100644 index 0000000..bc835bf --- /dev/null +++ b/link-to-ooo-home @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +usage() { + echo "This script (un)links or unlinks the given to/from libreoffice home" + echo + echo "Usage: ${0##*/} [--unlink] filelist" +} + +change_linking() { + local libdir="$1" + local filelist="$2" + local linkfile="" + local linkdir="" + + # Decide if we are linking or wiping first + if ${link_mode}; then + # Grab all files from the proper folder + for file in `cat ${filelist} | grep "/usr/share/libreoffice" | sort`; do + # if we get ourselves folder then just create it + # it might not be around so lets be safe + if [[ -d "${file}" ]] ; then + dirname="${file/${datadir}/${libdir}}" + # if the location is already there skip it + if [[ ! -e "${dirname}" ]]; then + mkdir -p "${dirname}" + chmod --reference="${file}" "${dirname}" + fi + continue + fi + linkfile="${file/${datadir}/${libdir}}" + # if the file is already there, skip it + # this is true when the parent folder is link + if [[ ! -e "${linkfile}" ]]; then + ln -sf "${file}" "${linkfile}" || exit 1 + fi + done + else + # first just remove the symlinks + for file in `cat ${filelist} | grep "/usr/share/libreoffice" | sort`; do + linkfile=${file/${datadir}/${libdir}} + if [[ -L "${linkfile}" && ! -r "${linkfile}" && ! -d "${linkfile}" ]]; then + rm -f "${linkfile}" || exit 1 + fi + done + # continue by wiping out all EMPTY dirs + # we have to be sure it is not owned by anything else + # doing in 2nd run to ensure avoiding collisions + for file in `cat ${filelist} | grep "/usr/share/libreoffice" | sort`; do + linkdir="${file/${datadir}/${libdir}}" + if [[ -d "${linkdir}" && -z `ls "${linkdir}"/* 2>/dev/null` ]]; then + # check if nothing else owns the dir + if [[ $(rpm -qf "${file}" 2>/dev/null |wc -l) == 0 ]]; then + rmdir "${linkdir}" || exit 1 + fi + fi + done + leftover_dirs=" + /usr/share/libreoffice/help + /usr/share/libreoffice/program + /usr/share/libreoffice/share + /usr/share/libreoffice + " + for i in ${leftover_dirs}; do + if [[ -d ${i} && ! "$(ls -A ${i})" ]]; then + rmdir "${i}" || exit 1 + fi + done + fi +} + +# Global VARS +link_mode=true +datadir=/usr/share +libdirs=( + "/usr/lib/" + "/usr/lib64/" + "/usr/lib32/" +) + +if [[ "$1" == "--unlink" ]]; then + link_mode=false + shift +fi + +if [[ "$1" == "--help" ]]; then + usage + exit 0 +fi + +# Verify we have just one left argument which is the filelist +if [[ $# > 1 || ! -f "$1" ]]; then + usage + exit 1 +fi + +for libdir in ${libdirs[@]}; do + # for each dir verify there is libreoffice folder, otherwise skip + if [[ ! -d "${libdir}/libreoffice/" ]]; then + continue + fi + change_linking ${libdir} $1 + # remove dangling links as they might happen when migratin from older + # libreoffice versions + find ${libdir}/libreoffice -type l -xtype l -delete +done |