Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support for homebrew cask #24653

Closed
fgimian opened this issue Jun 12, 2015 · 30 comments · Fixed by #59439
Closed

Feature Request: Support for homebrew cask #24653

fgimian opened this issue Jun 12, 2015 · 30 comments · Fixed by #59439
Labels
Feature new functionality including changes to functionality and code refactors, etc. MacOS pertains to the OS of fruit Platform Relates to OS, containers, platform-based utilities like FS, system based apps
Milestone

Comments

@fgimian
Copy link

fgimian commented Jun 12, 2015

Hey there guys, hope you're doing well 😄

I was wondering if you would please consider supporting homebrew-cask in the future?

This allows OS X users to install desktop applications via the CLI. Ansible contains support for it and it works rather well, but I'd really like to try Salt instead for automating the build of my Mac 😄

Thanks heaps and have a great weekend!
Fotis

@justinta justinta added Feature new functionality including changes to functionality and code refactors, etc. Platform Relates to OS, containers, platform-based utilities like FS, system based apps labels Jun 16, 2015
@justinta justinta added this to the Approved milestone Jun 16, 2015
@justinta
Copy link

@fgimian Thank you for this feature idea.

@DavidJFelix
Copy link
Contributor

👍 +1

@jfindlay jfindlay added the P2 Priority 2 label Aug 25, 2015
@jfindlay jfindlay added the MacOS pertains to the OS of fruit label Sep 25, 2015
@cliffrowley
Copy link

Yes please! ;-) I'm more than happy to help test (I am refactoring my home lab and looking at using saltstack to orchestrate my mini server and its virtual machines).

@stale
Copy link

stale bot commented Feb 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Feb 17, 2018
@fgimian
Copy link
Author

fgimian commented Feb 19, 2018

This would still be desirable if possible 😄

@stale
Copy link

stale bot commented Feb 19, 2018

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Feb 19, 2018
@weswhet
Copy link
Contributor

weswhet commented Apr 3, 2018

I believe this merged PR should bring support for cask installs. e.g. caskroom/cask/opera

@lmf-mx
Copy link
Contributor

lmf-mx commented Apr 30, 2019

#45309 adds some support for checking if a cask is installed. There are, however, a few outstanding issues.

  1. caskroom/cask appears to be an alias/redirect from the migration of the repo to Homebrew/homebrew-cask. With cask becoming part of core, tapping caskroom/cask is no longer necessary. brew taps the repo as homebrew/cask.

  2. caskroom/versions is also now located at Homebrew/homebrew-cask-versions and tapped as homebew/cask-versions. The check at 4aa3e23#diff-922c510bbabef7d622da0ff9dce6acd3R151 doesn't account for the casks in this repo.
    Installing a package such as vlc-nightly via homebrew/cask-versions/vlc-nightly or caskroom/versions/vlc-nightly will sucessfully install. The pkg.installed state will return as failed, since vlc-nightly will be returned as 'caskroom/cask/vlc-nightly'.

@sagetherage sagetherage removed the P2 Priority 2 label Jun 3, 2020
@cdalvaro
Copy link
Contributor

cdalvaro commented Jul 14, 2020

It is currently supported, just install your package specifying the full name: homebrew/cask/visual-studio-code

visual-studio-code:
  pkg.installed:
    - name: homebrew/cask/visual-studio-code

It works for custom taps too:

cdalvaro/tap/cpp-plotly:
  pkg.installed

or even fonts:

fira code nerd font:
  pkg.installed:
    - name: - name: homebrew/cask-fonts/font-fira-code-nerd-font

This support was added on #54216

Warning: The only thing I haven't tested yet, is what does happen when installing a cask formula which requires user password...

@gabeio
Copy link

gabeio commented Jan 14, 2021

brew changed how to interface with casks:

[ERROR   ] The following packages failed to install/update: homebrew/cask/google-chrome
[ERROR   ] Command '['su', '-l', 'gabeio', '-c', 'cd -- /Users/gabeio && { /usr/local/bin/brew cask list --versions\n }']' failed with return code: 1
[ERROR   ] stderr: Error: Calling brew cask list is disabled! Use brew list [--cask] instead.
[ERROR   ] retcode: 1

if anyone is interested in the brew version(s) I have:

$ brew --version
Homebrew 2.7.4
Homebrew/homebrew-core (git revision b36d1; last commit 2021-01-14)
Homebrew/homebrew-cask (git revision 71a8b0; last commit 2021-01-15)

and salt version:

$ salt --version
salt 3002.2

@cdalvaro
Copy link
Contributor

brew changed how to interface with casks:

[ERROR   ] The following packages failed to install/update: homebrew/cask/google-chrome
[ERROR   ] Command '['su', '-l', 'gabeio', '-c', 'cd -- /Users/gabeio && { /usr/local/bin/brew cask list --versions\n }']' failed with return code: 1
[ERROR   ] stderr: Error: Calling brew cask list is disabled! Use brew list [--cask] instead.
[ERROR   ] retcode: 1

if anyone is interested in the brew version(s) I have:

$ brew --version
Homebrew 2.7.4
Homebrew/homebrew-core (git revision b36d1; last commit 2021-01-14)
Homebrew/homebrew-cask (git revision 71a8b0; last commit 2021-01-15)

and salt version:

$ salt --version
salt 3002.2

This have been solved in #58381

@gabeio
Copy link

gabeio commented Jan 14, 2021

@cdalvaro thanks for the info! do you know when that is going to get out onto salt?

@cdalvaro
Copy link
Contributor

cdalvaro commented Jan 14, 2021

@cdalvaro thanks for the info! do you know when that is going to get out onto salt?

You are welcome! I know that it is planned to be released with the Aluminium version. But I don't know the release date yet.

Update: You can check here the Aluminium release date. Apparently, it is scheduled for February 24th.

@maneamarius
Copy link

maneamarius commented Feb 16, 2021

Hey guys, as of salt 3002.2, this doesn't work on Mac:

visual-studio-code:
  pkg.installed:
    - name: homebrew/cask/visual-studio-code

It just fails this way:

----------
          ID: vscode-installed
    Function: pkg.installed
        Name: homebrew/cask/visual-studio-code
      Result: False
     Comment: The following packages failed to install/update: homebrew/cask/visual-studio-code
     Started: 05:22:27.302660
    Duration: 5702.606 ms
     Changes:

Is there any way to make this work the salt way? I can make it work with cmd.run, but this shouldn't be the right way :)

@cdalvaro
Copy link
Contributor

cdalvaro commented Feb 16, 2021

At the moment, if you have access to you salt-master files, you can add this file: mac_brew_pkg.py (04b62a5) (#59439) to your custom _modules directory in order to overwrite the bundled one:

pillar/
reactor/
salt/
  _modules/
    mac_brew_pkg.py
  _states/
  data/

and then sync your minion modules:

salt '*' saltutil.sync_modules

If you prefer, you can use this version of mac_brew_pkg.py (7129b5b) (#58381), which is already merged into master, but not yet released.

@maneamarius
Copy link

Thank you!
I tried that, and for some reason, it installs the package and fails the state:

---------- ID: p4v-installed Function: pkg.installed Name: homebrew/cask/p4v Result: False Comment: The following packages failed to install/update: homebrew/cask/p4v=21.1 Started: 07:20:22.134855 Duration: 20268.193 ms Changes: ---------- homebrew/cask/p4v: ---------- new: 21.1,2075061 old: p4v: ---------- new: 21.1,2075061 old:

and here's the code I used:

p4v-installed: pkg.installed: - runas: {{ mac_user }} - name: homebrew/cask/p4v - version: {{ p4v_version }} - unless: brew list | grep p4v

@cdalvaro
Copy link
Contributor

Could you try this instead (if you have used patch #59439)?

p4v-installed:
  pkg.installed:
    - name: p4v

or if you have used #58381, try using this one?

p4v-installed:
  pkg.installed:
    - name: homebrew/cask/p4v

brew won't update the cask if it is already installed so the unless condition is not necessary.

@maneamarius
Copy link

I did not use any patches, I just used vanilla 3002.2
Which patch should I use? And how do I apply it? (I haven't done that before)
I think I should apply a patch which will be included in the next release, right?

thanks a lot,
Marius

@cdalvaro
Copy link
Contributor

#58381 and #59371 are already merged with master and should be available when Salt Aluminium version is released.

Download the salt/modules/mac_brew_pkg.py file from master (link) and put it inside salt/_modules directory in your salt-master host.

pillar/
  top.sls
salt/
  _modules/
    mac_brew_pkg.py
  top.sls

Then you have to sync all modules with your minions (salt '*' saltutil.sync_modules) and try your p4v formula this way:

p4v-installed:
  pkg.installed:
    - name: homebrew/cask/p4v

Warning: You must remember to delete this file when Salt 3003 is available to avoid freezing the module for future updates.

@maneamarius
Copy link

I copied the file, did refresh modules, and I still get this error.
So it installs it, but returns with error for some reason.

`----------
ID: p4v-installed
Function: pkg.installed
Name: homebrew/cask/p4v
Result: False
Comment: The following packages failed to install/update: homebrew/cask/p4v=21.1
Started: 13:45:26.494591
Duration: 25542.42 ms
Changes:
----------
homebrew/cask/p4v:
----------
new:
21.1,2075061
old:

Summary for xyz

Succeeded: 0 (changed=1)
Failed: 1

Total states run: 1
Total run time: 25.542 s`

@maneamarius
Copy link

If I remove runas from my state, it doesn't run at all, I get this:

---------- ID: p4v-installed Function: pkg.installed Name: homebrew/cask/p4v Result: False Comment: Unable to run command '['brew', '--prefix']' with the context '{'cwd': '/var/root', 'shell': False, 'env': {'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'PWD': '/', 'XPC_FLAGS': '0x0', 'XPC_SERVICE_NAME': 'com.saltstack.salt.minion', 'SHLVL': '0', 'LC_CTYPE': 'C', 'LC_NUMERIC': 'C', 'LC_TIME': 'C', 'LC_COLLATE': 'C', 'LC_MONETARY': 'C', 'LC_MESSAGES': 'C', 'LC_PAPER': 'C', 'LC_NAME': 'C', 'LC_ADDRESS': 'C', 'LC_TELEPHONE': 'C', 'LC_MEASUREMENT': 'C', 'LC_IDENTIFICATION': 'C', 'LANGUAGE': 'C'}, 'stdin': None, 'stdout': -1, 'stderr': -2, 'with_communicate': True, 'timeout': None, 'bg': False, 'close_fds': True}', reason: [Errno 2] No such file or directory: 'brew': 'brew' Started: 13:48:30.725950 Duration: 18.479 ms Changes:

@cdalvaro
Copy link
Contributor

I think the problem is that you are specifying the version of the app homebrew/cask/p4v=21.1, try without telling salt to install version 21.1

@maneamarius
Copy link

yeah you are right, I just tried without version, and doesn't error out anymore.

I'd like to pin to specific version though, is there a way to do that?

@cdalvaro
Copy link
Contributor

I have never tried that feature. Not even directly with brew. I will try to test it as soon as possible.

@maneamarius
Copy link

thanks a lot, I appreciate all your help so far!

@maneamarius
Copy link

Just to note, that visual-studio-code brew package can be installed using cask and version.
But p4v package cannot be installed using the version, it errors out as described above.
Maybe it helps you in troubleshooting?

@cdalvaro
Copy link
Contributor

May be you need to specify the full p4v version: 21.1,2075061

@maneamarius
Copy link

I tried that as well, still didn't work :(

@cdalvaro
Copy link
Contributor

cdalvaro commented Feb 16, 2021

I'm not really sure, but it seems like casks cannot be pinned:

~
❯  brew pin visual-studio-code
Error: No available formula with the name "visual-studio-code".

~
❯  brew pin homebrew/cask/visual-studio-code
Error: No available formula with the name "homebrew/cask/visual-studio-code".

~
❯  brew list --pinned

~
❯  brew pin boost

~
❯  brew list --pinned
boost

~
❯  brew unpin boost

~
❯  brew list --pinned

Update: Homebrew will install the cask version available at the moment of the first installation. Then, apps with auto-update won't be updated by Homebrew using brew upgrade. Instead, they'll use its own mechanism.

You cannot either install specific Homebrew formulas version unless they provide a specific formula for such version, like ruby

❯  brew search '/ruby@[0-9.]+/'
==> Formulae
ruby@2.4                      ruby@2.5                      ruby@2.6                      ruby@2.7                      ruby@3 ✔                      ruby@3.0 ✔

@maneamarius
Copy link

Yes, I think you are right, some casks offer the option to specify version, and some not.
It's a pity they don't follow same standard across..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature new functionality including changes to functionality and code refactors, etc. MacOS pertains to the OS of fruit Platform Relates to OS, containers, platform-based utilities like FS, system based apps
Projects
None yet
Development

Successfully merging a pull request may close this issue.