#!/bin/sh
# ----------------------------------------------------------------------------
# /tmp/postinstall-eisman.sh - eisman installation
#
# Creation   :  2013-01-16 dv
# Last update:  $Id: install.sh 41956 2016-06-18 20:33:29Z hbfl $
#
# Copyright (c) 2013-2016 the eisfair team, team(at)eisfair(dot)org
#
# 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.
# ----------------------------------------------------------------------------

# set package name
package_name=eisman

# ---------------------------------------------------------------------------
# update-2.7.5
# ---------------------------------------------------------------------------
update_2_7_5()
{
    # check for correct eisfair system
    if [ -z "${EISFAIR_SYSTEM}" ]
    then
        # get eisfair system-type
        . /var/install/include/check-eisfair-version
    fi

    # write eisfair system type to include file
    echo "EISMAN_SYSTEM=\"${EISFAIR_SYSTEM}\"" >> \
        /var/install/include/eismanlib

    # call eisman init to check the dabase
    eisman init

    # -----------------------------------------------------------------------
    # extract eisman_info (tarball, if required)
    # -----------------------------------------------------------------------
  
    tar_file=$(ls /tmp/${package_name}_info.tar.*)

    if [ ! -d /var/lib/eisman/info ]
    then
        if tar --help | grep -q 'no-overwrite-dir'
        then
            taroption1='--no-overwrite-dir'
        else
            taroption1=''
        fi

        if tar --help | grep -q 'keep-directory-symlink'
        then
            taroption2='--keep-directory-symlink'
        else
            taroption2=''
        fi

        cd /
        tar ${taroption1} ${taroption2} -xf ${tar_file}  2>/tmp/install.log

        if [ ! -s /tmp/install.log ]
        then
            rm -f /tmp/install.log
        fi
    fi

    rm -f ${tar_file}
    rm -rf /var/lib/eisman/backup
    echo 'DateTime' >/run/eisman-installed
    rm -f /var/install/deinstall/eisman
    rm -f /var/install/packages/eisman
}

# ---------------------------------------------------------------------------
# main
# ---------------------------------------------------------------------------

base_version=$(sed -e 's/[svn|cvs].*$//; s/\./_/g' /etc/version)

update_${base_version}

# remove filelist
rm -f /etc/filelist.d/${package_name}-files.txt

exit 0
# ----------------------------------------------------------------------------
# End
# ----------------------------------------------------------------------------

