######################################################################
####function:install appstore
####author:lance_cao
####create date:2019-11
####modify date:2019-11
######################################################################

#!/bin/bash
set -e
echo "[`date +'%F %H:%M:%S'`] [INFO] useage :  sh installappstore.sh sharepath sys_user"
if [ $# -ne 2 ]; then
        echo "$(basename $0): Missing script argument"
        echo "$(basename $0) [sharepath] [sys_user]"
        exit 1
fi

## ENV ##
pd=$PWD
vsharepath=$1
sys_user=$2
isSharepath=1
if [ -z "$vsharepath" ];then
    isSharepath=0
    vsharepath=$pd
fi
mkdir -p $vsharepath/appstatic

## tar appstatic.tar.gz ##
if [ -f "$pd/appstatic.tar.gz" ];then
    if [ $isSharepath -eq "1" ];then
       cp appstatic.tar.gz $vsharepath
    fi
    cd $vsharepath
    tar -zxvf appstatic.tar.gz
#    unzip -o appstatic.tar.gz
fi

#create link
cd $vsharepath/appstatic
pd=$PWD
if [ ! -L /var/appstatic ];then
  ln -s $pd /var/appstatic
fi
chown -R $sys_user. $vsharepath/appstatic
echo "appstore install success "
