Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
5 edited tags
| link
4
source | link

What code should I use to download and install my script into a user-writable directory in the user's PATH (without requiring sudo)?

A few people in answers/comments have suggested this is a virus or homework question. Not sure they understood the question. TheThe 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. One option is to tell them to manually download two scripts, copy them into a folder in their path, and then chmod them. Another option is to use a one-line installer with sudo which copies the file into /usr/bin or a similar location. I want this to work on most Unix-variants. Another option is to create and publish packages for several different systems including homebrew, apt, pact, and yum. I already encountered recently two users who had to do extra steps to set up sudo on their system. However, the commands in the API are actually simple enough that they would be able to use the system even though they are relatively novice in the Unix command line. Setting up separate packages means quite a lot of extra work in terms of maintenance, and also means that for some of the systems sudo would be required, which is not really desirable not only because some users don't have their systems configured for sudo but also because some users may see it as an additional security risk since it requires giving the package additional privileges. If I did however create packages for each of those systems, the code run by them would be very similar to the script I am describing in this system. Most packaging systems do not require any kind of code review now for publishing packages. So the actual effect of this will just mean additional work for me and a slightly greater security impact for the users if I create and maintain all of those separate packages.

Someone else suggested that this might be a homework question. I have no idea why they would get that idea. In fact, I am 36 years old, have been programming since I was seven years old, and am now working on my second online business. The concept of the one-line install is not something I originated naively. ForFor 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).

#!/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), firstFirst 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.

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.

What code should I use to download and install my script into a user-writable directory in the user's PATH?

A few people in answers/comments have suggested this is a virus or homework question. Not sure they understood the question. 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. One option is to tell them to manually download two scripts, copy them into a folder in their path, and then chmod them. Another option is to use a one-line installer with sudo which copies the file into /usr/bin or a similar location. I want this to work on most Unix-variants. Another option is to create and publish packages for several different systems including homebrew, apt, pact, and yum. I already encountered recently two users who had to do extra steps to set up sudo on their system. However, the commands in the API are actually simple enough that they would be able to use the system even though they are relatively novice in the Unix command line. Setting up separate packages means quite a lot of extra work in terms of maintenance, and also means that for some of the systems sudo would be required, which is not really desirable not only because some users don't have their systems configured for sudo but also because some users may see it as an additional security risk since it requires giving the package additional privileges. If I did however create packages for each of those systems, the code run by them would be very similar to the script I am describing in this system. Most packaging systems do not require any kind of code review now for publishing packages. So the actual effect of this will just mean additional work for me and a slightly greater security impact for the users if I create and maintain all of those separate packages.

Someone else suggested that this might be a homework question. I have no idea why they would get that idea. In fact, I am 36 years old, have been programming since I was seven years old, and am now working on my second online business. The concept of the one-line install is not something I originated naively. 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).

#!/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 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)?

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.

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.

What code should I use to download and install my script into a user-writable directory in the user's PATH (without requiring sudo)?

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).

#!/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.

3 added 2486 characters in body
source | link

A few people in answers/comments have suggested this is a virus or homework question. Not sure they understood the question. 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. One option is to tell them to manually download two scripts, copy them into a folder in their path, and then chmod them. Another option is to use a one-line installer with sudo which copies the file into /usr/bin or a similar location. I want this to work on most Unix-variants. Another option is to create and publish packages for several different systems including homebrew, apt, pact, and yum. I already encountered recently two users who had to do extra steps to set up sudo on their system. However, the commands in the API are actually simple enough that they would be able to use the system even though they are relatively novice in the Unix command line. Setting up separate packages means quite a lot of extra work in terms of maintenance, and also means that for some of the systems sudo would be required, which is not really desirable not only because some users don't have their systems configured for sudo but also because some users may see it as an additional security risk since it requires giving the package additional privileges. If I did however create packages for each of those systems, the code run by them would be very similar to the script I am describing in this system. Most packaging systems do not require any kind of code review now for publishing packages. So the actual effect of this will just mean additional work for me and a slightly greater security impact for the users if I create and maintain all of those separate packages.

Someone else suggested that this might be a homework question. I have no idea why they would get that idea. In fact, I am 36 years old, have been programming since I was seven years old, and am now working on my second online business. The concept of the one-line install is not something I originated naively. 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).

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).

A few people in answers/comments have suggested this is a virus or homework question. Not sure they understood the question. 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. One option is to tell them to manually download two scripts, copy them into a folder in their path, and then chmod them. Another option is to use a one-line installer with sudo which copies the file into /usr/bin or a similar location. I want this to work on most Unix-variants. Another option is to create and publish packages for several different systems including homebrew, apt, pact, and yum. I already encountered recently two users who had to do extra steps to set up sudo on their system. However, the commands in the API are actually simple enough that they would be able to use the system even though they are relatively novice in the Unix command line. Setting up separate packages means quite a lot of extra work in terms of maintenance, and also means that for some of the systems sudo would be required, which is not really desirable not only because some users don't have their systems configured for sudo but also because some users may see it as an additional security risk since it requires giving the package additional privileges. If I did however create packages for each of those systems, the code run by them would be very similar to the script I am describing in this system. Most packaging systems do not require any kind of code review now for publishing packages. So the actual effect of this will just mean additional work for me and a slightly greater security impact for the users if I create and maintain all of those separate packages.

Someone else suggested that this might be a homework question. I have no idea why they would get that idea. In fact, I am 36 years old, have been programming since I was seven years old, and am now working on my second online business. The concept of the one-line install is not something I originated naively. 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).

2 added 368 characters in body; edited title
source | link
1
source | link