Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Added batch mode to chocolatey.cmd - cinst multiple packages #304

Closed
wants to merge 2 commits into from
Closed

Added batch mode to chocolatey.cmd - cinst multiple packages #304

wants to merge 2 commits into from

Conversation

Redsandro
Copy link
Contributor

I wrote this batch installer.

It's a small clever hack I wrote some time ago for myself. But now that I installed Chocolatey on a friend's computer, I realized how much I missed this invaluable feature, so I thought I'd put it in a pull request.

Everything remains the same, but you can now also do this:

cinst notepadplusplus 7zip vlc putty GoogleChrome firefox filezilla adobereader Skype Dropbox VirtualCloneDrive foobar2000 gimp pidgin xnview speccy opera xnview

..and go drink a cofffee. :)

@Redsandro
Copy link
Contributor Author

Anyway, I strongly encourage you to merge this (and port it to the monolith if you want, but merge it first). When you do this trick on a random strangers laptop, they become so happy, you get instant Chocolatey fans. But it won't work if they install Chocolatey on someone elses laptop. Until this is merged, that is. ;)

@rismoney
Copy link
Contributor

ummm...I kindly disagree... - "but it should not be in there like today".

cinst putty -Version 0.62.0.1 works before this change but not after. Relying on the count of params is not a satisfactory test for batch mode.

plus I agree with @ferventcoder that if you're changing one ingress into calling chocolatey we should make it consistent. Forking the functionality between cmd and powershell functionality is not ideal since the cmd is really a convenience factor for non-posh access

@rismoney
Copy link
Contributor

one last thing I might opt for array splat handling in posh or take the packages in via a pipeline, which means the source could be handled any way the user wants (objects)

maybe like 7zip vlc putty | chocolatey install

@Redsandro
Copy link
Contributor Author

Nope, it works fine here. Single packages are handled exactly as before. I just installed putty to confirm your response but I had no problem. This is Windows 7 Home Premium with .NET 4.0.

cinst.bat is shorthand for chocolatey.cmd, and that is the one I changed. 99% of people will use cinst. 0,9% of people will use chocolatey.cmd And you want to hold off the update to accomodate for the other 0,1%? (PS Don't get offended by my exaggeration skills, that's just how I communicate. ;) )

And your pipe example is a totally bad unintuitive crazy kinda Chocolatey-will-never-get-popular-this-way language construct IMO. I just want to see this Chocolatey be more like... well, every other package manager out there in the Linux world so that you can actually guess how it works.

apt-get install geany firefox vlc chromium libreoffice filezilla
yum install apache2 php mysql vsftp mongodb
chocolatey install 7zip vlc putty GoogleChrome firefox filezilla
cinst 7zip vlc putty GoogleChrome firefox filezilla

There I fixed it. You're welcome. ;)

@Redsandro
Copy link
Contributor Author

Are you running windows XP or an older .NET? Or did you make an accidental typo when trying my code?

Because if it is the former that does not like the code, I can rewrite the batch in MS-DOS style. Uglier but maybe more compatible? (I'm just guessing here) I thought XP already did work with the 'new' syntax though.

@Redsandro
Copy link
Contributor Author

One last thing, I am not "Relying on the count of params". It just batches all params one by one.

@rismoney
Copy link
Contributor

let me retest. I will use current choco version and report results... I do like the concept btw - i wasn't trying to be a pita.

@rismoney
Copy link
Contributor

I removed my custom version an ran this-

on a fresh Win7 Enterprise, I bootstrapped with the install method on http://chocolatey.org/

within cmd.exe:

C:\Users\admin>cinst putty -Version 0.62.0.1
Installing packages in batch mode.
Installing putty ...
Chocolatey (v0.9.8.20) is installing putty and dependencies. By installing you a
ccept the license for putty and each dependency you are installing.
______ putty v0.62.0.2 ______
Downloading putty (http://the.earth.li/~sgtatham/putty/latest/x86/putty.zip) to
C:\Users\admin\AppData\Local\Temp\chocolatey\putty\puttyInstall.zip
Extracting C:\Users\admin\AppData\Local\Temp\chocolatey\putty\puttyInstall.zip t
o C:\Chocolatey\lib\putty.0.62.0.2\tools...
C:\Chocolatey\lib\putty.0.62.0.2\tools
putty has finished succesfully! The chocolatey gods have answered your request!
Adding C:\Chocolatey\bin\PAGEANT.bat and pointing to '%DIR%..\lib\putty.0.62.0.2
\tools\pageant.exe'.
Adding C:\Chocolatey\bin\PLINK.bat and pointing to '%DIR%..\lib\putty.0.62.0.2\t
ools\plink.exe'.
Adding C:\Chocolatey\bin\PSCP.bat and pointing to '%DIR%..\lib\putty.0.62.0.2\to
ols\pscp.exe'.
Adding C:\Chocolatey\bin\PSFTP.bat and pointing to '%DIR%..\lib\putty.0.62.0.2\t
ools\psftp.exe'.
Adding C:\Chocolatey\bin\PUTTY.bat and pointing to '%DIR%..\lib\putty.0.62.0.2\t
ools\putty.exe'.
Setting up PUTTY as a non-command line application.
Adding C:\Chocolatey\bin\PUTTYGEN.bat and pointing to '%DIR%..\lib\putty.0.62.0.
2\tools\puttygen.exe'.
Setting up PUTTYGEN as a non-command line application.
Finished installing 'putty' and dependencies - if errors not shown in console, n
one detected. Check log for errors if unsure.
Installing -Version ...
C:\Chocolatey\chocolateyinstall\chocolatey.ps1 : Missing an argument for parame
ter 'version'. Specify a parameter of type 'System.String' and try again.
At line:1 char:193
+ [System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threadi
ng.Thread]::CurrentThread.CurrentUICulture = '';& 'C:\Chocolatey\chocolateyinst
all\chocolatey.ps1' install -Version <<<<
    + CategoryInfo          : InvalidArgument: (:) [chocolatey.ps1], Parameter
   BindingException
    + FullyQualifiedErrorId : MissingArgument,chocolatey.ps1

Installing 0.62.0.1 ...
Chocolatey (v0.9.8.20) is installing 0.62.0.1 and dependencies. By installing yo
u accept the license for 0.62.0.1 and each dependency you are installing.
Unable to find package '0.62.0.1'.

Finished installing '0.62.0.1' and dependencies - if errors not shown in console
, none detected. Check log for errors if unsure.

C:\Users\admin>

@PowerShell -NoProfile -ExecutionPolicy unrestricted -Command "[System.Threading.Thread]::CurrentThread.CurrentCulture = ''; [System.Threading.Thread]::CurrentThread.CurrentUICulture = '';& '%DIR%chocolatey.ps1' %*"
set numArgs=0
for %%n in (%*) do Set /A numArgs+=1
if '%numArgs%' GTR '2' echo Installing packages in batch mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I just don't remember batch scripting, but it appears at first glance you are assuminganything GTR 2 parameters after cinst (aka install) are both package names. in that use case it works, and nicely I might add.

in the case of cinst putty -Version 0.62.0.1, this logic appears flawed based on my screen paste, since it is trying to batch install a package named "-version"

@rismoney
Copy link
Contributor

i am not using alpha version (which is the one on github iirc)

@Redsandro
Copy link
Contributor Author

Oh! I misunderstood you! You are correct. Let me get back to you when I am
not asleep. My mistake. I got a solution.
On Jun 26, 2013 6:49 AM, "Rich Siegel" notifications@github.com wrote:

i am not using alpha version (which is the one on github iirc)


Reply to this email directly or view it on GitHubhttps://github.com//pull/304#issuecomment-20027033
.

@Redsandro
Copy link
Contributor Author

You were absolutely right. When you said "cinst putty -Version 0.62.0.1 works before this change but not after." I thought you just mentioned the version of putty as a courtesy to me to be able to verify, instead of meaning an actual command. I should have picked up on the minus sign, but you can also use backticks to minimize confusion.

Having said that, I now remember why I didn't push this mod in the first place when I made it: Although I personally don't care about version management and just ignored it - I only use Chocolatey to batch install 30 apps on a clean system for others, and additional apps for myself although I rarely use Windows - I know I purposely ignored the rest of the commands and that is why I shouldn't push this. I just forgot about it after a long time.

However, I do seriously mean that this feature is absolutely invaluable to the point that I'd rather create a custom installer for myself and everyone I recommend Chocolatey to, than wait 15 months for someone to port this to ps.

On a more positive note, I just fixed all the problems in my latest commit. :) You can now either install multiple packages, or give commands using -wildcards as specified in chocolatey /?.

@Redsandro
Copy link
Contributor Author

Single:

C:\Users\Redsandro>cinst notepadplusplus
Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
______ notepadplusplus.install v6.3.3 ______
# blah blah

Added commands (works with all commands):

C:\Users\Redsandro>cinst notepadplusplus -version 2.24.1
Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
Unable to find version '2.24.1' of package 'notepadplusplus'.
# etc etc

Batch mode:

C:\Users\Redsandro>cinst notepadplusplus treesize
Installing packages in batch mode.

Installing notepadplusplus ...

Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
'notepadplusplus 6.3.3' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'notepadplusplus' and dependencies - if errors not shown in console, none detected. Check log for errors if unsure.

Installing treesize ...

Chocolatey (v0.9.8.20) is installing treesize and dependencies. By installing you accept the license for treesize and each dependency you are installing.
Unable to find package 'treesize'.

Finished installing 'treesize' and dependencies - if errors not shown in console, none detected. Check log for errors if unsure.

Installed all packages. :)

@rismoney
Copy link
Contributor

Iirc the chocolatey.ps1 isnt using positional parameters... so shouldnt
Cinst -version 1.0 pkgnane work?

I appreciate your efforts but I think trying to solve this via cmd will only make fixing it via ps1 needing to unwind this.

Maybe others have an opinion on this... I love the idea btw.

-------- Original message --------
From: Redsandro notifications@github.com
Date:
To: chocolatey/chocolatey chocolatey@noreply.github.com
Cc: "Siegel, Richard" RSiegel@ise.com
Subject: Re: [chocolatey] Added batch mode to chocolatey.cmd - cinst multiple packages (#304)

Single:

C:\Users\Redsandro>cinst notepadplusplus
Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
______ notepadplusplus.install v6.3.3 ______

blah blah

Added commands (works with all commands):

C:\Users\Redsandro>cinst notepadplusplus -version 2.24.1
Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
Unable to find version '2.24.1' of package 'notepadplusplus'.

etc etc

Batch mode:

C:\Users\Redsandro>cinst notepadplusplus treesize
Installing packages in batch mode.

Installing notepadplusplus ...

Chocolatey (v0.9.8.20) is installing notepadplusplus and dependencies. By installing you accept the license for notepadplusplus and each dependency you are installing.
'notepadplusplus 6.3.3' already installed.
If you want to reinstall the current version of an existing package, please use the -force command.

Finished installing 'notepadplusplus' and dependencies - if errors not shown in console, none detected. Check log for errors if unsure.

Installing treesize ...

Chocolatey (v0.9.8.20) is installing treesize and dependencies. By installing you accept the license for treesize and each dependency you are installing.
Unable to find package 'treesize'.

Finished installing 'treesize' and dependencies - if errors not shown in console, none detected. Check log for errors if unsure.

Installed all packages. :)


Reply to this email directly or view it on GitHubhttps://github.com//pull/304#issuecomment-20112828.

@Redsandro
Copy link
Contributor Author

Does that work? As far as I know, $command is always the first and $packageName is always the second, because they are not used as wildcards. I don't think that ps does automatic shifting if the first is actually $version but is extracted.

I think this is pretty rock-solid. But in the end you can break everything if you want it to, especially this hideous thing called powerscript. But this implementation does everything the way chocolatey /? says it is done. At least as far as I have tested.

@Redsandro
Copy link
Contributor Author

Also, don't underestimate the power of cmd. The ps does not require fixing. But you're right I'm curious to others' opinions too.

I do know the opinion of non-technical users. It has astounding similarities with the last sentence in the chorus of Thrift Shop by Macklemore.

As a final exposition I would like to constrain how much added value this is to normal users. And we're all busy people, the smallest ps features take forever to get in mainline.

The reason that I am pushing this so vividly is that I had four people applaud enthousiasticly this Chocolatey trick I did, and when they mention they want to implement that in their own workflow, I have to explain that I'm using a custom version and they need to copy my blabla.cmd to yaddah yaddah (translated into how they perceive my instructions) and they are like: Wut? http://goo.gl/OdpNo

@rismoney
Copy link
Contributor

I googled this thrift shop and watched http://vimeo.com/m/57418480 ... no words. Made my day

@ferventcoder
Copy link
Contributor

Well, 15 months or a few days... still doesn't make it right c9f9e8d

@ferventcoder
Copy link
Contributor

so this requires comma between package names. I am trying to figure out removing everything from implicitly being positional but running into a few issues I will need to explore later.

@Redsandro
Copy link
Contributor Author

Wow, it's handy to know powershell. :P

Details are very important. Details can even make an overpriced turd popular. Just look at Apple Inc. That's why I'm seemingly nitpicky, but please understand it is only because I care. :)

That said, this is a big step forward. But it's still unintuitive-ish. These days, smartphones come without a manual because everything is tackled in the simplest feasible decimation. People (can) rely on that. Not needing comma's is a smartphone that doesn't need a manual. Otherwise we'd have to explain in the manual: We know the 10 most popular package managers use space delimited package lists for batch installation, but we need a comma separated list because [insert reason the user doesn't really care about].

Especially if you promote Chocolatey as "like apt-get".

I know, semantically "like" allows for variations. But that's not how the world, users from the three most popular distro's that use apt-get, and google, work.

We can probably use both btw. Just putting it out there.

@ferventcoder
Copy link
Contributor

Yep. Notice I said temporarily need a comma.

On Thursday, June 27, 2013, Redsandro wrote:

Wow, it's handy to know powershell. :P

Details are very important. Details can even make an overpriced turd
popular. Just look at Apple Inc. That's why I'm seemingly nitpicky, but
please understand it is only because I care. :)

That said, this is a big step forward. But it's still unintuitive-ish.
These days, smartphones come without a manual because everything is tackled
in the simplest feasible decimation. People (can) rely on that. Not needing
comma's is a smartphone that doesn't need a manual. Otherwise we'd have to
explain in the manual: We know the 10 most popular package managers use
space delimited package lists for batch installation, but we need a comma
separated list because [insert reason the user doesn't really care about]

.

Especially if you promote Chocolatey as "like apt-get".

I know, semantically "like" allows for variations. But that's not how
the world, users from the three most popular distro's that use apt-get, and
google, work.


Reply to this email directly or view it on GitHubhttps://github.com//pull/304#issuecomment-20126209
.


Rob
"Be passionate in all you do"

http://devlicio.us/blogs/rob_reynolds
http://ferventcoder.com
http://twitter.com/ferventcoder

@Redsandro
Copy link
Contributor Author

this requires comma between package names.

Temporarily? :P

Comma is inherent to powershell array afaik so I'm not sure how you propose to do that, but that last comment makes me happy. :)

@ferventcoder
Copy link
Contributor

its actually pretty easy -

[parameter(Position=1, ValueFromRemainingArguments=$true)]
  [string[]]$packageNames=@('')

The hard part is that I have naming conflicts with debug and verbose. So I either have to change the names, which I'm not going to do, or drop powershell in favor of c# calling powershell packages (which is in the plans anyway).

@Redsandro
Copy link
Contributor Author

That simple huh.

By c# replacing ps, do you mean you want to rewrite the entire monolith?

@ferventcoder
Copy link
Contributor

@ferventcoder
Copy link
Contributor

And you ask the twitters and the twitters provide... :)

Fixed in 6ca7ed1

@Redsandro
Copy link
Contributor Author

I don't understand the consequences of removing something that needs to stay in, but this is a huge step in the usability of Chocolatey! I am happy.

Although I didn't test anything (already got a working batcher in place ;)) so I don't know if those rismoney testcases will hold up.

@Redsandro
Copy link
Contributor Author

So once rismoney approves, I suggest uploading a new release as soon as possible. YESTERDAY!

@ferventcoder
Copy link
Contributor

I didn't remove, I just moved them down... :)

So those things are still there.

@ferventcoder
Copy link
Contributor

cup chocolatey -pre and you have it... :)

@rismoney
Copy link
Contributor

@Redsandro I don't have to approve. I am only here to critique, debase, and hassle people :)

Seriously though - the best thing about open source projects, which this "issue" illustrates so well, is that you had an idea, submitted a PR demonstrating a prototype on how you thought it should work, it was reviewed by people who care about the project, and someone else rose up to implement in a way that fits within the bigger picture. Awesome work for an awesome feature.

@ferventcoder
Copy link
Contributor

That and I've been mulling over this guy for awhile in how I would see it implemented. :)

@ferventcoder
Copy link
Contributor

Also your sarcasm went a long way into me getting off of my duff and getting 'er done. 👍

With my new job you should see a much faster response time...

@Redsandro
Copy link
Contributor Author

Yes I approve with a smile on my face. :)
Did not expect to have this available (through -prerelease) today.

@ferventcoder
Copy link
Contributor

Beauty of a prerelease. Those can go out all day and night so folks can play with them. And if they don't work, well it was a prerelase... ;)

@rismoney
Copy link
Contributor

hmm, if sarcasm works....
I am not going to thread 💩 or anything.

the feature I could really use to help get my internal packages opensourced is-
a pkgsource id in chocolatey.config file or an environment variable that could then be used within chocolateyinstall.ps1 to replace a hardcoded url.

Right now all my packages are hardcoded to an internal url, and ideally there would be a way to
if pkgsourceid exists or env:$pkgsourceid exists then use that, otherwise fall back to url like Mozilla.org for firefox or whatever.

Summary I want to be able to create packages that can be used universally, on the public - via mirrors or private feed. Embedding a url becomes problematic to maintain.

Then a param called pkgsource could be also used to override the default url.

This has nothing to do with the -source, source (but you know that already)

@ferventcoder
Copy link
Contributor

yep... know what you are talking about @rismoney - will Mark Johnson's stuff not work for you? The offline installer piece?

@rismoney
Copy link
Contributor

link?

@Redsandro
Copy link
Contributor Author

Not really understanding what you mean. I thought your auto-update packages did something like that. I don't really understand those either. :P But apart from that, aren't all package sources hardcoded? We would need to have a sources registry. In which case we might as well add the silent installer switches to a registry. And the installation code. And we wouldn't need packages anymore.

Sorry I am probably misunderstanding this. :P

@rismoney
Copy link
Contributor

example-

Install-ChocolateyPackage -packageName "$packageName" `
            -fileType 'msi' `
            -url 'http://chocopackages.myorg.com/PuppetEnterprise/puppet-enterprise-2.6.1.msi' `
            -silentArgs '/quiet'
            #-url64bit '' `
            #-validExitCodes

myorg.com doesn't help you at all, and I don't want to put myorg url on the interwebs.

@rismoney
Copy link
Contributor

but I want to publish 100s of packages, for the world to consume, because chocolatey adoption would skyrocket, if people knew how to install/uninstall everything from Office to Exchange Server using just cinst. I just want to sanitize them.

@rismoney
Copy link
Contributor

we can certainly take this elsewhere. there might even be an issue on this.

@rismoney
Copy link
Contributor

#269

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants