#!/bin/bash
#############################################################
#  lomanager
#
# Purpose: manage the installation/update/removal of LibreOffice in PCLinuxOS 
# 
# Requirements: 
#  - PCLinuxOS installation 
#  - Internet connection (not for removal)
#  - zenity, bc, awk, curl, wget, sed, wmctrl, webcore-fonts, xdg-utils, notify-send
#
# Obsoletes: getopenoffice
#
# Version: 26.2.3-1 (2026-04-28) by pinoc <vogtpet@gmail.com>
#############################################################
# Copyright (C) 2026 Bill Reynolds <texstar@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################
# i18n - Internationalization 
#====================================================
export TEXTDOMAIN=lomanager
export TEXTDOMAINDIR="/usr/share/locale"
export LC_NUMERIC="en_US.UTF-8"
glov="26.2.3" && glov2="26.2" && WICON='/usr/share/icons/office_section.png'
LOCURRENT="70e089b17412e4cb7773e41413306b17a2328c34"
TITLE="LibreOffice Manager "$glov 
ZEN2="/usr/bin/zenity --no-wrap --window-icon="$WICON
ZEN3="/usr/bin/zenity --window-icon="$WICON

if [ -d "/union" ]; then
    $ZEN2 --title="lomanager" --info --text=$"Please run this program after installation!"
  exit 0
fi


#set default parameters:
VERBOSE=0
VINFO=0

#read parameters from command line
#=================================================
for i in $*
do
  case $i in
     --debug)
     VERBOSE=1
     ;;
     --vinfo)
     VINFO=1
     ;;
     --help)
     echo "usage: $0 --debug --vinfo"
     echo "--debug: verbose output for debugging"
     echo "--vinfo: info on installed and latest version"
     echo "--help: show options"
     exit
     ;;
     *)
     # unknown option
     echo "Error: unknown option"
     echo "usage: $0 --help"
     exit
     ;;
 esac
done

# version testing
#===========================
if [ $VINFO -eq 1 ]; then 
  v_installed=0
  if rpm -qa | grep -q libreoffice; then v_installed=`rpm -qa libreoffice*-ure* --qf '%{version}'|cut -d '.' -f 1-3`; fi
  v_new=$glov 
  echo 'installed version: ' $v_installed
  echo 'current version  : ' $v_new
  exit 0
fi

# Check if not root
#=================================================
if [ "$USER" != "root" ]; then
  echo "Please run this script from the start menu or as root (su -)!"
  exit 0
fi

# verbose output for debugging
if [ $VERBOSE -eq 1 ]; then set -xv;fi


# define some variables
#=================================================
lomil="/tmp/lomanager-install.log"
# PV-update and insert from losort
# remember to update libreoffice-openclipart  when glov2 has changed
sysarch=`getconf LONG_BIT` 
sysarchdir="x86_64" && sysarchext="_x86-64"
tmpdir=/root/LOtmp
basepackdir="LibreOffice_"$glov"_Linux"$sysarchext"_rpm"
basepack=$basepackdir".tar.gz"   # base package to be downloaded
langpackbase="LibreOffice_"$glov"_Linux"$sysarchext"_rpm_langpack_" # non en_US langpack
helppackbase="LibreOffice_"$glov"_Linux"$sysarchext"_rpm_helppack_" # help package
httpsource="https://download.documentfoundation.org/libreoffice/stable/"$glov"/rpm/"$sysarchdir"/"  # http-source

# check that package managers are closed
#=================================================
for idx in synaptic kpackage apt-get dnf dnf5_launcher
do 
 if [ "`ps -ef|grep -w $idx | wc -l`" -ge 2 ];then
  MSG=$"Please close your package manager '$idx' \nand then run LibreOffice Manager again.\n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  cd && /bin/rm -fr $tmpdir 
  exit 0
 fi
done

# check for running OO or LO processes,
# if found get their windowID and close them gracefully
#=========================================================
wids=`wmctrl -l |grep "LibreOffice Base\|LibreOffice Calc\|LibreOffice Draw\|LibreOffice Impress\|LibreOffice Math\|LibreOffice Writer\|Printer Administration\|OpenOffice.org Base\|OpenOffice.org Calc\|OpenOffice.org Draw\|OpenOffice.org Impress\|OpenOffice.org Math\|OpenOffice.org Writer"|awk '{print$1}'`
if [ -n "$wids" ];then 
  MSG=$"Active Office application found\!\nWe will close it now. Then restart LibreOffice Manager.\n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  for idx in $wids; do wmctrl -ic $idx; done
  pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null
  cd && /bin/rm -fr $tmpdir
  exit 0
fi


# get system users
SYSUSERS=$(grep [0-9][0-9][0-9]:.*/home /etc/passwd | grep -f /etc/shells | cut -d: -f1)

# Check for live session and available disk space 
#=================================================================
if [ -d "/union" ]; then LIVE_MODE=1; else LIVE_MODE=0; fi
if [ $LIVE_MODE -eq 1 ];then TITLE=$TITLE"-live session:";fi
FREE=`df -k |grep "/$" |awk '{print$4}'`
if [ -e /usr/bin/java ];then MINSPACE=1100000; else MINSPACE=1300000;fi

# exit if not enough space, especially in live-session
if [ $LIVE_MODE -eq 1 ] && [ $FREE -lt $MINSPACE ];then 
  MSG=$"              Welcome to LibreOffice Manager\!\n\nPlease run this program after the live session has been installed to the harddisk of your computer. \n\nExiting..."
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  cd && /bin/rm -fr $tmpdir
  exit 0
fi

# define LO-locales and their desciptions: 
# total 110 in 4.4
# in OO: Tools -> Options -> Language Settings-> Languages
# alphabetically sorted listing for lomanager
# OO locales
#  insert here from losort (1):
OOLOC=(en-US af sq am ar as ast eu be bn bn-IN brx bs br bg my ca ca-valencia zh-CN zh-TW hr cs da dgo nl dz en-ZA en-GB eo et fa fi fr ga gd gl ka de el gu he hi hu is id it ja kn ks kk km rw kok ko kmr-Latn lo lv lt lb mk mai ml mni mr mn nr ne nso nb nn oc or om pl pt-BR pt pa-IN ro ru sa-IN sat sr sr-Latn sid sd si sk sl st es sw-TZ ss sv tg ta tt te th bo ts tn tr uk ug uz ve vi cy xh zu)
count=${#OOLOC[@]}

#  insert here from losort (2):
# OO locale descriptions
OOLOCT=("English (USA)" "Afrikaans" "Albanian" "Amharic" "Arabic" "Assamese" "Asturian" "Basque" "Belarusian" "Bengali" "Bengali (India)" "Bodo (India)" "Bosnian" "Breton" "Bulgarian" "Burmese" "Catalan" "Catalan (Valencian)" "Chinese (simplified)" "Chinese (traditional)" "Croatian" "Czech" "Danish" "Dogri" "Dutch" "Dzongkha" "English (South Africa)" "English (United Kingdom)" "Esperanto" "Estonian" "Farsi" "Finnish" "French" "Gaelic (Ireland)" "Gaelic (Scotland)" "Galician" "Georgian" "German" "Greek" "Gujarati" "Hebrew" "Hindi (India)" "Hungarian" "Icelandic" "Indonesian" "Italian" "Japanese" "Kannada (India)" "Kashmiri (Kashmir)" "Kazakh" "Khmer" "Kinyarwanda" "Konkani" "Korean" "Kurdish" "Lao" "Latvian" "Lithuanian" "Luxembourgish" "Macedonian" "Maithili" "Malayalam (India)" "Manipuri" "Marathi (India)" "Mongolian" "Ndebele" "Nepali" "Northern Sotho" "Norwegian (Bokmaal)" "Norwegian (Nynorsk)" "Occitan" "Oriya (India)" "Oromo" "Polish" "Portuguese (Brazil)" "Portuguese (Portugal)" "Punjabi (India)" "Romanian" "Russian" "Sanskrit (India)" "Santali" "Serbian" "Serbian Latin (Serbia)" "Sidama" "Sindhi" "Sinhala" "Slovak" "Slovenian" "Sotho" "Spanish" "Swahili (Tanzania)" "Swati" "Swedish" "Tajik" "Tamil (India)" "Tatar" "Telugu (India)" "Thai" "Tibetan (PR China)" "Tsonga" "Tswana" "Turkish" "Ukrainian" "Uyghur" "Uzbek" "Venda" "Vietnamese" "Welsh" "Xhosa" "Zulu")
count2=${#OOLOCT[@]}  # this list to be used later in line 335

# find out how much space we need, get current locale
a=`cat /etc/sysconfig/i18n |grep 'LC_TELEPHONE='` && a=${a:13:5}
LOC1=${a:0:2} && LOC2=${a:3:2} && LOC3=$LOC1'-'$LOC2
if [ "$LOC3" == "en-US" ]  || [ "$LOC3" == "en-GB" ] || [ "$LOC3" == "en-ZA" ] || [ "$LOC3" == "ca-valencia" ] || [ "$LOC3" == "pa-IN" ] || [ "$LOC3" == "pt-AO" ] || [ "$LOC3" == "pt-BR" ] || [ "$LOC3" == "sa-IN" ] || [ "$LOC3" == "sw-TZ" ] || [ "$LOC3" == "zh-CN" ] || [ "$LOC3" == "zh-TW" ];then
  tt=$LOC3
else
  tt=$LOC1
fi

# if tt is not in OOLOC then reset to en-US 
index=0 && isok="0"
while [ $index -lt $count ]; do
  if [ "$tt" == "${OOLOC[$index]}" ];then isok="1";fi
  let "index++"
done
if [ "$isok" == "0" ];then 
  LOC1="en" && LOC2="US" && LOC3="en-US" && tt="en-US"
fi

# check if any OO-version is installed. If so, then offer the option to uninstall
set -- /usr/bin/ooffice2* && if [ -f "$1" ];then QQ=$#; else QQ=0;fi
if [ $QQ != "0" ] || [ -e /usr/bin/ooffice3.0 ] || [ -e /usr/bin/openoffice.org3 ] || [ -e /usr/bin/libreoffice* ] ; then 
  OOOPT=$($ZEN3 --title "$TITLE" --list --text $"                         Welcome to LibreOffice Manager\!\n\nPlease select an option and press OK, or press Cancel to quit." --width 600 --height 275  --list  --radiolist  --column $"Select Option" --column $"LibreOffice Action" TRUE $"Install, reinstall, upgrade, or add LibreOffice locale" FALSE $"Completely remove LibreOffice");
  # Quit if Cancel was pressed
  #===================================================
  if [ "$OOOPT" == "" ]; then 
      $ZEN2 --title "$TITLE" --info --width=400 --text=$"You chose to exit. \nNo changes were applied to your system."
      cd && /bin/rm -fr $tmpdir
      exit 0
  # completely remove
  #===================================================
  elif [ "$OOOPT" == $"Completely remove LibreOffice" ]; then
  
    # OpenOffice version 2.x
    if [ $QQ != "0" ]; then 
      $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
      dnf remove openoffice.org openoffice.org-mimelnk -y
      update-menus
      # get the installed OO2.4-version
      XX=`ls /usr/bin/ooconfig*` && XX=${XX:17:3}
      for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo-2.0; done
      for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo-$XX; done
      /bin/rm -fr /root/.ooo-$XX && /bin/rm -fr /root/.ooo-2.0
      MSG=$"OpenOffice has been successfully removed from your system."
      if [ ! -e /usr/bin/libreoffice ];then
        $ZEN2 --title="$TITLE" --info --timeout 10 --text="$MSG"
        cd && /bin/rm -fr $tmpdir
        exit 0
      fi
    fi
    
    # OpenOffice version 3.0.0 (was on 2009.1 CD)
    if [ -e /usr/bin/ooffice3.0 ]; then 
      $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
      dnf remove openoffice.org-core -y
      update-menus
      for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo3 /home/$idx/.config/.ooo3; done
      /bin/rm -fr /root/.ooo3 /root/.config/.ooo3 /opt/openoffice*
      psoo=`/bin/ps -ef|grep -i OpenOffice|awk '{print$2}'` && kill -9 $psoo &>/dev/null
      MSG=$"OpenOffice has been successfully removed from your system."
      if [ ! -e /usr/bin/libreoffice ];then
        $ZEN2 --title="$TITLE" --info --timeout 10 --text="$MSG"
        cd && /bin/rm -fr $tmpdir && update-menus
        exit 0
      fi
    fi
    
    # OpenOffice version 3.0.1 and higher
    if [ -e /usr/bin/openoffice.org3 ]; then
      # inform about OO-removal
      MSG=$"OpenOffice detected\!\n\nPlease press \n - 'Yes' <span color='red'><b>to remove the outdated/unsupported\n    OpenOffice</b></span>.\n - 'No' to exit this script"
      $ZEN2 --title="$TITLE" --question --text "$MSG"
      if [ "$?" == "1" ]; then 
        cd && /bin/rm -fr $tmpdir
        exit 0
      fi
      # remove the older or current version completely
      bv=`cat /opt/openoffice.org3/program/versionrc | grep 'OOOBaseVersion='`
      bv=${bv##OOOBaseVersion=} && if [ "$bv" == "" ]; then bv="3.1";fi
      $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
      dnf remove openoffice.org-ure openoffice.org$bv-mandriva-menus -y
      update-menus
      for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo3 /home/$idx/.config/.ooo3 /home/$idx/OpenOffice_Info.txt /home/$idx/Desktop/getopenoffice.desktop; done
      /bin/rm -fr /root/.ooo3 /root/.config/.ooo3 /opt/openoffice* /root/Desktop/getopenoffice.desktop
      /bin/rm -f /etc/skel/OpenOffice_Info.txt /root/OpenOffice_Info.txt
      /bin/rm -f /etc/skel_fm/OpenOffice_Info.txt /etc/skel_default/OpenOffice_Info.txt
      /bin/rm -f /etc/skel-orig/OpenOffice_Info.txt
      psoo=`/bin/ps -ef|grep -i OpenOffice|awk '{print$2}'` && kill -9 $psoo &>/dev/null
      MSG=$"OpenOffice has been successfully removed from your system."
      if [ ! -e /usr/bin/libreoffice ];then
        $ZEN2 --title="$TITLE" --info --timeout 10 --text="$MSG"
        cd && /bin/rm -fr $tmpdir && update-menus
        exit 0
      fi
    fi
  
    # LibreOffice version 3.3
    if [ -e /usr/bin/libreoffice ]; then
      # test for and kill LO-quickstarter
      pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null
      # remove the older or current version completely
      bv=`cat /opt/libreoffice/program/versionrc | grep 'OOOBaseVersion='`
      bv=${bv##OOOBaseVersion=} && if [ "$bv" == "" ]; then bv="3.3";fi 
      $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing LibreOffice. \nPlease be patient... :-)" &
      dnf remove libreoffice3-ure libreoffice$bv-mandriva-menus -y
      update-menus
      for idx in $SYSUSERS
        do 
        /bin/rm -fr /home/$idx/.libreoffice /home/$idx/.config/.libreoffice /home/$idx/Desktop/lomanager.desktop
        if [ -d /home/$idx/.kde4/vdt ]; then /bin/rm -f /home/$idx/.kde4/vdt/2/2a/LO*;fi
       done
      if [ -d /etc/skel_fm/.kde4/vdt ]; then /bin/rm -f /etc/skel_fm/.kde4/vdt/2/2a/LO*; fi
      /bin/rm -fr /root/.libreoffice /root/.config/.libreoffice /opt/libreoffice /root/Desktop/lomanager.desktop
      /bin/rm -f /usr/share/icons/libreoffice-*

      MSG=$"LibreOffice has been successfully removed from your system."
      $ZEN2 --title="$TITLE" --info --timeout 10 --text="$MSG"
      cd && /bin/rm -fr $tmpdir && update-menus -n
      exit 0
    fi
    
    
    # PV-update
    # declare here all versions INCLUDING the current version
    declare -a LOOLDV=("3.4" "3.5" "3.6" "4.0" "4.1" "4.2" "4.3" "4.4" "5.0" "5.1" "5.2" "5.3" "5.4" "6.0" "6.1" "6.2" "6.3" "6.4" "7.0" "7.1" "7.2" "7.3" "7.4" "7.5" "7.6" "24.2" "24.8" "25.2" "25.8" "26.2")
    for idxx in "${LOOLDV[@]}"
    do
    bv="$idxx" && loexe=/usr/bin/libreoffice$bv
    if [ -e $loexe ]; then
      # test for and kill LO-quickstarter
      pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null
      # remove the older or current version completely
      $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing LibreOffice. \nPlease be patient... :-)" &
      if [ "$bv" == "3.4" ]
      then 
        dnf remove libreoffice$bv-ure libreoffice$bv-mandriva-menus -y
      elif [ "$bv" == "3.5" ] || [ "$bv" == "3.6" ] || [ "$bv" == "4.0" ]
      then 
        dnf remove libreoffice$bv-ure libreoffice$bv-stdlibs libreoffice$bv-mandriva-menus -y
      else
        dnf remove libreoffice$bv-ure libreoffice$bv-freedesktop-menus libobasis$bv-ooofonts -y
      fi
      update-menus
      
      for idx in $SYSUSERS
        do 
        /bin/rm -fr /home/$idx/.libreoffice /home/$idx/.config/libreoffice /home/$idx/Desktop/lomanager.desktop
        done
      /bin/rm -fr /root/.libreoffice /root/.config/.libreoffice /root/.config/libreoffice /opt/libreoffice* /root/Desktop/lomanager.desktop /etc/skel/.config/libreoffice*
      /bin/rm -f /usr/share/icons/libreoffice* && update-menus -n

      MSG=$"LibreOffice has been successfully removed from your system."
      $ZEN2 --title="$TITLE" --info --timeout 10 --text="$MSG"
      cd && /bin/rm -fr $tmpdir
      exit 0
    fi
    done


  # install/update option
  #===================================================
  else
    if [ -e /usr/bin/openoffice.org3 ]; then
      # inform about OO-removal
      MSG=$"OpenOffice detected\!\n\nPlease press \n - 'Yes' <span color='red'><b>to remove the outdated/unsupported\n    OpenOffice</b></span> and <span color='black'><b>to install the current and\n    supported version of LibreOffice</b></span>.\n - 'No' to exit this script"
      $ZEN2 --title="$TITLE" --question --text "$MSG"
      if [ "$?" == "1" ]; then 
        cd && /bin/rm -fr $tmpdir
        exit 0
      fi
    fi

    # PV-update
    # all old versions but NOT the current one
    if [ -e /usr/bin/libreoffice ] || [ -e /usr/bin/libreoffice3.* ] || [ -e /usr/bin/libreoffice4.* ] || [ -e /usr/bin/libreoffice5.* ] || [ -e /usr/bin/libreoffice6.* ] || [ -e /usr/bin/libreoffice7.0 ] || [ -e /usr/bin/libreoffice7.1 ] || [ -e /usr/bin/libreoffice7.2 ] || [ -e /usr/bin/libreoffice7.3 ] || [ -e /usr/bin/libreoffice7.4 ]  || [ -e /usr/bin/libreoffice7.5 ] || [ -e /usr/bin/libreoffice7.6 ] || [ -e /usr/bin/libreoffice24.2 ] || [ -e /usr/bin/libreoffice24.8 ] || [ -e /usr/bin/libreoffice25.2 ] || [ -e /usr/bin/libreoffice25.8 ] ; then
      # inform about LO6.X-removal
      MSG=$"Outdated LibreOffice detected\!\n\nPlease press \n - 'Yes' <span color='red'><b>to remove the outdated/unsupported\n    LibreOffice</b></span> and <span color='black'><b>to install the current and\n    supported version of LibreOffice</b></span>.\n - 'No' to exit this script"
      $ZEN2 --title="$TITLE" --question --text "$MSG"
      if [ "$?" == "1" ]; then 
        cd && /bin/rm -fr $tmpdir
        exit 0
      fi
    fi

    # if current version is already installed then we need less space
    if [ -e /usr/bin/libreoffice$glov2 ]; then
       a=`cat /opt/libreoffice$glov2/program/versionrc | grep 'buildid='` && a=${a##buildid=}
       if [ "$a" == "$LOCURRENT" ]; then 
         # the current version is already installed, space for additional locale ~ 90MB
         MINSPACE=100000
       else
         # inform about LO5.x-removal
         MSG=$"Outdated LibreOffice detected\!\n\nPlease press \n - 'Yes' <span color='red'><b>to remove the outdated/unsupported\n    LibreOffice</b></span> and <span color='black'><b>to install the current and\n    supported version of LibreOffice</b></span>.\n - 'No' to exit this script"
         $ZEN2 --title="$TITLE" --question --text "$MSG"
         if [ "$?" == "1" ]; then 
          cd && /bin/rm -fr $tmpdir
          exit 0
        fi
       fi
    fi
  fi
fi

# exit if not enough space
if [ $FREE -lt $MINSPACE ]; then
  MSG=$"Insufficient disk space to install LibreOffice.\n\nExiting..."
  $ZEN2 --title "$TITLE" --error --text "$MSG"
  cd && /bin/rm -fr $tmpdir
  exit 0
fi

# only now we need a working internet connection
#=================================================
# check for proper openssl-setup, maybe required for some LO-servers
if [ ! -d /etc/openssl ];then 
  /bin/mkdir /etc/openssl
  /bin/ln -s /etc/ssl/certs/ /etc/openssl/certs
fi

cd /tmp && /bin/rm -f index.html* inet.log*
MSG=$"Testing your Internet connection..."
( wget --timeout=40 https://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN3 --width 400 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close

if [ -f /tmp/index.html ]; then
  echo
  echo Internet connection working
  echo
  /bin/rm -f index.html* inet.log*
else
  MSG=$"Problem accessing the Internet\! You have either:\n a) no Internet connection, too bad :-(, or\n b) you use a proxy sever, or \n c) you have a dns-lookup error.\n\nNote: If you are sure that your Internet connection works fine then you could try to reconfigure it:\n\n b) Configure your proxy server:\n=================================\nopen a konsole and enter:\n      export http_proxy=http://proxy.example.com:8080\nReplace with the name of your proxy server. Then in the same konsole enter:  lomanager \n\n c) Configure your Internet to use OpenDNS:\n=================================\n1. Open PCLinuxOS Control Center 'Configure Your Computer'\n2. Select 'Network and Internet' -> 'Network Center', open your network connection and click the button 'Configure' \n3. Uncheck 'Get DNS servers from DHCP'.\n     In the box for DNS Server 1 enter: 208.67.222.222 \n     In the box for DNS Server 2 enter: 208.67.220.220 \nClick on 'OK' at the bottom right to close this dialog window. \n4. Back in the Network Center window click on 'Disconnect', wait for it to finish, then click on 'Connect'. \n5. Your Internet connection is now configured to use OpenDNS. Close all open PCC-windows and start lomanager again. \n\nNote: these OpenDNS configuration steps have been saved to the file 'OpenDNS_howto.txt' in your HOME-directory.\nExiting..."
  $ZEN2 --title="$TITLE" --info --text "$MSG"

  # output the OpenDNS config info
  INP1=/root/OpenDNS_howto.txt
  echo "Steps to reconfigure your Internet connection" > $INP1
  echo " " >> $INP1
  echo "a) using your proxy server:" >> $INP1
  echo "============================================ " >> $INP1
  echo "open a konsole and enter: " >> $INP1
  echo "   export http_proxy=http://proxy.example.com:8080" >> $INP1
  echo "Replace with the name of your proxy server. " >> $INP1
  echo "Then in the same konsole enter the command of your application, i.e:  lomanager  " >> $INP1
  echo " " >> $INP1
  echo "b) using OpenDNS (https://www.opendns.com/):" >> $INP1
  echo "============================================ " >> $INP1
  echo "1. Open PCLinuxOS Control Center 'Configure Your Computer'." >> $INP1
  echo "2. Select 'Network and Internet' -> 'Network Center', open your network connection and click the button 'Configure'" >> $INP1
  echo "3. Uncheck 'Get DNS servers from DHCP'" >> $INP1
  echo "        In the box for DNS Server 1 enter: 208.67.222.222" >> $INP1
  echo "        In the box for DNS Server 1 enter: 208.67.220.220" >> $INP1
  echo "   Finally click on the OK button at the bottom right to close this dialog window.   " >> $INP1
  echo "4. Back in the Network Center window click on 'Disconnect', wait for it to finish, then click on 'Connect'." >> $INP1
  echo "5. Your Internet connection is now configured to use OpenDNS. Close all open PCC-windows." >> $INP1
    
  /bin/cp $INP1 /etc/skel/OpenDNS_howto.txt
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/OpenDNS_howto.txt
    /bin/cp $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  /bin/rm -f index.html* inet.log* && cd && /bin/rm -fr $tmpdir
  exit 0
fi

# ok, now that we have a Internet connection do some tests 
#===============================================================
# first initialize the log-file
echo "lomanager installation log file:" > $lomil ; date >> $lomil
rpm -qa lomanager >> $lomil

# 1) check that we use the latest lomanager version, if not exit and show how to properly update
# browser test
#======================
wwwb=""
louser=`/bin/ps -ef |grep -m 1 'lomanager'|awk '{print$1}'`
echo louser $louser  >> $lomil

# browser test 
# unfortunately www-browser and xdg-open does not work
# everywhere so we first test through a list of browsers
# to find out if there is any browser installed
#
# Note:  chromium-browser and firefox can only be launched as root, we don't want that
#
#for idx in konqueror rekonq opera midori epiphany jumanji xxxterm dillo surf chromium-browser firefox
# working: konqueror opera midori epiphany jumanji xxxterm dillo surf 
# not working: rekonq chromium-browser firefox arora seamonkey


for idx in konqueror opera midori epiphany jumanji xxxterm dillo surf
do
  if which $idx 2>/dev/null; then
    wwwb=`which $idx 2>/dev/null`
    break
  fi
done

if [ "$wwwb" != "" ];then
  echo "Detected webbrowser: "$wwwb  >> $lomil
else
  echo "no supported webbrowser could be detected" >> $lomil
fi

cd /tmp; /bin/rm -f index.html* lomanager-*.rpm*

# 2) test the http status of the LO-base pack
source=$httpsource$basepack
HTTPstat=`curl -I --stderr /dev/null $source | grep "Not Found" | cut -d' ' -f2`
if [[ "$HTTPstat" -ge 400 ]]; then
  # current version is installed but not (yet) on LO-servers
  a=`cat /opt/libreoffice$glov2/program/versionrc | grep 'buildid='` && a=${a##buildid=}
  if [ "$a" == "$LOCURRENT" ]; then 
    MSG=$"LibreOffice uptodate but not (yet) on the LO-servers.\nTest again later.\n\nExiting..."
    $ZEN2 --title "$TITLE" --info --text "$MSG"
    cd && /bin/rm -fr $tmpdir /tmp/LO_* /tmp/td* /tmp/*.mirrorlist*
    exit 1
  fi
  MSG=$"LibreOffice package not found. \nPlease use an updated version of lomanager or the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread.\nhttps://www.pclinuxos.com/forum/index.php/topic,59009.0.html\n\nExiting..."
  $ZEN2 --title "$TITLE" --error --text "$MSG"
  echo "base-pack not found on LO-servers" >> $lomil
  /bin/rm -fr $tmpdir
  if [ "$wwwb" != "" ];then 
     /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
  fi
  exit 1
fi

# Explain what we want to do: build zenity dialog text
#  insert here from losort (3):
#=================================================
GOO_LANG=$($ZEN3 --title "$TITLE" --list --text $"Please scroll the list below and either\n- confirm the selected LibreOffice locale, or\n- select any other LibreOffice locale, or\n- press Cancel to quit this script." --width 400 --height 500 --radiolist --column $"Select" --column $"New locale (country settings)" TRUE "English (USA)" FALSE "Afrikaans" FALSE "Albanian" FALSE "Arabic" FALSE "Assamese" FALSE "Asturian" FALSE "Basque" FALSE "Belarusian" FALSE "Bengali" FALSE "Bodo (India)" FALSE "Bosnian" FALSE "Breton" FALSE "Bulgarian" FALSE "Burmese" FALSE "Catalan" FALSE "Catalan (Valencian)" FALSE "Chinese (simplified)" FALSE "Chinese (traditional)" FALSE "Croatian" FALSE "Czech" FALSE "Danish" FALSE "Dogri" FALSE "Dutch" FALSE "Dzongkha" FALSE "English (South Africa)" FALSE "English (United Kingdom)" FALSE "Esperanto" FALSE "Estonian" FALSE "Farsi" FALSE "Finnish" FALSE "French" FALSE "Gaelic (Ireland)" FALSE "Gaelic (Scotland)" FALSE "Galician" FALSE "Georgian" FALSE "German" FALSE "Greek" FALSE "Gujarati" FALSE "Hebrew" FALSE "Hindi (India)" FALSE "Hungarian" FALSE "Icelandic" FALSE "Indonesian" FALSE "Italian" FALSE "Japanese" FALSE "Kannada (India)" FALSE "Kashmiri (Kashmir)" FALSE "Kazakh" FALSE "Khmer" FALSE "Kinyarwanda" FALSE "Konkani" FALSE "Korean" FALSE "Kurdish" FALSE "Lao" FALSE "Latvian" FALSE "Lithuanian" FALSE "Luxembourgish" FALSE "Macedonian" FALSE "Maithili" FALSE "Malayalam (India)" FALSE "Manipuri" FALSE "Marathi (India)" FALSE "Mongolian" FALSE "Ndebele" FALSE "Nepali" FALSE "Northern Sotho" FALSE "Norwegian (Bokmaal)" FALSE "Norwegian (Nynorsk)" FALSE "Occitan" FALSE "Oriya (India)" FALSE "Oromo" FALSE "Polish" FALSE "Portuguese (Brazil)" FALSE "Portuguese (Portugal)" FALSE "Punjabi (India)" FALSE "Romanian" FALSE "Russian" FALSE "Sanskrit (India)" FALSE "Santali" FALSE "Serbian" FALSE "Serbian Latin (Serbia)" FALSE "Sindhi" FALSE "Sinhala" FALSE "Slovak" FALSE "Slovenian" FALSE "Sotho" FALSE "Spanish" FALSE "Swahili (Tanzania)" FALSE "Swati" FALSE "Swedish" FALSE "Tajik" FALSE "Tamil (India)" FALSE "Tatar" FALSE "Telugu (India)" FALSE "Thai" FALSE "Tibetan (PR China)" FALSE "Tsonga" FALSE "Tswana" FALSE "Turkish" FALSE "Ukrainian" FALSE "Uyghur" FALSE "Uzbek" FALSE "Venda" FALSE "Vietnamese" FALSE "Welsh" FALSE "Xhosa" FALSE "Zulu");

# Quit if Cancel was pressed
if [ "$GOO_LANG" == "" ]; then 
  $ZEN2 --title "$TITLE" --info --text=$"You chose to exit. \nNo changes were applied to your system."
  cd && /bin/rm -fr $tmpdir
  exit 0
fi

# get selected locale
index=0
while [ $index -lt $count ]; do
  if [ "$GOO_LANG" == "${OOLOCT[$index]}" ];then tt=${OOLOC[$index]};fi
  let "index++"
done

# reset Portuguese (pt-PT) and Belarusian (be-BY) still needed??
#if [ "$tt" == "pt-PT" ];then tt="pt"; fi 
#if [ "$tt" == "be-BY" ];then tt="be"; fi 

# check if selected version is already installed,
# inform about language switching or offer to reinstall a borked OO install
#==========================================================================
LOREINSTALL=0
if [ `rpm -qa libreoffice$glov2-$tt |wc -l` == "1" ]; then
  # libreoffice is already installed get the installed version
  a=`cat /opt/libreoffice$glov2/program/versionrc | grep 'buildid='` && a=${a##buildid=}
  if [ "$a" == "$LOCURRENT" ]; then 
    MSG=$"The current version of LibreOffice is already installed for this locale\!\n\nNOTE: to select any added locale in LibreOffice go to:\nTools -> Options -> Language Settings\n         -> Languages: User Interface\nThen restart LibreOffice to apply the new locale.\n\nPlease press \n - 'Yes' to exit this script now, or \n - 'No' to REINSTALL the current (borked) version \n   of LibreOffice.\n\nIMPORTANT: selecting 'No' will remove all LibreOffice locales\nas well as any customized LibreOffice settings\!\!"
    $ZEN2 --title="$TITLE" --question --text "$MSG"
    if [ "$?" == "0" ]; then 
      cd && /bin/rm -fr $tmpdir
      exit 0
    else 
      LOREINSTALL=1
    fi
  fi
fi

# inform about dictionary
#============================================
if [ "$tt" != "en-US" ];then
 INP1=/root/getLOdictionary.txt
  echo "A LibreOffice dictionary might be available for you new locale." > $INP1
  echo "Please follow these steps to install a LibreOffice dictionary:" >> $INP1
  echo "1) Ensure LibreOffice is not running." >> $INP1
  echo "2) Open the following url in your web-browser:" >> $INP1
  echo "   https://extensions.services.openoffice.org/dictionary" >> $INP1
  echo "3) Download the appropriate dictionary, open it with LibreOffice, and follow the instructions." >> $INP1
  echo "   " >> $INP1
  echo "Additional extensions can be found here:" >> $INP1
  echo "   https://libreplanet.org/wiki/Group:OpenOfficeExtensions/List" >> $INP1
  echo "   " >> $INP1
  echo "LibreOffice Templates can be found here: " >> $INP1
  echo "   https://wiki.documentfoundation.org/Downloads/Templates" >> $INP1
  echo "   " >> $INP1
  echo "Note: to select any added locale in LibreOffice go to:" >> $INP1
  echo "Tools -> Options -> Language Settings -> Languages: User Interface" >> $INP1
  echo "Then restart LibreOffice to apply the new locale." >> $INP1
  /bin/cp $INP1 /etc/skel/getLOdictionary.txt
  for idx in $SYSUSERS
    do
    INP2=/home/$idx/getLOdictionary.txt
    /bin/cp $INP1 $INP2 && chown $idx:`id -gn $idx` $INP2
  done
  MSG=$"A LibreOffice dictionary might be available for your\nnew LibreOffice localization.\nPlease read the document 'getLOdictionary.txt' in your\nHome folder for further instructions."
  $ZEN2 --timeout 10 --title="$TITLE" --info --text "$MSG" &
fi

# set libreoffice to not exist
LX=-2
# now check if it exists
if [ -e /usr/bin/libreoffice$glov2 ]; then
  LX=-1 # -1: does exist but may be older version
  a=`cat /opt/libreoffice$glov2/program/versionrc | grep 'buildid='` && a=${a##buildid=}
  if [ "$a" == "$LOCURRENT" ]; then 
    LX=0  # 0: does exist and is current version
    echo adding new LOlocale
  fi  
fi

# 1) download LO-basepack and langpack if needed
#=================================================
# delete old desktop getopenoffice file
for idx in $SYSUSERS; do /bin/rm -f /home/$idx/Desktop/getopenoffice.desktop; done
/bin/rm -f /root/Desktop/getopenoffice.desktop

dl_txt=$"Download speed:" && eta_txt=$"Estimated time:" && TITLE1=$TITLE": getting LO-base package..."
source=$httpsource$basepack && /bin/rm -fr $tmpdir && /bin/mkdir $tmpdir && cd $tmpdir && /bin/mkdir tmp
/bin/rm -f /tmp/LO_download

# LO does not exist yet, is outdated, or to be reinstalled
if [ $LX -lt 0 ] || [ $LOREINSTALL -eq 1 ];then 
  # 1) get the base pack
  #==============================
  #begin base-pack
  #=====================
  /bin/rm -f $basepack* /tmp/co_cancel; SCRIPT_PID=$$
  wget $source 2>&1 | tee /tmp/LO_download \
    | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
    | ( if `$ZEN3 --width 600 --progress --auto-close --title="$TITLE1"`; then
      echo 'Download completed'
        else
	  kill `/bin/ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
          $ZEN3 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
          echo "Downloading base-pack via wget failed " >> $lomil
          if [ "$wwwb" != "" ];then 
            /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
          fi
         touch /tmp/co_cancel
        fi )

    if [ -e /tmp/co_cancel ];then
      /bin/rm -fr $tmpdir /tmp/LO_download /tmp/co_cancel
      exit 1
    fi
    /bin/rm -f /tmp/co_cancel

   # quit if still not downloaded for whatever reason...
   if [ ! -e $basepack ];then
     $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
     echo "Downloading base-pack via wget failed " >> $lomil
     if [ "$wwwb" != "" ];then 
       /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
     fi
     cd && /bin/rm -fr $tmpdir /tmp/LO_download
     exit 1
   fi

  tar xfz $basepack; res=`echo $?`
  if [ $res -ne 0 ];then
    $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
    echo "Extracting base-pack failed " >> $lomil
    cd && /bin/rm -fr $tmpdir /tmp/LO_download
    exit 1
  fi
  xdir=`ls -d L*/` && cd $xdir/RPMS 
  /bin/mv *.rpm ../../tmp/
  cd $tmpdir && /bin/rm -fr $xdir 

  # end base-pack
  #====================
  # 2) get help-package
  #==============================
  helppackb=$helppackbase"en-US.tar.gz" && tt_help=1
  TITLE2=$TITLE": getting LO-help package..." && source=$httpsource$helppackb
  HTTPstat=`curl -I --stderr /dev/null $source | grep "Not Found" | cut -d' ' -f2`
  if [ "$HTTPstat" == "404" ]; then
    MSG=$"LibreOffice package not found.\nPlease update lomanager to the latest version\nand then run LibreOffice Manager again. \n\nExiting..."
    $ZEN2 --title "$TITLE" --error --text "$MSG"
    echo "basehelp-pack not found on LO-servers" >> $lomil
    cd && /bin/rm -fr $tmpdir
    if [ "$wwwb" != "" ];then 
      /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
    fi
    exit 0
  fi

  #=====================
  # begin base-helppack
  #=====================
  /bin/rm -f $helppackb* /tmp/co_cancel; SCRIPT_PID=$$
  wget $source 2>&1 | tee /tmp/LO_download \
    | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
    | ( if `$ZEN3 --width 600 --progress --title="$TITLE2" --auto-close`; then
	  echo 'Download completed'
        else
	  kill `/bin/ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
          $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
          echo "Downloading basehelp-pack via wget failed " >> $lomil
          if [ "$wwwb" != "" ];then 
            /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
          fi
         touch /tmp/co_cancel
        fi )

    if [ -e /tmp/co_cancel ];then
      /bin/rm -fr $tmpdir /tmp/LO_download /tmp/co_cancel
      exit 1
    fi
    /bin/rm -f /tmp/co_cancel


   # quit if still not downloaded for whatever reason...
   if [ ! -e $helppackb ];then
     $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
     echo "Downloading basehelp-pack via wget failed " >> $lomil
     if [ "$wwwb" != "" ];then 
       /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
     fi
     cd && /bin/rm -fr $tmpdir /tmp/LO_download
     exit 1
   fi

  # extract the basehelp-pack
  tar xfz $helppackb; res=`echo $?`
  if [ $res -ne 0 ];then
    $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
    echo "Extracting basehelp-pack failed " >> $lomil
    cd && /bin/rm -fr $tmpdir /tmp/LO_download
    exit 0
  fi
  xdir=`ls -d L*/` && cd $xdir/RPMS 
  /bin/mv *.rpm ../../tmp/
  cd $tmpdir && /bin/rm -fr $xdir 

# end base-helppack
#====================
fi

# get language + help package
#==================================
if [ "$tt" != "en-US" ];then
  langpack=$langpackbase$tt".tar.gz"
  TITLE2=$TITLE": getting LO-language package..." && source=$httpsource$langpack
  HTTPstat=`curl -I --stderr /dev/null $source | grep "Not Found" | cut -d' ' -f2`
  if [ "$HTTPstat" == "404" ]; then
    MSG=$"LibreOffice package not found.\nPlease update lomanager to the latest version\nand then run LibreOffice Manager again. \n\nExiting..."
    $ZEN2 --title "$TITLE" --error --text "$MSG"
    echo "lang-pack $tt not found on LO-servers" >> $lomil
    cd && /bin/rm -fr $tmpdir
    if [ "$wwwb" != "" ];then 
      /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
    fi
    exit 0
  fi

  # downloading langpack
   /bin/rm -f $langpack* /tmp/co_cancel; SCRIPT_PID=$$
    wget $source 2>&1 | tee /tmp/LO_download \
      | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
      | ( if `$ZEN3 --width 600 --progress --title="$TITLE2" --auto-close`; then
	  echo 'Download completed'
        else
	  kill `/bin/ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
          $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
          echo "Downloading lang-pack $tt via wget failed " >> $lomil
          if [ "$wwwb" != "" ];then 
            /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
          fi
         touch /tmp/co_cancel
        fi )

    if [ -e /tmp/co_cancel ];then
      /bin/rm -fr $tmpdir /tmp/LO_download /tmp/co_cancel
      exit 1
    fi
    /bin/rm -f /tmp/co_cancel


   # quit if still not downloaded for whatever reason...
   if [ ! -e $langpack ];then
     $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
     echo "Downloading lang-pack $tt via wget failed " >> $lomil
     if [ "$wwwb" != "" ];then 
       /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
     fi
     cd && /bin/rm -fr $tmpdir /tmp/LO_download
     exit 1
   fi

  # extract the lang-pack
  tar xfz $langpack; res=`echo $?`
  if [ $res -ne 0 ];then
    $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
    echo "Extracting lang-pack $tt failed " >> $lomil
    cd && /bin/rm -fr $tmpdir /tmp/LO_download
    exit 1
  fi
  xdir=`ls -d L*/` && cd $xdir/RPMS
  /bin/mv *.rpm ../../tmp/
  cd $tmpdir && /bin/rm -fr $xdir

  # end lang-pack
  #====================

  # only get help-package if it is available for the selected locale
  #=========================================
  # insert here from losort (4):
  HAS_HELP=(am ast bg bn-IN bn bo bs ca-valencia ca cs da de dz el en-GB en-ZA eo es et eu fi fr gl gu he hi hr hu id is it ja ka km ko mk nb ne nl nn om pl pt-BR pt ru si sk sl sq sv tg tr ug uk vi zh-CN zh-TW)
  c_help=${#HAS_HELP[@]}

  index=0 && tt_help=0
  while [ $index -lt $c_help ]; do
    if [ "$tt" == "${HAS_HELP[$index]}" ];then tt_help=1;fi
    let "index++"
  done

  if [ $tt_help -eq 1 ];then
    helppack=$helppackbase$tt".tar.gz"
    TITLE2=$TITLE": getting LO-help package..." && source=$httpsource$helppack
    HTTPstat=`curl -I --stderr /dev/null $source | grep "Not Found" | cut -d' ' -f2`
    if [ "$HTTPstat" == "404" ]; then
      MSG=$"LibreOffice package not found.\nPlease update lomanager to the latest version\nand then run LibreOffice Manager again. \n\nExiting..."
      $ZEN2 --title "$TITLE" --error --text "$MSG"
      echo "langhelp-pack $tt not found on LO-servers" >> $lomil
      cd && /bin/rm -fr $tmpdir
      if [ "$wwwb" != "" ];then 
        /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
      fi
      exit 1
    fi

    # downloading langhelp-pack
   /bin/rm -f $helppack* /tmp/co_cancel; SCRIPT_PID=$$
    wget $source 2>&1 | tee /tmp/LO_download \
      | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
      | ( if `$ZEN3 --width 600 --progress --title="$TITLE2" --auto-close`; then
	  echo 'Download completed'
        else
	  kill `/bin/ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
          $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
          echo "Downloading langhelp-pack $tt via wget failed " >> $lomil
          if [ "$wwwb" != "" ];then 
            /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
          fi
         touch /tmp/co_cancel
        fi )

    if [ -e /tmp/co_cancel ];then
      /bin/rm -fr $tmpdir /tmp/LO_download /tmp/co_cancel
      exit 1
    fi
    /bin/rm -f /tmp/co_cancel


   # quit if still not downloaded for whatever reason...
   if [ ! -e $helppack ];then
     $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled. Please use the offline-installer\ndescribed in Important Notes 1b in the lomanager-thread."
     echo "Downloading langhelp-pack $tt via wget failed " >> $lomil
     if [ "$wwwb" != "" ];then 
       /bin/su $louser -c "($wwwb https://www.pclinuxos.com/forum/index.php/topic,59009.0.html)"
     fi
     cd && /bin/rm -fr $tmpdir /tmp/LO_download
     exit 1
   fi

    # extract langhelp -pack
    tar xfz $helppack; res=`echo $?`
    if [ $res -ne 0 ];then
      $ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
      echo "Extracting langhelp-pack $tt failed " >> $lomil
      cd && /bin/rm -fr $tmpdir /tmp/LO_download
      exit 1
    fi
    xdir=`ls -d L*/` && cd $xdir/RPMS 
    /bin/mv *.rpm ../../tmp/
    cd $tmpdir && /bin/rm -fr $xdir 
  fi
fi

# test for and kill the LO-quickstarter !
pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null


# now we have everything to install the current LO-version 
# only at this stage we should remove any older LO or OO
#==============================================================

# 3) test for older versions to be removed
#================================================ 
# version 2.x (was on 2007 CD) 
set -- /usr/bin/ooffice2* && if [ -f "$1" ];then QQ=$#; else QQ=0;fi
if [ $QQ != "0" ]; then 
  $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
  dnf remove openoffice.org openoffice.org-mimelnk -y
  # get the installed OO-version
  XX=`ls /usr/bin/ooconfig*` && XX=${XX:17:3}
  for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo-2.0; done
  for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo-$XX; done
  /bin/rm -fr /root/.ooo-$XX && /bin/rm -fr /root/.ooo-2.0
  update-menus
fi

# version 3.0.0 (was on 2009.1 CD)
if [ -e /usr/bin/ooffice3.0 ]; then 
  $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
  dnf remove openoffice.org-core -y
  for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo3; done
  /bin/rm -fr /root/.ooo3 /opt/openoffice*
  psoo=`/bin/ps -ef|grep -i OpenOffice|awk '{print$2}'` && kill -9 $psoo &>/dev/null
  update-menus
fi

# version 3.0.1 and higher
if [ -e /usr/bin/openoffice.org3 ]; then
  psoo=`/bin/ps -ef|grep -i OpenOffice|awk '{print$2}'` && kill -9 $psoo &>/dev/null
  # get the installed OO-version
  a=`cat /opt/openoffice.org3/program/versionrc | grep 'BuildVersion=ooo-build '`
  a=${a##BuildVersion=ooo-build } && a=${a//./} && b=3214 
  if [ "$a" == "" ]; then a=3205; fi
  XX=`echo "a=$a;b=$b;r=-1;if(a==b)r=0;if(a>b)r=1;r"|bc`
  bv=`cat /opt/openoffice.org3/program/versionrc | grep 'OOOBaseVersion='`
  bv=${bv##OOOBaseVersion=} && if [ "$bv" == "" ]; then bv="3.1";fi
  # remove the older or current version completely
  $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing outdated OpenOffice. \nPlease be patient... :-)" &
  dnf remove openoffice.org-ure openoffice.org$bv-mandriva-menus -y
  for idx in $SYSUSERS; do /bin/rm -fr /home/$idx/.ooo3 /home/$idx/.config/ooo3 /home/$idx/Desktop/getopenoffice.desktop; done
  /bin/rm -fr /root/.ooo3 /root/.config/.ooo3 /opt/openoffice* /root/Desktop/getopenoffice.desktop
  update-menus
fi

# LibreOffice version 3.3
if [ -e /usr/bin/libreoffice ]; then
  # test for and kill LO-quickstarter
  pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null
  bv=`cat /opt/libreoffice/program/versionrc | grep 'OOOBaseVersion='`
  bv=${bv##OOOBaseVersion=} && if [ "$bv" == "" ]; then bv="3.3";fi 
  $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing LibreOffice. \nPlease be patient... :-)" &
  dnf remove libreoffice3-ure libreoffice$bv-mandriva-menus -y
  for idx in $SYSUSERS
    do 
    /bin/rm -fr /home/$idx/.libreoffice /home/$idx/.config/.libreoffice /home/$idx/Desktop/lomanager.desktop
    if [ -d /home/$idx/.kde4/vdt ]; then /bin/rm -f /home/$idx/.kde4/vdt/2/2a/LO*;fi
   done
  if [ -d /etc/skel_fm/.kde4/vdt ]; then /bin/rm -f /etc/skel_fm/.kde4/vdt/2/2a/LO*; fi
  /bin/rm -fr /root/.libreoffice /root/.config/.libreoffice /opt/libreoffice /root/Desktop/lomanager.desktop
  /bin/rm -f /usr/share/icons/libreoffice-* && update-menus
fi

# PV-update
# declare here all old versions but NOT the current one
declare -a LOOLDV=("3.4" "3.5" "3.6" "4.0" "4.1" "4.2" "4.3" "4.4" "5.0" "5.1" "5.2" "5.3" "5.4" "6.0" "6.1" "6.2" "6.3" "6.4" "7.0" "7.1" "7.2" "7.3" "7.4" "7.5" "7.6" "24.2" "24.8" "25.2" "25.8")
for idxx in "${LOOLDV[@]}"
do
  bv="$idxx" && loexe=/usr/bin/libreoffice$bv
  if [ -e $loexe ]; then
    # test for and kill LO-quickstarter
    pslo=`/bin/ps -ef|grep -i libreoffice|awk '{print$2}'` && kill -9 $pslo &>/dev/null
    # remove the older or current version completely
    $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing LibreOffice. \nPlease be patient... :-)" &
    if [ "$bv" == "3.4" ]
    then 
      dnf remove libreoffice$bv-ure libreoffice$bv-mandriva-menus -y
    elif [ "$bv" == "3.5" ] || [ "$bv" == "3.6" ] || [ "$bv" == "4.0" ]
    then 
      dnf remove libreoffice$bv-ure libreoffice$bv-stdlibs libreoffice$bv-mandriva-menus -y
    else
      dnf remove libreoffice$bv-ure libreoffice$bv-freedesktop-menus libobasis$bv-ooofonts -y
    fi      
    for idx in $SYSUSERS
      do 
      /bin/rm -fr /home/$idx/.libreoffice /home/$idx/Desktop/lomanager.desktop
      done
      /bin/rm -fr /root/.libreoffice /root/.config/.libreoffice /opt/libreoffice* /root/Desktop/lomanager.desktop 
      /bin/rm -f /usr/share/icons/libreoffice* && update-menus
   fi
done


# remove current version of LibreOffice completely
if [ $LX -eq -1 ] || [ $LOREINSTALL -eq 1 ]; then
  $ZEN2 --title="$TITLE" --info --timeout 20 --width=400 --text $"Removing LibreOffice. \nPlease be patient... :-)" &
  dnf remove libreoffice$glov2-ure libreoffice$glov2-freedesktop-menus libobasis$glov2-ooofonts -y
  # backup the old user folder which may contain special settings they want to keep
  for idx in $SYSUSERS
    do 
    if [ -d /home/$idx/.libreoffice ]; then
      /bin/mv -f /home/$idx/.libreoffice /home/$idx/.libreoffice_old &>/dev/null
    fi
    if [ -d /home/$idx/.config/libreoffice ]; then 
      /bin/mv -f /home/$idx/.config/libreoffice /home/$idx/.config/libreoffice_old &>/dev/null
    fi
  done
  /bin/rm -fr /root/.libreoffice /root/.config/libreoffice /opt/libreoffice* /root/Desktop/lomanager.desktop /etc/skel/.config/libreoffice
  /bin/rm -f /usr/share/icons/libreoffice* && update-menus
fi

# 4) finally install current LO
#==============================
cd $tmpdir && cd tmp 
/bin/rm -f /tmp/LO_*

MSG=$"Installing and post-installation checks will be finished once the message:\\n\\n                 'The new LibreOffice locale is now available'\\n\\nappears in a new window. Please wait for this window to appear."
$ZEN2 --title="$TITLE" --info --timeout 50 --text="$MSG" &
dnf install ./*.rpm -y

# post-install stuff
#============================

# check if clipart is installed and upgrade if outdated
#========================================================
cliparttest=`rpm -qa libreoffice-openclipart | awk -F '-' '{print$3}'`
if [ "$cliparttest" != "" -a "$cliparttest" != "$glov2" ];then 
  dnf install libreoffice-openclipart -y
fi

# LO-icons don't show up in LXDE, fix that
#============================================
/bin/cp -f /usr/share/icons/hicolor/32x32/apps/libreoffice* /usr/share/icons/
if [ -e /usr/bin/lxpanelctl ];then lxpanelctl restart;fi
xdg-desktop-menu forceupdate && update-menus -n

# disable automatic online update check
for idx in $SYSUSERS
  do 
  udir=/home/$idx/.config/libreoffice/4/user
  regfile=/home/$idx/.config/libreoffice/4/user/registrymodifications.xcu
  if [ -e $regfile ]; then
    pushd $udir
    onlinechecker=$(cat registrymodifications.xcu|grep AutoCheckEnabled | grep -c "<value>true</value>")
    if [ $onlinechecker -eq 1 ]; then 
      # get line
      ll=$(cat registrymodifications.xcu|grep -n AutoCheckEnabled |awk -F':' '{printf$1}')
      sed -i "${ll}s/true/false/" registrymodifications.xcu
    else
      ## entry does not exist, add the appropriate line before the end of the file
      # delete last line
      sed -i '$d' registrymodifications.xcu
      echo \<item oor:path=\"/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job[\'UpdateCheck\']/Arguments\"\>\<prop oor:name=\"AutoCheckEnabled\" oor:op=\"fuse\" oor:type=\"xs:boolean\"\>\<value\>false\</value\>\</prop\>\</item\> >> registrymodifications.xcu
      # add back last line
      echo \</oor:items\> >> registrymodifications.xcu        
    fi    
    popd
  else
    # LO never started before, fake one
    mkdir -p $udir
    echo \<?xml version=\"1.0\" encoding=\"UTF-8\"?\>  >> $regfile 
    echo \<oor:items xmlns:oor=\"https://openoffice.org/2001/registry\" xmlns:xs=\"https://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"https://www.w3.org/2001/XMLSchema-instance\"\>  >> $regfile 
    echo \<item oor:path=\"/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job[\'UpdateCheck\']/Arguments\"\>\<prop oor:name=\"AutoCheckEnabled\" oor:op=\"fuse\" oor:type=\"xs:boolean\"\>\<value\>false\</value\>\</prop\>\</item\> >> $regfile
    echo \</oor:items\> >> $regfile        
    chown -R $idx:`id -gn $idx` /home/$idx/.config/libreoffice
  fi
done

# check in skel
regfile=/etc/skel/.config/libreoffice/4/user/registrymodifications.xcu
if [ ! -e $regfile ]; then
  mkdir -p /etc/skel/.config/libreoffice/4/user
  echo \<?xml version=\"1.0\" encoding=\"UTF-8\"?\>  >> $regfile 
  echo \<oor:items xmlns:oor=\"https://openoffice.org/2001/registry\" xmlns:xs=\"https://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"https://www.w3.org/2001/XMLSchema-instance\"\>  >> $regfile 
  echo \<item oor:path=\"/org.openoffice.Office.Jobs/Jobs/org.openoffice.Office.Jobs:Job[\'UpdateCheck\']/Arguments\"\>\<prop oor:name=\"AutoCheckEnabled\" oor:op=\"fuse\" oor:type=\"xs:boolean\"\>\<value\>false\</value\>\</prop\>\</item\> >> $regfile
  echo \</oor:items\> >> $regfile     
fi

# fix starting docs from smb-drive (seems to be resolved with LO > 5.4.3 ??
#sed -i 's/^X-GIO-NoFuse=true/#X-GIO-NoFuse=true/' /opt/libreoffice*/share/xdg/*.desktop

cd && /bin/rm -fr $tmpdir /tmp/LO_* /tmp/td* /tmp/*.mirrorlist*
for idx in $SYSUSERS
  do 
  # delete core-files if they were generated
  find /home/$idx -maxdepth 1 -type f \( ! -iname ".*" \) -name "core.[:0-9:]*" -exec rm {} \;
done

#clean menu entries
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/base.desktop >/dev/null 2>&1
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/calc.desktop >/dev/null 2>&1
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/draw.desktop >/dev/null 2>&1
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/impress.desktop >/dev/null 2>&1
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/math.desktop >/dev/null 2>&1
sed -i '/Categories=Office;*/c\Categories=Office;' /opt/libreoffice*/share/xdg/writer.desktop >/dev/null 2>&1
xdg-desktop-menu forceupdate --mode system

# the end :-)
MSG=$"The new LibreOffice locale is now available\nfrom the submenus under PCmenu -> Office.\n\nNote: to select any added locale in LibreOffice go to:\nTools -> Options -> Language Settings\n         -> Languages: User Interface\nThen restart LibreOffice to apply the new locale.\n\nHave fun\!"
$ZEN2 --title="$TITLE" --info --text="$MSG"
exit 0
