0

Edit: places where I said $HOME/.bin I should have written $HOME/bin or any equivalent is fine.

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.

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 folder (create that if it doesn't exist) and then make sure that $HOME/bin or $HOME/.bin is in their PATH.

This is my current install script:

#!/bin/bash
BASE="https://api.blah.com"

if ! hash curl 2>/dev/null; then
  echo "Please install curl. On Ubuntu/Mint/Debian, command is sudo apt-get install curl"
  echo "Trying to install curl.."
  sudo apt-get install curl
  if ! hash curl 2>/dev/null; then
    echo "Yeah couldn't install curl.  Please install it."
    exit 1 
  else
    echo "curl installed. Continuing."
  fi
fi

sudo bash -c "curl -s $BASE/mycmd > /usr/bin/mycmd"
sudo chmod uga+x /usr/bin/mycmd

Three reasons I am asking this question rather than just starting to hack on a solution right away: 1) I think that this is a common requirement or desire (installing something non-globally without requiring privileges) and so the answer to this question will probably be useful to someone else. 2) since this is supposed to work on the majority of systems, I believe there are going to be a few wrinkles, perhaps ones that I am not aware of since I don't use all types of systems regularly, just Ubuntu. 3) I believe that at least a few users out there may have already solved this problem.

Regarding 2), 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 the user's $HOME/.bin or ($HOME/bin) 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)?

Also, one more meta statement about this question.. I am shortening it.. if you object completely to the approach, please just don't answer, rather than giving me a lecture. For example I am aware that some people don't like one-line installs. If you have minor changes to the approach however, please do answer.

Thanks very much!

0

If you can access the user's $PATH variable, try installing your script in a (the?) directory owned and executable by the $USER.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.