This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathConfigureOnce.ps1
74 lines (67 loc) · 2.94 KB
/
ConfigureOnce.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function Initialize {
Get-Content -Path 'configexample.yml' -Encoding UTF8 | Out-String | Set-Variable 'config'
Write-Host '[Info] ' -ForegroundColor Cyan -NoNewline
Write-Host '请输入需要自动打卡的信息化门户账号:'
Read-Host | Set-Variable id
Write-Host '[Info] ' -ForegroundColor Cyan -NoNewline
Write-Host '请输入密码:'
Read-Host -AsSecureString | Set-Variable pass
$pass = [System.Net.NetworkCredential]::new('', $pass).Password # this looks stupid :(
$config -creplace '"\{STUID\}"', "`"$id`"" -creplace '"\{PSWD\}"', "`"$pass`"" | `
Out-File -FilePath 'config.yml' -Encoding UTF8 -Force
Write-Host '[Info] ' -ForegroundColor Cyan -NoNewline
Write-Host '已将配置写入config.yml文件.'
Pause
}
####
# Start from here:
####
$step = 1
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "检查Python环境..." -ForegroundColor White
$step++
$justInstalled=0
Invoke-Expression 'python -V' | Set-Variable v
if (-not ($v -match '3\.\w\.\w')) {
Write-Error "未正确配置Python环境."
try {
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "正在尝试安装Python环境, 这取决于目前网络环境速度. (Source: npm.taobao.org 淘宝镜像源)"
$step++
if(!(Test-Path 'python-installer.exe')) {
Invoke-WebRequest -Uri 'http://npm.taobao.org/mirrors/python/3.7.8/python-3.7.8-amd64.exe' -OutFile 'python-installer.exe'
}
pwd | set "cwd"
.\python-installer.exe /quiet PrependPath=1 Include_test=0 `
TargetDir="$cwd\python3" Shortcuts=0 Include_doc=0 Include_dev=0 Include_launcher=0
$justInstalled = 1
while (!(Test-Path "$cwd\python3\Scripts\pip.exe")) {
Start-Sleep -Seconds 1
}
Start-Sleep -Seconds 3
}
catch { Write-Host $error[0]; break }
}
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "正在检查pip指令是否可用."
$step++
Invoke-Expression 'pip -V' | Set-Variable pv
if ($pv -match '^pip\s\w{2}\.\w\.\w') {
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "正在安装运行所需的Python Package."
$step++
iex 'pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt'
}
elseif($justInstalled -eq 1) {
iex "$cwd\python3\Scripts\pip.exe install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt"
}
else {
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "正在安装运行所需的Python Package."
$step++
@(iex 'cmd /U/C where python')[0].ToString().Replace('python.exe', 'Scripts') | set ppath
iex "$ppath\pip.exe install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt"
}
Write-Host "[Step $step] " -ForegroundColor Red -NoNewLine
Write-Host "记录账号信息(信息仅在本地存储)"
Initialize # this performs the function defined most above.