Skip to content

Commit

Permalink
Merge pull request #689 from Ana06/more-installer
Browse files Browse the repository at this point in the history
More improvements in installer.vm
  • Loading branch information
Ana06 authored Oct 18, 2023
2 parents 5ccdf05 + fa71a04 commit 6149f75
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20230926</version>
<version>0.0.0.20231013</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
40 changes: 20 additions & 20 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function VM-Check-Reboot {
)
try {
if (Test-PendingReboot){
VM-Write-Log "ERROR" "[Err] Host must be rebooted before continuing install of $package.`n"
VM-Write-Log "ERROR" "Host must be rebooted before continuing installation of $package.`n"
Invoke-Reboot
exit 1
}
Expand Down Expand Up @@ -681,7 +681,7 @@ function VM-Write-Log-Exception {
)
$msg = $error_record.Exception.Message
$position_msg = $error_record.InvocationInfo.PositionMessage
VM-Write-Log "ERROR" "[ERR] $msg`r`n$position_msg"
VM-Write-Log "ERROR" "$msg`r`n$position_msg"
throw $error_record
}

Expand Down Expand Up @@ -919,23 +919,23 @@ function VM-Remove-Appx-Package {
VM-Write-Log-Exception $_
}
} else {
VM-Write-Log "WARN" "[+] Installed $appName not found on the system."
VM-Write-Log "WARN" "`tInstalled $appName not found on the system."
}
# Check if the app is provisioned
$provisionedPackage = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq $appName } -ErrorAction SilentlyContinue
if ($provisionedPackage) {
try {
Remove-AppxProvisionedPackage -PackageName $provisionedPackage.PackageName -Online -ErrorAction SilentlyContinue
VM-Write-Log "INFO" $("Provisioned package " + $provisionedPackage.PackageName + " removed")
VM-Write-Log "INFO" $("`tProvisioned package " + $provisionedPackage.PackageName + " removed")
}
catch {
VM-Write-Log-Exception $_
}
} else {
VM-Write-Log "WARN" "[+] Provisioned $appName not found on the system."
VM-Write-Log "WARN" "`tProvisioned $appName not found on the system."
}
} catch {
VM-Write-Log "ERROR" "An error occurred while removing the $appName package. Error: $_"
VM-Write-Log "ERROR" "`tAn error occurred while removing the $appName package. Error: $_"
}
}

Expand All @@ -952,9 +952,9 @@ function VM-Set-Service-Manual-Start {

if ($service) {
Set-Service -Name $service.Name -StartupType Manual
VM-Write-Log "INFO" "[+] Service $serviceName has been disabled."
VM-Write-Log "INFO" "Service $serviceName has been disabled."
} else {
VM-Write-Log "WARN" "[+] Service $serviceName not found."
VM-Write-Log "WARN" "Service $serviceName not found."
}
} catch {
VM-Write-Log "ERROR" "An error occurred while setting the service startup type. Error: $_"
Expand All @@ -976,9 +976,9 @@ function VM-Disable-Scheduled-Task {
try {
$output = Disable-ScheduledTask -TaskName $value -ErrorAction SilentlyContinue
if ($output){
VM-Write-Log "INFO" "[+] Scheduled task '$name' has been disabled."
VM-Write-Log "INFO" "Scheduled task '$name' has been disabled."
} else {
VM-Write-Log "ERROR" "[+] Scheduled task '$name' not found."
VM-Write-Log "ERROR" "Scheduled task '$name' not found."
}

} catch {
Expand Down Expand Up @@ -1024,13 +1024,13 @@ function VM-Update-Registry-Value {
if (!(Test-Path -Path $path)) {
# Create the registry key
New-Item -Path $path -Force | Out-Null
VM-Write-Log "INFO" "`t[+] Registry key created: $path"
VM-Write-Log "INFO" "Registry key created: $path"
} else {
VM-Write-Log "WARN" "`t[+] Registry key already exists: $path"
VM-Write-Log "WARN" "Registry key already exists: $path"
}

Set-ItemProperty -Path $path -Name $value -Value $validatedData -Type $type -Force | Out-Null
VM-Write-Log "INFO" "[+] $name has been successful"
VM-Write-Log "INFO" "$name has been successful"
} catch {
VM-Write-Log "ERROR" "Failed to update the registry value. Error: $_"
}
Expand All @@ -1056,16 +1056,16 @@ function VM-Remove-Path {
if ($type -eq "file") {
if (Test-Path -Path $path -PathType Leaf) {
Remove-Item -Path $path -Force
VM-Write-Log "INFO" "[+] $name has been successfully removed."
VM-Write-Log "INFO" "$name has been successfully removed."
} else {
VM-Write-Log "WARN" "[+] $path does not exist."
VM-Write-Log "WARN" "$path does not exist."
}
} elseif ($type -eq "dir") {
if (Test-Path -Path $path -PathType Container) {
Remove-Item -Path $path -Recurse -Force
VM-Write-Log "INFO" "[+] $name has been successfully removed."
VM-Write-Log "INFO" "$name has been successfully removed."
} else {
VM-Write-Log "WARN" "[+] $path does not exist."
VM-Write-Log "WARN" "$path does not exist."
}
}
} catch {
Expand All @@ -1090,9 +1090,9 @@ function VM-Execute-Custom-Command{
foreach ($cmd in $cmds) {
Start-Process powershell -ArgumentList "-WindowStyle","Hidden","-Command",$cmd -Wait
}
VM-Write-Log "INFO" "[+] All commands for '$name' have been executed successfully."
VM-Write-Log "INFO" "`tAll commands for '$name' have been executed successfully."
} catch {
VM-Write-Log "ERROR" "An error occurred while executing commands for '$name'. Error: $_"
VM-Write-Log "ERROR" "`tAn error occurred while executing commands for '$name'. Error: $_"
}
}

Expand Down Expand Up @@ -1284,4 +1284,4 @@ public class Shell {
} catch {
VM-Write-Log-Exception $_
}
}
}
2 changes: 1 addition & 1 deletion packages/installer.vm/installer.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>installer.vm</id>
<version>0.0.0.20231016</version>
<version>0.0.0.20231017</version>
<authors>Mandiant</authors>
<description>Generic installer for custom virtual machines.</description>
<dependencies>
Expand Down
15 changes: 11 additions & 4 deletions packages/installer.vm/tools/chocolateyinstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ try {
foreach ($package in $packagesToInstall) {
VM-Write-Log "INFO" "Installing: $package"
choco install "$package" -y
VM-Write-Log "INFO" "$package has been installed"
if ($LASTEXITCODE) {
VM-Write-Log "INFO" "`t$package has been installed"
} else {
VM-Write-Log "ERROR" "`t$package has not been installed"
}
}
} catch {
VM-Write-Log-Exception $_
}
VM-Write-Log "INFO" "[+] All packages complete"
VM-Write-Log "INFO" "Packages installation complete"

# Set Profile/Version specific configurations
VM-Write-Log "INFO" "[+] Beginning Windows OS VM profile configuration changes"
VM-Write-Log "INFO" "Beginning Windows OS VM profile configuration changes"
$configPath = Join-Path $Env:VM_COMMON_DIR "config.xml" -Resolve
VM-Apply-Configurations $configPath

Expand Down Expand Up @@ -120,6 +124,8 @@ try {
Write-Host "`t[-] $logPath" -ForegroundColor Yellow
Write-Host "`t[-] %PROGRAMDATA%\chocolatey\logs\chocolatey.log" -ForegroundColor Yellow
Write-Host "`t[-] %LOCALAPPDATA%\Boxstarter\boxstarter.log" -ForegroundColor Yellow
Start-Sleep 5
& notepad.exe $logPath
}

# Let users know installation is complete by setting lock screen & wallpaper background, playing win sound, and display message box
Expand Down Expand Up @@ -175,7 +181,8 @@ public class VMBackground
$form.Text = "$Env:VMname Installation Complete"
$form.TopMost = $true
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
if ($iconPath = Join-Path $Env:VM_COMMON_DIR "vm.ico" -Resolve){
$iconPath = Join-Path $Env:VM_COMMON_DIR "vm.ico"
if (Test-Path $iconPath) {
$form.Icon = New-Object System.Drawing.Icon($iconPath)
}
# Create a FlowLayoutPanel
Expand Down

0 comments on commit 6149f75

Please sign in to comment.