1 # Title: PowerShell package build script
2 # Description: Build packages with installation
3 # Type: script
4 # Author: bajasoft <jbajer@gmail.com>
5 # Version: 0.2
6
7 # How to run PowerShell scripts: http://technet.microsoft.com/en-us/library/ee176949.aspx
8
9 # Command line parameters
10 # [-o] - set output file name (otter-browser.ps1 -o nameOfFile)
11 # [-a] - set architecture of binaries (Argument: 32/64)
12 # [-t] - type of build, default is weekly. Ignored if -a is included (Argument: weekly/beta/release)
13
14 Param(
15 [int]$a,
16 [string]$o,
17 [string]$t
18 )
19
20 # Global values
21 $Global:outputPath = "C:\develop\github\"
22 $Global:inputPath = "C:\downloads\Otter\"
23 $Global:7ZipBinaryPath = "C:\Program Files\7-Zip\7z.exe"
24 $Global:innoBinaryPath = "C:\Program Files (x86)\Inno Setup 5\ISCC.exe"
25 $Global:innoScriptPath = ".\otter-browser.iss"
26 $Global:configPath = ".\otter\config.h"
27
28 # Main-function
main()29 function main
30 {
31 "Packaging..."
32
33 # Find version information
34 ForEach ($line in Get-Content $Global:configPath)
35 {
36 if ($line -like '*OTTER_VERSION_MAIN*')
37 {
38 $mainVersion = $line -replace '^#define OTTER_VERSION_MAIN ' -replace '"'
39 }
40
41 if ($line -like '*OTTER_VERSION_WEEKLY*')
42 {
43 $weeklyVersion = $line -replace '^#define OTTER_VERSION_WEEKLY ' -replace '"'
44 }
45
46 if ($line -like '*OTTER_VERSION_CONTEXT*')
47 {
48 $contextVersion = $line -replace '^#define OTTER_VERSION_CONTEXT ' -replace '"'
49 }
50 }
51
52 # Set architecture of binaries
53 if ($a -eq 64)
54 {
55 $architecture = 64
56 }
57 else
58 {
59 $architecture = 32
60 }
61
62 if(!$o)
63 {
64 # Type of build
65 switch ($t)
66 {
67 "beta"
68 {
69 $packageName = "otter-browser-win" + $architecture + "-" + $contextVersion
70 $setupName = "otter-browser-win" + $architecture + "-" + $contextVersion + "-setup"
71 }
72 "release"
73 {
74 #TODO
75 }
76 default
77 {
78 $packageName = "otter-browser-win" + $architecture + "-weekly" + $weeklyVersion
79 $setupName = "otter-browser-win" + $architecture + "-weekly" + $weeklyVersion + "-setup"
80 }
81 }
82 }
83 else
84 {
85 $packageName = $o;
86 $setupName = $packageName + "-setup";
87 }
88
89 $7zipFileName = $Global:outputPath + $packageName + ".7z"
90 $zipFileName = $Global:outputPath + $packageName + ".zip"
91
92 # Set values to Inno setup script
93 $content = Get-Content $Global:innoScriptPath
94
95 $content |
96 Select-String -Pattern "ArchitecturesInstallIn64BitMode=x64" -NotMatch |
97 Select-String -Pattern "ArchitecturesAllowed=x64" -NotMatch |
98 ForEach-Object {
99 if ($architecture -eq 64 -and $_ -match "^DefaultGroupName.+")
100 {
101 "ArchitecturesInstallIn64BitMode=x64"
102 "ArchitecturesAllowed=x64"
103 }
104
105 $_ -replace "#define MyAppVersion.+", ("#define MyAppVersion `"$mainVersion" + "$contextVersion`"") -replace "OutputBaseFilename=.+", "OutputBaseFilename=$setupName" -replace "LicenseFile=.+", ("LicenseFile=$Global:inputPath" + "COPYING") -replace "OutputDir=.+", "OutputDir=$Global:outputPath" -replace "VersionInfoVersion=.+", "VersionInfoVersion=$mainVersion"
106 } |
107 Set-Content $Global:innoScriptPath
108
109 # Do full build
110 fullBuild $7zipFileName $zipFileName
111
112 "Finished!"
113 }
114
fullBuild($7zipFileName, $zipFileName)115 function fullBuild ($7zipFileName, $zipFileName)
116 {
117 Start-Process -NoNewWindow -Wait $Global:innoBinaryPath -ArgumentList $Global:innoScriptPath
118 Start-Process -NoNewWindow -Wait $Global:7ZipBinaryPath -ArgumentList "a", $7zipFileName, ($Global:inputPath + "*"), "-mmt4", "-mx9", "-m0=lzma2"
119 Start-Process -NoNewWindow -Wait $Global:7ZipBinaryPath -ArgumentList "a", "-tzip", $zipFileName, $Global:inputPath, "-mx5"
120 }
121
122 # Entry point
123 main
124