#!/bin/bash
#登录账号
user=`whoami`
#运行环境
env="debug";
if [[ $user = "root" ]]; then
echo $user;
env="release";
fi
echo "运行环境:${env}";
#安全验证操作
if [[ $env != "debug" ]]; then
read -t 20 -s -n 4 -p "请在20秒内输入操作密码:" pwd
if [[ $pwd != 1234 ]]; then
echo -e "\n"
echo "密码错误无法使用"
exit
fi
#statements
fi
root_dir="/root/";
#管理端代码目录
web_dir="${root_dir}nginx/html/test/";
echo "开始更新前端代码"
echo "$web_dir"
if [[ -f "${web_dir}dist.zip" ]]; then
echo "存在新资源包,尝试解压更新"
if [[ -f "${web_dir}web_admin.zip" ]]; then
echo "存在旧web_admin.zip文件,删除web_admin.zip"
rm -f "${web_dir}web_admin.zip"
fi
mv "${web_dir}dist.zip" "${web_dir}web_admin.zip"
fi
if [[ -f "${web_dir}web_admin.zip" ]]; then
echo "尝试解压web_admin.zip更新"
echo "删除现有目录:static"
rm -rf "${web_dir}static/"
echo "开始解压web_admin.zip"
unzip -q -o "${web_dir}web_admin.zip" -d "${web_dir}"
echo "解压完成"
else
echo "待更新资源包不存在,不能更新"
fi