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

run a script on the shell with sudo #18

Closed
neumachen opened this issue Mar 20, 2015 · 3 comments
Closed

run a script on the shell with sudo #18

neumachen opened this issue Mar 20, 2015 · 3 comments
Labels

Comments

@neumachen
Copy link

So how do I go on about calling a script on the yaml file with sudo?

Let's say I have a directory and on the root is a directory called scripts, how do I run a script in that directory and prompt for sudo when needed or as an entire execution?

@anishathalye
Copy link
Owner

I'm not 100% sure what exactly you're asking, so correct me if I'm wrong.

It sounds like you want to run some interactive bash scripts (or similar) that are located a subdirectory of your dotfiles folder, and you want to be able to use sudo in the scripts and have it prompt you for a password. You can do that using a shell command in your install.conf.yaml using the extended syntax to be able to use the additional options.

Commands are executed in your dotfiles directory, so you can specify relative paths and it'll work out just fine. You can also enable stdin/stdout/stderr as required.

For example, suppose you had a bash script in your dotfiles directory, in scripts/test (and the execute bit was set, or you called bash scripts/test explicitly):

#!/usr/bin/env bash
sudo echo this is being run as root for no good reason

Then you could have your install.conf.yaml as follows:

- shell:
  -
    description: "Run test script"
    command: "./scripts/test"
    stdout: true
    stderr: true
    stdin: true

This should work like you want it to. You can disable stdin/stdout/stderr as desired (and if you omit the line, it defaults to disabled).

@neumachen
Copy link
Author

Thanks @anishathalye. Reason is, I have both OSX and Linux based distros and I often am spinning fresh dev environments (that includes installing rails, spring, etc). So I wanted to create a one dotfile installer for all but currently the only way I can differentiate between OSX and Linux is $(uname -s).

But this is awesome, will try it out. Once I am done, perhaps I can add this to a template thing for those who want a fresh dev environment for rails or node development. 👯

@anishathalye
Copy link
Owner

Ok, I see, that makes sense.

You may also be interested in doing something like what was discussed in #11, perhaps even adding platform detection by uname -s to select which install.conf.yaml file you use.

Also, you could take the approach I use -- I have dotfiles contain all the shared stuff, and then I have per-machine configuration in dotfiles-local, where there is one branch corresponding to a machine or set of machines (currently with 6 sets of configuration).

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

No branches or pull requests

2 participants