Skip to content

Commit

Permalink
added a boxstarter shell for loading modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mwrock committed Jan 9, 2014
1 parent 10bee85 commit 3472fef
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 16 deletions.
16 changes: 1 addition & 15 deletions BoxStarter.Common/Boxstarter.Common.psm1
@@ -1,21 +1,7 @@
Resolve-Path $PSScriptRoot\*.ps1 |
% { . $_.ProviderPath }

Export-ModuleMember Write-BoxstarterMessage,
Start-TimedSection,
Stop-TimedSection,
Enter-BoxstarterLogable,
Out-BoxstarterLog,
Log-BoxstarterMessage,
Test-Admin,
Invoke-FromTask,
Get-IsRemote,
Confirm-Choice,
Create-BoxstarterTask,
Remove-BoxstarterTask,
Write-BoxstarterLogo,
Get-CurrentUser,
Get-IsMicrosoftUpdateEnabled
Export-ModuleMember Write-BoxstarterMessage, Start-TimedSection, Stop-TimedSection, Enter-BoxstarterLogable, Out-BoxstarterLog, Log-BoxstarterMessage, Test-Admin, Invoke-FromTask, Get-IsRemote, Confirm-Choice, Create-BoxstarterTask, Remove-BoxstarterTask, Write-BoxstarterLogo, Get-CurrentUser, Get-IsMicrosoftUpdateEnabled

Export-ModuleMember -Variable Boxstarter

1 change: 1 addition & 0 deletions Boxstarter.Azure/Boxstarter.Azure.pssproj
Expand Up @@ -30,6 +30,7 @@
<Compile Include="Boxstarter.Azure.psd1" />
<Compile Include="BoxStarter.Azure.psm1" />
<Compile Include="Enable-BoxstarterVM.ps1" />
<Compile Include="Install-WinRMCert.ps1" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Target Name="Build" />
Expand Down
1 change: 1 addition & 0 deletions Boxstarter.Chocolatey/New-BoxstarterPackage.ps1
Expand Up @@ -27,6 +27,7 @@ Optional path whose contents will be copied to the repository
.LINK
http://boxstarter.codeplex.com
New-PackageFromScript
about_boxstarter_chocolatey
about_boxstarter_variable_in_chocolatey
Invoke-BoxstarterBuild
Expand Down
2 changes: 2 additions & 0 deletions Boxstarter.sln
Expand Up @@ -15,6 +15,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildScripts", "BuildScripts", "{E959DA78-673C-42A8-B935-F9665BC4C54B}"
ProjectSection(SolutionItems) = preProject
BuildScripts\bootstrapper.ps1 = BuildScripts\bootstrapper.ps1
BoxstarterChocolateyInstall.ps1 = BoxstarterChocolateyInstall.ps1
BuildScripts\build.proj = BuildScripts\build.proj
BuildScripts\build.ps1 = BuildScripts\build.ps1
BuildScripts\chocolateyinstall.ps1 = BuildScripts\chocolateyinstall.ps1
Expand All @@ -29,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
BoxStarter.bat = BoxStarter.bat
boxstarter.config = boxstarter.config
BoxstarterShell.ps1 = BoxstarterShell.ps1
build.bat = build.bat
LICENSE.txt = LICENSE.txt
EndProjectSection
Expand Down
28 changes: 28 additions & 0 deletions BoxstarterShell.ps1
@@ -0,0 +1,28 @@
$here = Split-Path -parent $MyInvocation.MyCommand.Definition
Resolve-Path $here\Boxstarter.*\*.psd1 |
% { Import-Module $_.ProviderPath -DisableNameChecking -Force -ErrorAction SilentlyContinue }
Import-Module $here\Boxstarter.Common\Boxstarter.Common.psd1 -Function Test-Admin

if(!(Test-Admin)) {
Write-BoxstarterMessage "Not running with administrative rights. Attempting to elevate..."
$command = "-ExecutionPolicy bypass -noexit -command &$here\BoxstarterShell.ps1"
Start-Process powershell -verb runas -argumentlist $command
Exit
}

$Host.UI.RawUI.WindowTitle="Boxstarter Shell"
cd $env:SystemDrive\
Write-Output @"
Welcome to the Boxstarter shell!
The Boxstarter commands have been imported from $here and are available for you to run in this shell.
You may also import them into the shell of your choice.
Here are some commands to get you started:
Install a Package: Install-BoxstarterPackage
Create a Package: New-BoxstarterPackage
Build a Package: Invoke-BoxstarterBuild
Enable a VM: Enable-BoxstarterVM
For Command help: Get-Help <Command Name> -Full
For Boxstarter documentation, source code, to report bugs or participate in discussions, please visit http://boxstarter.org
"@
7 changes: 7 additions & 0 deletions BuildScripts/BoxstarterChocolateyInstall.ps1
@@ -0,0 +1,7 @@
try {
Write-ChocolateySuccess "Boxstarter"
Write-Host "To load all Boxstarter Modules immediately, just enter 'BoxstarterShell'." -ForegroundColor Yellow
} catch {
Write-ChocolateyFailure "Boxstarter" "$($_.Exception.Message)"
throw
}
2 changes: 2 additions & 0 deletions BuildScripts/nuget/Boxstarter.Chocolatey.nuspec
Expand Up @@ -43,6 +43,8 @@
<file src="..\..\boxstarter.bat" target="tools"/>
<file src="..\..\boxstarter.config" target="tools"/>
<file src="..\..\LICENSE.txt" target="tools"/>
<file src="..\..\BoxstarterShell.ps1" target="tools"/>
<file src="..\..\BoxLogo.ico" target="tools"/>
<file src="..\..\Boxstarter.Chocolatey\**\*.*" target="tools\Boxstarter.Chocolatey"/>
</files>
</package>
3 changes: 3 additions & 0 deletions BuildScripts/nuget/Boxstarter.nuspec
Expand Up @@ -38,4 +38,7 @@
- Add ability to configure a VHD to open it to WMI so that Boxstarter Installs canenable remoting.
</releaseNotes>
</metadata>
<files>
<file src="..\BoxstarterChocolateyinstall.ps1" target="tools\chocolateyinstall.ps1"/>
</files>
</package>
48 changes: 47 additions & 1 deletion BuildScripts/setup.ps1
Expand Up @@ -17,8 +17,8 @@ function Install-Boxstarter($here, $ModuleName) {

PersistBoxStarterPathToEnvironmentVariable "PSModulePath"
PersistBoxStarterPathToEnvironmentVariable "Path"
$binPath = Join-Path $env:ChocolateyInstall bin
Import-Module "$boxstarterPath\$ModuleName" -DisableNameChecking -Force -ErrorAction SilentlyContinue
write-host "Boxstarter is now ready. You can type 'Boxstarter' from any command line at any path."
$successMsg = @"
The $ModuleName Module has been copied to $boxstarterPath and added to your Module path.
You will need to open a new console for the path to be visible.
Expand All @@ -32,9 +32,55 @@ PS:>Import-Module $ModuleName
PS:>Get-Help Boxstarter
"@
Write-BoxstarterMessage $successMsg

if($ModuleName -eq "Boxstarter.Chocolatey") {
$desktop = $([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::DesktopDirectory))
$startMenu=$("$env:appdata\Microsoft\Windows\Start Menu\Programs\Boxstarter")
if(!(Test-Path $startMenu)){
mkdir $startMenu
}
$target="powershell.exe"
$targetArgs="-ExecutionPolicy bypass -NoExit -Command &$boxstarterPath\BoxstarterShell.ps1"

$link = Join-Path $desktop "Boxstarter Shell.lnk"
Create-Shortcut $link $target $targetArgs $boxstarterPath

$link = Join-Path $startMenu "Boxstarter Shell.lnk"
Create-Shortcut $link $target $targetArgs $boxstarterPath

Add-Content -Path "$binPath\BoxstarterShell.bat" -Force -Value "$target $TargetArgs"
}

}

function Create-Shortcut($location, $target, $targetArgs, $boxstarterPath) {
$wshshell = New-Object -ComObject WScript.Shell
$lnk = $wshshell.CreateShortcut($location)
$lnk.TargetPath = $target
$lnk.Arguments = "$targetArgs"
$lnk.WorkingDirectory = $boxstarterPath
$lnk.IconLocation="$boxstarterPath\BoxLogo.ico"
$lnk.Save()

$tempFile = "$env:temp\TempShortcut.lnk"

$writer = new-object System.IO.FileStream $tempFile, ([System.IO.FileMode]::Create)
$reader = new-object System.IO.FileStream $location, ([System.IO.FileMode]::Open)

while ($reader.Position -lt $reader.Length)
{
$byte = $reader.ReadByte()
if ($reader.Position -eq 22) {
$byte = 34
}
$writer.WriteByte($byte)
}

$reader.Close()
$writer.Close()

Move-Item -Path $tempFile $location -Force
}
function PersistBoxStarterPathToEnvironmentVariable($variableName){
$value = [Environment]::GetEnvironmentVariable($variableName, 'User')
if($value){
Expand Down
Binary file added boxlogo.ico
Binary file not shown.

0 comments on commit 3472fef

Please sign in to comment.