23 October 2013

chocolatey.org packages sudo

Sudo - my first chocolatey.org package

Chocolatey is a windows nuget based app distribution framework a bit like apt-get for linux.
I have been using it for some years and finaly came around creating a package for the platform.

This blogpost shares some of my findings


Sudo is a command line utility used to elevate priviledges from a shell prompt, the same way as in linux, just that windows requires a prompt and a new window. There are no attributes on runas or cmd for doing this but the trick is to use the ShellExecution from a cscript. 

The utility is found in our deployment utilities and i was missing it as a global command and thought i would distribute it using chocolatey for easy distribution and reuse.

The structure of the chocolatey nuget packages

When working with the chocolatey and batch files the trick i found was to dump the copied content to bin and use the chocolateyinstall.ps1 to handle the Bin reference file. The difficult part was to figure out how to generate the Bin file that was not created automatically. 

The Bin folder is the one accessible through the environment PATH and therefore where you need a reference to sudo if you want it to be usable in any shell context. All other packages had there Bins created and no references to how this was done in there respective chocolateyinstall.ps1 files.

Further research in the main chocolatey repository lead me to the Source of the Bin files and revealled that the exe files where automatically scanned and served as base for generating the relative Binfiles.

$files = get-childitem $packageFolder -include *.exe -recurse

The final product

The final touch was to add the Generate-BinFile straight to the install script of the package. This approach means that the BinFile is not removed when uninstalling the package but there does not seem to be a chocolateyuninstall script executable from the package and therefore no way to handle this.

After uploading the final package to both https://github.com/janhebnes/chocolatey-packages and the official gallery http://chocolatey.org/packages/sudo you can now download it through the chocolatey distribution network.

A simple access to the elevated shell > CINST SUDO

No comments: