This repository has been archived on 2024-09-06. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
PersonnalVNC/buildscript.ps1
2016-04-05 16:52:05 +02:00

148 lines
No EOL
4.7 KiB
PowerShell

param([string]$appconf="", [string]$hotliners="")
#PS build script for PersonnalHelpDesk
#
#Version 0.1
$VERSION = "0.1"
$WORKING_DIR = Split-Path -path $($MyInvocation.MyCommand.Definition)
$BUILD_DIR = $WORKING_DIR + "\build"
$UTILS_DIR = $WORKING_DIR + "\utils"
$TMP_DIR = $WORKING_DIR + "\tmp"
$SRC_DIR = $WORKING_DIR + "\src"
$PS_EXEC_NAME = "launcher.exe"
$FINAL_EXEC_NAME = "helpdesk.exe"
$VNC_URL = "http://www.uvnc.com/component/jdownloads/finish/5-bins/295-ultravnc-1210-all-bin-zip/0.html"
$PS2EXE_URL = "https://gallery.technet.microsoft.com/PS2EXE-Convert-PowerShell-9e4e07f1/file/134627/1/"
$7Z_URL = "http://www.7-zip.org/a/7za920.zip"
$7ZSFX_URL = "http://7zsfx.info/files/7zsd_160_2712.7z"
function create_dir {
param([string]$dir)
if (Test-Path $dir){
return $false
}
New-Item $dir -type directory | Out-Null
return $true
}
function extract{
param(
[string]$dest_path,
[string]$zip_path
)
$shell = new-object -com Shell.Application
Try {
$shell.NameSpace($dest_path).CopyHere($zip_path) | Out-Null
Write-Host -ForegroundColor Green "done"
}
Catch {
Write-Host -ForegroundColor Red " Error "
}
}
function download_util{
param(
[string]$util,
[string]$source,
[string]$file_to_extract
)
create_dir "$UTILS_DIR\$VERSION\$util"
Write-Host -ForegroundColor white -NoNewline "Downloading $util please wait ... "
Try {
(New-Object System.Net.WebClient).DownloadFile($source,"$TMP_DIR\$util.zip")
}
Catch {
Write-Host -ForegroundColor Red " Error bad URL? "
return
}
Write-Host -ForegroundColor Green -NoNewline "done"
if ($file_to_extract -ne "false"){
Write-Host -ForegroundColor white -NoNewLine " ... extracting : "
extract "$UTILS_DIR\$VERSION\$util\" "$TMP_DIR\$util.zip\$file_to_extract"
}
}
if ( -Not $appconf -Or -Not (Test-Path $appconf) ){
Write-Host -ForegroundColor White "Application configuration file $appconf not found, using default"
$appconf = "$SRC_DIR\res\conf\app.conf.ps1"
}
if ( -Not $hotliners -Or -Not (Test-Path $hotliners) ){
Write-Host -ForegroundColor White "Application configuration file $hotliners not found, using default"
$hotliners = "$SRC_DIR\res\conf\hotliners.conf.ps1"
}
if (-not (create_dir $BUILD_DIR)){
Remove-Item $BUILD_DIR\* -recurse
}
create_dir $UTILS_DIR | Out-Null
create_dir $TMP_DIR | Out-Null
if ( create_dir $UTILS_DIR\$VERSION ) {
#then download VNC + PS2EXE
download_util "vnc" $VNC_URL "win7\winvnc.exe"
download_util "ps2exe" $PS2EXE_URL "*"
download_util "7z" $7Z_URL "7za.exe"
(New-Object System.Net.WebClient).DownloadFile($7ZSFX_URL,"$TMP_DIR\7zsd.7z")
cmd -ArgumentList @("/c", "$UTILS_DIR/$VERSION/7z/7za.exe", "e", "$TMP_DIR\7zsd.7z", "7zsd.sfx","-o$UTILS_DIR/$VERSION/", "-y")
}
#applying personnal parameters
$patched_source = @()
Get-Content $SRC_DIR\helpdesk.ps1 | ForEach-Object {
switch ($_) {
{$_ -match "app.conf.ps1"} {
ForEach ($line in Get-Content $appconf) {
$patched_source += $line
}
break
}
{$_ -match "hotliners.conf.ps1"} {
ForEach ($line in Get-Content $hotliners){
$patched_source += $line
}
break
}
default{$patched_source += $_}
}
}
$patched_source | Set-Content $BUILD_DIR\helpdesk.ps1 -Encoding "UTF8"
# Build executable from our PS script
Invoke-Expression "$UTILS_DIR\$VERSION\ps2exe\ps2exe.ps1 $BUILD_DIR\helpdesk.ps1 $BUILD_DIR\$PS_EXEC_NAME -noconsole -nested"
Remove-Item $BUILD_DIR\$PS_EXEC_NAME.config
Set-Location $WORKING_DIR
# Copy all file to build Dir
create_dir $BUILD_DIR\res\ | Out-Null
Copy-Item $SRC_DIR\UltraVNC.ini $BUILD_DIR\res\
Copy-Item $SRC_DIR\res\* $BUILD_DIR\res\
Copy-Item $UTILS_DIR\$VERSION\vnc\winvnc.exe $BUILD_DIR\res\
create_dir $BUILD_DIR\res\conf\ | Out-Null
if ($appconf -ne "") {
$txtfile = Get-Content $appconf
}
else {
$txtfile = Get-Content $BUILD_DIR\res\conf\app.conf.ps1
}
if ($hotliners -ne "") {
Copy-Item $hotliners $BUILD_DIR\res\conf\hotliners.conf.ps1
}
else {
Copy-Item $SRC_DIR\res\conf\hotliners.conf.ps1 $BUILD_DIR\res\conf\hotliners.conf.ps1
}
#Zip all elements
Set-Location $BUILD_DIR
cmd -ArgumentList @("/c", "$UTILS_DIR/$VERSION/7z/7za.exe", "a", "installer.7z", "*")
#copy file for autoSFX archive.
Copy-Item $WORKING_DIR\src\config.txt $BUILD_DIR\
Copy-Item $UTILS_DIR\$VERSION\7zsd.sfx $BUILD_DIR\
#concatenate binary files for creating ou auto-SFX file
cmd -ArgumentList @("/c", "copy", "/b","7zsd.sfx", "+", "config.txt", "+", "installer.7z", $FINAL_EXEC_NAME)
#Remove-Item $BUILD_DIR -recurse