######################################################################
####function: install fileserver
####author:danial_chen
####create date:2020-03
####modify date:2020-03
######################################################################

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

pd=$PWD
## update config ##
clustername=$1

#update setappenv
sed -i s/clustername/$clustername/g $pd/fileserver/fileserver.yaml
sed -i s/clustername/$clustername/g $pd/fileserver/fileserver-svc.yaml

#create namespaces
ns=`kubectl get ns |grep $clustername |wc -l`
if [ $ns -eq 0 ];then
    kubectl create ns $clustername
fi

#create fileserver service
cd $pd/fileserver
file=`kubectl get deploy -n $clustername |grep fileserver |wc -l`
if [ $file -ne 0 ];then
    kubectl delete -f .
fi
kubectl create -f .

echo "fileserver install success!"
