#软件安装目录
$dir="C:\Program Files\"
#安装文件夹
$soft_mulu="ln"
#软件绝对目录
$soft=$dir+$soft_mulu
$softpack="bacon"
$conf="C:\Program Files\ln\bacon\conf.ini"
cd C:\Users\Administrator\Desktop\windows
# 编辑配置文件的
Function edit_conf () {
echo "[server]
url = ${url}
uuid =
[kafka]
host = ${db}:9200
user = ln
password = LnUning37!" >conf.ini
# 修改配置文件并重启
if (test-path $conf) {
echo "[server]
url = ${url}
uuid =
[kafka]
host = ${db}:9200
user = ln
password = LnUning37!" > $conf
}
stop-service bacon 2>&1 |out-null
#echo "正在重启服务"
start-sleep 5
start-service bacon 2>&1|out-null
#echo "服务重启完成"
}
# 拷贝目录和安装
function cp_soft($soft_dir) {
# 判断原软件包是否存在!
#类似 out-null linux /dev/null
echo ${soft}
if (test-path $soft) {
echo "停止服务“
stop-service bacon 2>&1 |out-null
# 这里必须要等待10s,否则软件无法删除
start-sleep 10
#sc delete bacon
echo " 原软件未删除,删除中!"
rm -force -recurse ${soft}
echo " 删除完成!"
}
# 创建软件目录
mkdir -force $soft 2>&1 |out-null
# 拷贝软件包
cp -Recurse ${soft_dir} ${soft}
echo "软件包已复制"
cd ${soft}
cd $softpack
#安装服务,并设置自启动
./run.exe --startup auto install
echo "准备启动"
start-service bacon
echo "软件已启动"
}
# 安装引导
Function install() {
echo ""
echo " 1. windows server 2008"
echo " 2. windows server 2012-2019"
echo " 3. windows server 2008 Enterprise Edition"
echo ""
$version=read-host " 请根据windows系统版本选择编号"
if ($version -eq 1) {
$soft_dir="ln-2008/bacon"
cp_soft $soft_dir
}
elseif ($version -eq 2) {
echo "版本2"
$soft_dir="ln-2012-2019/bacon"
cp_soft $soft_dir
}
elseif ($version -eq 3) {
$soft_dir="ln-win_2008_enterprise_Edition"
cp_soft $soft_dir
}
}