forked from chocolatey-community/chocolatey-oneget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-provider.ps1
69 lines (51 loc) · 2.34 KB
/
install-provider.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
# by default it will find the newest $providerName.dll and copy it to the right location
# (change the default value of $providerName when you change your provider name )
# otherwise you can say 'debug' or 'release' for the $build
Param( [string]$build = '', [string]$providerName = 'ChocolateyProvider' )
$orig = (pwd)
cd $PSScriptRoot
function CopyHarder {
param( [string]$srcPath, [string]$output )
if( test-path $output ) {
write-host -fore white "Deleting old file from `n '$output' `n"
# delete the old provider assembly
# even if it's in use.
$tmpName = "$filename.delete-me.$(get-random)"
$tmpPath = "$env:localappdata\oneget\providerassemblies\$tmpName"
ren $output $tmpName -force -ea SilentlyContinue
erase -force -ea SilentlyContinue $tmpPath
if( test-path $tmpPath ) {
#locked. Move to temp folder
write-host -fore yellow "Old provider is in use, moving to `n '$env:TEMP' folder `n"
move $tmpPath $env:TEMP
write-host -fore yellow "Moved old provider out of the way, you must restart any processes using the it. `n"
}
if( test-path $output ) {
write-host -fore red "Can't remove existing file: `n $output `n"
cd $orig
return
}
}
write-host -fore green "copying provider assembly `n '$srcpath' `n=> '$output' `n"
copy -force $srcPath $output
}
$candidates = dir -recurse "output\$providerName.dll" | sort -Descending -Property LastWriteTime
if( $build ) {
$candidates = dir -recurse "output\$providerName.dll" | sort -Descending -Property LastWriteTime | ?{ $_ -match $build }
} else {
$candidates = dir -recurse "output\$providerName.dll" | sort -Descending -Property LastWriteTime
}
$provider = $candidates | select -first 1
if( -not $provider ) {
write-host -fore red "Can't find matching provider '$providerName.dll' in output folder with '$build' somewhere in the path`n"
cd $orig
return
}
$srcpath = $provider.Fullname
$filename = $provider.Name
$srcdir = $provider.Directory
foreach( $dll in (dir $srcdir\*.dll) ) {
$output = "$env:localappdata\oneget\providerassemblies\$($dll.Name)"
CopyHarder $dll.FullName $output
}
cd $orig