#!/bin/sh

# Package
PACKAGE="mc"
DNAME="Midnight Commander"

# Find the CPU architecture
synoinfo=`get_key_value /etc.defaults/synoinfo.conf unique`
arch=`echo $synoinfo | cut -d_ -f2`
[ $arch = 88f6282 ] && arch=88f6281
[ $arch = cedarview ] && arch=x86
[ $arch = bromolow ] && arch=x86

# Others
INSTALL_DIR="/usr/local/${PACKAGE}"
PATH="${INSTALL_DIR}/bin:/usr/local/bin:/bin:/usr/bin:/usr/syno/bin"


preinst ()
{
    # Check if the architecture is supported
    case $arch in
        88f6281|x86)
            true
            ;;
        *)
            cat << EOM
Your architecture is not supported by this package, sorry.
Architecture  : $arch
Synology info : $synoinfo
EOM
        exit 1
            ;;
    esac
    exit 0
}

postinst ()
{
    # Link
    ln -s ${SYNOPKG_PKGDEST} ${INSTALL_DIR}
    
    # Put mc in the PATH
    mkdir -p /usr/local/bin
    mkdir -p /usr/lib/locale
    cp -fR ${INSTALL_DIR}/install/$arch/* ${INSTALL_DIR}
    cp -fR ${INSTALL_DIR}/install/usr/* /usr
    /usr/bin/localedef -c -f UTF-8 -i ru_RU ru_RU.UTF-8

    exit 0
}

preuninst ()
{
    exit 0
}

postuninst ()
{
    # Remove link
    rm -f ${INSTALL_DIR}
    rm -f /usr/local/bin/mc

    exit 0
}

preupgrade ()
{
    exit 0
}

postupgrade ()
{
    exit 0
}
