# Tanım: Tam özellikli çapraz platform ofis paketi (ikili)
# URL: http://www.libreoffice.org
# Paketçi: milisarge
# Gerekler: cups xorg-libxaw xorg-libxcursor xorg-libxft xorg-libxinerama xorg-libxi xorg-libxrandr dbus-glib krb5
# Grup: ofis

isim=libreoffice-bin
isimp=libreoffice
surum=6.0.0
devir=1
kaynak=(http://tdf.c3sl.ufpr.br/libreoffice/stable/6.0.0/rpm/x86_64/LibreOffice_6.0.0_Linux_x86-64_rpm.tar.gz)


derle() {
    local workd="$SRC/tmp_work"
    mkdir $workd

    cd LibreOffice_${surum}*/RPMS
    for rpm in *.rpm; do
        bsdtar -p -o -C $workd -xf $rpm
    done

    bsdtar -p -o -C $workd -xf \
        $isimp${surum%.*}*.noarch.rpm

    cd $workd
    mkdir -p $PKG/usr/lib/$isimp
    mv opt/$isimp*/* $PKG/usr/lib/$isimp

    cd $PKG/usr/lib/$isimp
    ln -sf basis${surum%.*} basis-link

    mkdir -p $PKG/usr/bin
    local programs=(sbase scalc sdraw simpress smath soffice spadmin swriter)
    for program in ${programs[@]}; do
        ln -sf /usr/lib/$isimp/program/$program $PKG/usr/bin/$program
    done

    mkdir -p $PKG/usr/share/applications
    cd $PKG/usr/lib/$isimp/share/xdg/

    for desktop in *.desktop; do
       sed -i '/^Exec=/s/libreoffice[^ ]*/soffice/' $desktop
       ln -sf /usr/lib/$isimp/share/xdg/$desktop $PKG/usr/share/applications/$desktop 
    done

    mv $workd/usr/share/{mime,icons} $PKG/usr/share

    find $PKG \(\
        -inamep '*readme*' -o \
        -inamep '*changelog*' -o \
        -namep '*TODO*' -o \
        -inamep '*news*' -o \
        -inamep '*license*' -o \
        -inamep '*credits*' \
     \) -exec rm -rf '{}' \; || true
}
