@@ -7,19 +7,73 @@ Function Add-OciDB {
77 param (
88 )
99 begin {
10+ $installDir = ' C:\oracle\product\21c'
11+ $setupDir = ' C:\tools\oracle-setup'
12+ $workingDir = ' C:\tools\oracle'
13+
14+ $dbPassword = ' oracle'
15+ $dbPort = ' 1521'
16+ $dbEmExpressPort = ' 5550'
17+ $dbCharset = ' AL32UTF8'
18+ $dbDomain = ' localdomain'
19+
20+ $dbZipFile = ' OracleXE213_Win64.zip'
21+ $dbUrl = ' https://download.oracle.com/otn-pub/otn_software/db-express/OracleXE213_Win64.zip'
1022 }
1123 process {
12- $dbUrl = ' https://download.oracle.com/otn-pub/otn_software/db-express/OracleXE213_Win64.zip'
13- $dbZipFile = ' OracleXE213_Win64.zip'
24+ Add-Type - Assembly " System.IO.Compression.Filesystem"
25+ @ (
26+ $workingDir ,
27+ $setupDir ,
28+ " $setupDir \temp" ,
29+ $installDir
30+ ) | ForEach-Object {
31+ New-Item - ItemType Directory - Path $_ - Force | Out-Null
32+ }
33+
1434 Get-File - Url $dbUrl - OutFile $dbZipFile
15- New-Item - ItemType Directory - Path C:\tools\oracle- setup - Force | Out-Null
16- New-Item - ItemType Directory - Path C:\tools\oracle - Force | Out-Null
17- Expand-Archive - Path $dbZipFile - DestinationPath C:\tools\oracle- setup - Force
18- $rspContent = Get-Content - Path C:\tools\oracle- setup\XEInstall.rsp
19- $rspContent = $rspContent -replace ' PASSWORD=.*' , " PASSWORD=pass"
20- $rspContent = $rspContent -replace ' INSTALLDIR=.*' , " INSTALLDIR=C:\tools\oracle\"
21- Set-Content - Path C:\tools\oracle- setup\XEInstall- new.rsp - Value $rspContent
22- cmd.exe / c ' C:\tools\oracle-setup\setup.exe /s /v"RSP_FILE=C:\tools\oracle-setup\XEInstall-new.rsp" /v"/L*v C:\tools\oracle-setup\setup.log" /v"/qn"'
35+ $rspContent = @ (
36+ " INSTALLDIR=$installDir \"
37+ " PASSWORD=$dbPassword "
38+ " LISTENER_PORT=$dbPort "
39+ " EMEXPRESS_PORT=$dbEmExpressPort "
40+ " CHAR_SET=$dbCharset "
41+ " DB_DOMAIN=$dbDomain "
42+ )
43+ $argumentList = @ (
44+ ' /s'
45+ " /v`" RSP_FILE=$setupDir \OracleServerInstall.rsp`" "
46+ " /v`" /L*v $setupDir \OracleServerSetup.log`" "
47+ ' /v"/qn"'
48+ )
49+ if (Get-Command 7z - ErrorAction SilentlyContinue) {
50+ 7z x $dbZipFile " -o$setupDir " - y | Out-Null
51+ } else {
52+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($dbZipFile , $setupDir )
53+ }
54+ $rspContent | Set-Content - Path $setupDir \OracleServerInstall.rsp
55+
56+ $oldEnv = @ {
57+ TMPDIR = $env: TMPDIR
58+ TMP = $env: TMP
59+ TEMP = $env: TEMP
60+ }
61+
62+ try {
63+ $env: TMPDIR = " $setupDir \temp"
64+ $env: TMP = " $setupDir \temp"
65+ $env: TEMP = " $setupDir \temp"
66+
67+ Start-Process - FilePath $setupDir \setup.exe - ArgumentList $argumentList - WorkingDirectory $workingDir - NoNewWindow - Wait
68+ }
69+ finally {
70+ $env: TMPDIR = $oldEnv.TMPDIR
71+ $env: TMP = $oldEnv.TMP
72+ $env: TEMP = $oldEnv.TEMP
73+ }
74+
75+ Add-Path - PathItem " $oracleHome \bin"
76+ $env: ORACLE_HOME = " $installDir \dbhomeXE"
2377 }
2478 end {
2579 }
0 commit comments