Skip to content

Commit b3284da

Browse files
committed
优化linux 安装脚本
1 parent 5b371fb commit b3284da

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

install.ps1

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ Write-Output "Latest version: $tag"
1818

1919
# download
2020
Write-Output "Downloading..."
21+
$tempPath = Get-Random -Maximum 500
22+
$tempPath = "$env:TEMP\cg-$tempPath"
23+
if ( Test-Path $tempPath ) {
24+
rm $tempPath\*
25+
} else {
26+
mkdir -p $tempPath
27+
}
2128
function download_file($name, $path) {
2229
Write-Output "Download file $path "
23-
if ( Test-Path "$env:TEMP\$name" ) {
24-
del "$env:TEMP\$name"
25-
}
26-
27-
Invoke-WebRequest $path -Out "$env:TEMP\$name"
30+
Invoke-WebRequest $path -Out "$tempPath\$name"
2831
}
2932
download_file cg "$rawPath/$tag/cg"
3033
download_file cg.bat "$rawPath/$tag/cg.bat"
@@ -33,14 +36,14 @@ Write-Output "Download success."
3336

3437
# move file
3538
$cgPath = "$env:APPDATA\cg\bin"
36-
$existDir = Test-Path $cgPath
37-
if ($existDir -eq $False) {
39+
if (Test-Path $cgPath) {
40+
rm $cgPath\*
41+
} else {
3842
mkdir -p $cgPath
3943
}
4044

41-
mv "$env:TEMP\cg" $cgPath
42-
mv "$env:TEMP\cg.bat" $cgPath
43-
mv "$env:TEMP\cg.jar" $cgPath
45+
mv "$tempPath\*" $cgPath
46+
rm $tempPath
4447

4548
# set environment
4649
Write-Output "setting environment."
@@ -54,4 +57,3 @@ if (! $alreadyAdded) {
5457
}
5558

5659
Write-Output "Install success!"
57-
cg -v

install.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ echo "Download success."
2828
# move file
2929
cgDir=$HOME/.cg/bin
3030
mkdir -p $cgDir
31+
mv /tmp/cg.jar $cgDir/
3132

3233
chmod +x /tmp/cg
33-
mv /tmp/cg /usr/bin/
34-
mv /tmp/cg.jar $cgDir/
34+
sudo mv /tmp/cg /usr/bin/
3535

3636
echo "Install success!"
37-
cg -v

0 commit comments

Comments
 (0)