Edit: places where I said $HOME/.bin I should have written $HOME/bin or any equivalent is fine. I.E, any user-writable directory that is in the user's PATH.
So I have a bash script which I am distributing as a client for my API. Current version installs like this curl -s http://api.blah.com/install | sudo sh
. I may try to deal with six different package management systems so that they can just apt-get
or brew install
at some point, but for now I am going with the one-liner since I want this solution to work for multiple systems. However, apparently there are quite a few users on systems like cygwin or even Macs who don't have sudo at all or don't have it set up.
The scenario is a user signs up for my API, enters their credit card information. I have a bash client for the API that doubles as a reference implementation and also a way to try out the API or deploy VMs and Docker containers using the command line. I want to create an easy way for users to install the API client.
For example, there used to be a one-line install for npm curl http://npmjs.org/install.sh | sh
. Also homebrew has a one-line installer ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
(see http://brew.sh).
My install script just downloads the API client script and puts it in /usr/bin and makes it executable. But I am thinking based on the issues with sudo and the fact that this doesn't really need to be installed globally, I would like to just install it into the user's $HOME/.bin or $HOME/local/bin (create that if it there is no existing equivalent).
This is my current install script:
#!/bin/bash
BASE="https://api.blah.com"
sudo bash -c "curl -s $BASE/mycmd > /usr/bin/mycmd"
sudo chmod uga+x /usr/bin/mycmd
First wrinkle that occurs to me is that many users are now in zsh. So if I add or modify a line in ~/.bashrc that updates the PATH to include $HOME/.bin, that won't work for those systems.
So to restate the question, what code should I use to download and install my script into a user-writable directory in that user's PATH ($HOME/local/bin, or whatever is available in PATH by default) directory and make sure that is in their PATH, with the requirement (or at least strong desire) that this will work on almost everyone's system (if they have something like a Unix prompt) (without requiring sudo)?
Since some people consider modifying the PATH to be evil, I would like to install in the default $HOME/whatever/bin for that system, that is already in the user's PATH, if possible, rather than automatically modifying their PATH to include some particular directory.
Thanks very much!
command
is probably better thanhash
. Actually, I think it answers pretty much all of it. unix.stackexchange.com/a/126854/52934cat > ./file || cd elsewhere
- that doesn't address$PATH
though. Sorry. Butgetconf
can help you there. Alsoset -C
will ensure you don't overwrite anything you shouldn't.