Invoking Boxstarter with a script and not a package

Oct 8, 2013 at 8:11 PM
Edited Oct 8, 2013 at 8:14 PM
I would like to have my boxstarter script be a stand-alone script and not part of a package. My scenario is that I am trying to have something so that dozens of people in my office can run Boxstarter from a network share and customize their personal installation script. I want to avoid having to build a package each time they change something.

I have everything in place to install BoxStarter and run their personalized script. I thought using Invoke-Boxstarter would allow me to run all of the Boxstart stuff in the script block.

In my sample script, the 'Update-ExecutionPolicy' command seems to work, but the cinstm command does not.

Is what I a looking for supported? Here is my sample script.
Import-Module $env:appdata\boxstarter\Boxstarter.Chocolatey\Boxstarter.Chocolatey.psd1

Invoke-BoxStarter -RebootOk -ScriptToCall {
    Update-ExecutionPolicy Unrestricted

    cinstm 7zip.install

    Write-BoxstarterMessage 'Finished'
}
Coordinator
Oct 8, 2013 at 8:59 PM

Hi Rob,

Using the Invoke-Boxstarter function is not the way you want to go here. I apologize for the lack of clarity and plan to address that soon after the next release. That function is used by Invoke-ChocolateyBoxstarter which is what you want to call but it lacks a ScriptBlock parameter. However, I recently pushed 1.1.40 which address this (its not yet documented) and here is how you would call this. You do need to at least save the individual script to a file or a plain text URL resource like a github gist. Lets say you wanted to use this script https://gist.github.com/mwrock/6890586. You would call:

Import-Module $env:appdata\boxstarter\Boxstarter.Chocolatey\Boxstarter.Chocolatey.psd1

Invoke-ChocolateyBoxstarter https://gist.github.com/mwrock/6890586/raw/32013f11d5e633999869cc15aa17a2497c0ef9e3/gistfile1.txt

Now if the script was saved to \\network\share\script.ps1 then you would call:

Import-Module $env:appdata\boxstarter\Boxstarter.Chocolatey\Boxstarter.Chocolatey.psd1

Invoke-ChocolateyBoxstarter \\network\share\script.ps1

Hope that makes sense.

Oct 9, 2013 at 2:52 PM
That is awesome and everything seems to be working great.

Thanks for implementing my request before I thought of it! You must do great in the stock market.
Oct 9, 2013 at 8:20 PM
I might have spoken too soon. It looks like, after the first run, the script won't run again. When this is used for real, it probably won't be a huge issue, but it does make it hard to test scripts.

The temp package that is being created is updated, but it never seems to run. Here is the output. Do you see anything obviously wrong with what I am doing?
Boxstarter: LocalRepo is at C:\Users\rcannon\AppData\Roaming\boxstarter\BuildPackages
Boxstarter: Chocoltey installed, seting up interception of Chocolatey methods.
Calling 'C:\Chocolatey\chocolateyinstall\nuget.exe pack temp_RCANNONDESK\temp_RCANNONDESK.nuspec -NoPackageAnalysis'.
Attempting to build package from 'temp_RCANNONDESK.nuspec'.
Successfully created package 'C:\Users\rcannon\AppData\Roaming\boxstarter\BuildPackages\temp_RCANNONDESK.1.0.0.nupkg'.

Boxstarter: Created a temporary package temp_RCANNONDESK from \\isgfile02\Boxstarter\UserScripts\rcannon.ps1 in C:\Users
\rcannon\AppData\Roaming\boxstarter\BuildPackages
Boxstarter: Installing temp_RCANNONDESK package from C:\Users\rcannon\AppData\Roaming\boxstarter\BuildPackages
++ Boxstarter starting Calling Chocolatey to install temp_RCANNONDESK
Chocolatey (v0.9.8.20) is installing temp_RCANNONDESK and dependencies. By installing you accept the license for temp_RC
ANNONDESK and each dependency you are installing.
______ temp_RCANNONDESK v1.0.0 ______
Boxstarter: Starting Windows Update Service
++ Boxstarter finished Installation session. 00:00:12.0179082
Coordinator
Oct 10, 2013 at 2:09 AM

Hmm. This is a Boxstarter bug. It means there is an error thrown from inside of your script. Boxstarter is swallowing the error. The Chocolatey convention is to write scripts in this format:

try {

#Your script here

Write-ChocolateySuccess 'example'

} catch {

Write-ChocolateyFailure 'example' $($_.Exception.Message)

throw

}

This ensures script errors are displayed from Write-ChocolateyFailure and Boxstarter then swallows what is thrown so that a single package failure does not halt the entire install. Boxstarter consumers should be ensured that their errors will be displayed regardless of their own try/catch.

For now you can work around this by wrapping your script like this:

try {

#Your script here

} catch {

Write-Error $_

}

Oct 10, 2013 at 3:40 PM
That worked and showed me the error message.

My issue was a package that I was installing from a local source (via the -Source flag). It had a dependency on DotNet4.5, which works when it installed via the command line, but not via Boxstarter. I think it was only using the local source and couldn't find DotNet4.5 there. Using the 'chocolatey source add' command to permanently add the source, instead of using the -Source flag worked.

Thanks again.