#!/bin/bash

if [ $# -ne 1 ]; then
    echo "inst.sh package"
    exit 0
fi

package=$1
date_dir=$(basename $(echo ${package} | awk -F. '{print $1}'))
prefix=/root/

tar -zxvf ${package}
if [ -d ${prefix}wiwo/libs/${date_dir}/ ]; then
	install ${prefix}wiwo/libs/${date_dir}/* /root/wiwo/libs/
fi
if [ -d ${prefix}wiwo/bin/${date_dir}/ ]; then
	install ${prefix}wiwo/bin/${date_dir}/* /root/wiwo/bin/
fi
if [ -d ${prefix}udatabase/${date_dir}/ ]; then
	install ${prefix}udatabase/${date_dir}/* /root/udatabase/
fi
if [ -d ${prefix}umcheck/${date_dir}/ ]; then
	install ${prefix}umcheck/${date_dir}/* /root/umcheck/
fi

for file in `ls ${prefix}wiwo/libs/${date_dir}`
do
    link_name=`echo $file | awk -F'.' '{printf "%s.%s\n",$1,$2}'`
    target_name=$file
    cd /root/wiwo/libs/;mv $link_name $link_name.old;ln -s ${target_name} ${link_name};cd -
done

#clean
`rm -rf ${prefix}wiwo/libs/${date_dir}`
`rm -f  ${package}`

ldconfig
