upgrade 1.1
This commit is contained in:
155
bin/apps.json
Normal file
155
bin/apps.json
Normal file
@@ -0,0 +1,155 @@
|
||||
[
|
||||
{
|
||||
"Name": "7-Zip",
|
||||
"Id": "7zip.7zip",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "Command",
|
||||
"Command": "del /f /q \"C:\\Program Files\\7-Zip\\7-zip.chm\"",
|
||||
"Description": "Remove 7-zip.chm file"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Google Chrome",
|
||||
"Id": "Google.Chrome",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "RegImport",
|
||||
"Path": "./config/chrome.reg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "OpenOffice",
|
||||
"Id": "Apache.OpenOffice",
|
||||
"Version": "4.116.9816",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "Command",
|
||||
"Command": "\"C:\\Program Files (x86)\\OpenOffice 4\\program\\soffice.exe\" -headless -nologo -nodefault",
|
||||
"Description": "Run software once to generate the configuration files"
|
||||
},
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/openoffice/registrymodifications.xcu",
|
||||
"Destination": "$env:APPDATA\\OpenOffice\\4\\user\\registrymodifications.xcu"
|
||||
},
|
||||
{
|
||||
"Type": "Command",
|
||||
"Command": "echo y | \"C:\\Program Files (x86)\\OpenOffice 4\\program\\unopkg.com\" add --shared -s \"$PSScriptRoot\\assets\\openoffice\\historymanager2.1.oxt\"",
|
||||
"Description": "Install history extension"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Microsoft Teams",
|
||||
"Id": "Microsoft.Teams",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": []
|
||||
},
|
||||
{
|
||||
"Name": "KeePassXC",
|
||||
"Id": "KeePassXCTeam.KeePassXC",
|
||||
"Version": "2.6.6",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/keepassxc/keepassxc.ini",
|
||||
"Destination": "$env:APPDATA\\KeePassXC\\keepassxc.ini"
|
||||
},
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/keepassxc/KeePassXC.lnk",
|
||||
"Destination": "$HOME\\Desktop\\KeePassXC.lnk"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "VeraCrypt",
|
||||
"Id": "IDRIX.VeraCrypt",
|
||||
"Version": "1.26.20",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/veracrypt/Configuration.xml",
|
||||
"Destination": "$env:APPDATA\\VeraCrypt\\Configuration.xml"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "File Shredder",
|
||||
"Id": "PowTools.FileShredder",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "RegImport",
|
||||
"Path": "./config/fileshredder.reg"
|
||||
},
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/fileshredder/File Shredder.lnk",
|
||||
"Destination": "$HOME\\Desktop\\File Shredder.lnk"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "VLC",
|
||||
"Id": "VideoLAN.VLC",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/vlc/vlcrc",
|
||||
"Destination": "$env:APPDATA\\vlc\\vlcrc"
|
||||
},
|
||||
{
|
||||
"Type": "RegImport",
|
||||
"Path": "./config/vlc.reg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "Adobe Acrobat Reader",
|
||||
"Id": "Adobe.Acrobat.Reader.64-bit",
|
||||
"Version": "",
|
||||
"Enabled": 0,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "RegImport",
|
||||
"Path": "./config/adobe_acrobat.reg"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Name": "System Optimize",
|
||||
"Id": "System.Config",
|
||||
"Version": "",
|
||||
"Enabled": 1,
|
||||
"PostInstall": [
|
||||
{
|
||||
"Type": "RegImport",
|
||||
"Path": "./config/sys_optimize.reg"
|
||||
},
|
||||
{
|
||||
"Type": "FileCopy",
|
||||
"Source": "./assets/hosts",
|
||||
"Destination": "$env:SystemRoot\\System32\\drivers\\etc\\hosts"
|
||||
},
|
||||
{
|
||||
"Type": "Command",
|
||||
"Command": "\"$PSScriptRoot\\config\\sys_config.bat\""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
129
bin/main.ps1
Normal file
129
bin/main.ps1
Normal file
@@ -0,0 +1,129 @@
|
||||
# 设置严格模式,遇到错误停止,防止错误的命令雪崩
|
||||
$ErrorActionPreference = "Stop"
|
||||
#Set-StrictMode -Version Latest
|
||||
|
||||
# === 1. 加载依赖库 ===
|
||||
# 确保 lib 目录存在
|
||||
if (-not (Test-Path "$PSScriptRoot\..\lib")) {
|
||||
Write-Error "Cannot find .\lib, some files missing."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# === 2. 读取配置 ===
|
||||
$jsonPath = "$PSScriptRoot\apps.json"
|
||||
if (-not (Test-Path $jsonPath)) {
|
||||
Write-Error "Cannot find: $jsonPath"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "Reading configurations..." -ForegroundColor Cyan
|
||||
# 使用 UTF8 读取防止中文乱码
|
||||
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
||||
|
||||
# === 3. 主循环 ===
|
||||
foreach ($app in $apps) {
|
||||
if ($app.Enabled -ne 1) {
|
||||
Write-Host "[Skipping] $($app.Name)" -ForegroundColor DarkGray
|
||||
continue # 立即结束本次循环,进入下一个软件
|
||||
}
|
||||
|
||||
Write-Host "`n==========================================" -ForegroundColor Cyan
|
||||
Write-Host "Installing: $($app.Name)" -ForegroundColor Yellow
|
||||
Write-Host "=========================================="
|
||||
|
||||
if ($app.Id -eq "System.Config") {
|
||||
# 如果是纯配置项,直接打印跳过信息
|
||||
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
|
||||
} else {
|
||||
# --- 步骤 A: Winget 安装 ---
|
||||
$wingetArgs = @(
|
||||
"install",
|
||||
"--id", $app.Id,
|
||||
"-e",
|
||||
"--silent",
|
||||
"--accept-package-agreements",
|
||||
"--accept-source-agreements",
|
||||
"--disable-interactivity"
|
||||
# "--scope", "machine"
|
||||
)
|
||||
|
||||
# [版本检查逻辑]
|
||||
# 检查 Version 是否存在且不为空字符串
|
||||
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
|
||||
Write-Host "-> Version: $($app.Version)"
|
||||
$wingetArgs += "-v"
|
||||
$wingetArgs += $app.Version
|
||||
} else {
|
||||
Write-Host "-> Version: latest"
|
||||
}
|
||||
|
||||
Write-Host "-> Installing via winget..."
|
||||
|
||||
# 执行安装
|
||||
$proc = Start-Process -FilePath "winget" -ArgumentList $wingetArgs -Wait -PassThru -NoNewWindow
|
||||
|
||||
# 检查安装结果 (0=成功, -1978335189=已安装)
|
||||
if ($proc.ExitCode -eq 0) {
|
||||
Write-Host "[Success]" -ForegroundColor Green
|
||||
} elseif ($proc.ExitCode -eq -1978335189) {
|
||||
Write-Host "[Skip] Already installed" -ForegroundColor Yellow
|
||||
continue # 已经安装的为了避免覆盖配置,也就不配置了
|
||||
} else {
|
||||
Write-Error "[Fail] Error code: $($proc.ExitCode)"
|
||||
continue # 安装失败则跳过后续配置
|
||||
}
|
||||
}
|
||||
|
||||
# --- 步骤 B: PostInstall 配置 ---
|
||||
if ($app.PostInstall -and $app.PostInstall.Count -gt 0) {
|
||||
Write-Host "`n-> Configuring..." -ForegroundColor Cyan
|
||||
|
||||
$stepIndex = 0
|
||||
foreach ($action in $app.PostInstall) {
|
||||
|
||||
# [间隔逻辑] 如果这不是第一步,先等待 2 秒
|
||||
if ($stepIndex -gt 0) {
|
||||
Write-Host "(Waiting 2 seconds...)" -ForegroundColor DarkGray
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($action.Type) {
|
||||
|
||||
# 1. 复制文件
|
||||
"FileCopy" {
|
||||
& "$PSScriptRoot\..\lib\invoke-filecopy.ps1" `
|
||||
-Source $action.Source `
|
||||
-Destination $action.Destination
|
||||
}
|
||||
|
||||
# 2. 导入注册表
|
||||
"RegImport" {
|
||||
& "$PSScriptRoot\..\lib\invoke-regimport.ps1" `
|
||||
-Path $action.Path
|
||||
}
|
||||
|
||||
# 3. 执行 CMD
|
||||
"Command" {
|
||||
& "$PSScriptRoot\..\lib\invoke-cmdexec.ps1" `
|
||||
-Command $action.Command `
|
||||
-WorkDir $action.WorkDir
|
||||
}
|
||||
|
||||
Default {
|
||||
Write-Warning "`nUnknown action: $($action.Type)"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Error "`nFailed to operate step $($stepIndex + 1): $_"
|
||||
}
|
||||
|
||||
$stepIndex++
|
||||
}
|
||||
} else {
|
||||
Write-Host "-> No configurations." -ForegroundColor DarkGray
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`n=== Done. Need restart ===" -ForegroundColor Green
|
||||
Pause
|
||||
Reference in New Issue
Block a user