How it exactly works? - bash

I was trying to install Node.js on Ubuntu 16.04 with the help of the following instruction
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
I was confused to see sudo "bash -" without options specified. How it can be so?

This command line uses curl to download a script from Node's site. It then pipes it in to a new shell executed as root (thanks to the sudo), and the script contains all the actions required for installing Node.

Related

curl -s https://laravel.build/example-app | bash is asking for a Uri

When if follow the Laravel getting started docs it says to use
curl -s https://laravel.build/example-app | bash
But it then asks me for a URI which the Laravel documentation does not tell me about.
If I try and put in something like:
d:laravel-test
The console comes back saying
Cannot recognize "D:laravel-test" as a System.Uri due to a format error.
I'm quite new to web development so please go easy on me.
You must use the build command from a linux (Bash) command line, not the powershell.
In the Windows command line (powershell), navigate to the folder where your Laravel projects are to be stored.
C:\Users\username>cd PATH TO FOLDER
Open the windows subsystem for linux by typing 'wsl' at the prompt
C:\Users\username\path to folder>wsl (This part isn't clear in the docs)
This will open the Linux/BASH command line where you should paste the Laravel curl build command
username#computer:/filepath$ curl -s https://laravel.build/example-app | bash
This will launch the installation. Note that it will take a long time the first time but will be much faster the next time. The Docker environment will continue to run in this terminal.
Not an expert but this worked for me.
curl -s https://laravel.build/example-app | bash

skip installing confirm('yes' or 'no') in Dockerfile [duplicate]

How do I install the anaconda / miniconda without prompts on Linux command line?
Is there a way to pass -y kind of option to agree to the T&Cs, suggested installation location etc. by default?
can be achieved by bash miniconda.sh -b (thanks #darthbith)
The command line usage for this can only be seen with -h flag but not --help, so I missed it.
To install the anaconda to another place, use the -p option:
bash anaconda.sh -b -p /some/path
AFAIK pyenv let you install anaconda/miniconda
(after successful instalation)
pyenv install --list
pyenv install miniconda3-4.3.30
For a quick installation of miniconda silently I use a wrapper
script script that can be executed from the terminal without
even downloading the script. It takes the installation destination path
as an argument (in this case ~/miniconda) and does some validation too.
curl -s https://gist.githubusercontent.com/mherkazandjian/cce01cf3e15c0b41c1c4321245a99096/raw/03c86dae9a212446cf5b095643854f029b39c921/miniconda_installer.sh | bash -s -- ~/miniconda
Silent installation can be done like this, but it doesn't update the PATH variable so you can't run it after the installation with a short command like conda:
cd /tmp/
curl -LO https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -u
Here -b means batch/silent mode, and -u means update the existing installation of Miniconda at that path, rather than failing.
You need to run additional commands to initialize PATH and other shell init scripts, e.g. for Bash:
source ~/miniconda3/bin/activate
conda init bash

How to run (./) a bash script located in the cloud?

Using a ubuntu 16.04 what I do is :
Download the .sh script using wget https://gist.githubusercontent.com/...
Turn the .sh file executable sudo chmod guo+x sysInit.sh
Execute the code through sudo ./sysInit.sh
I was wondering if it is possible to run the code directly from the web.
Would be something like: sudo ./ https://gist.githubusercontent.com/....
Is it possible to do that?
You can use cUrl to download and run your script. I don't think its installed by default on Ubuntu so you'll have to sudo apt-get install curl first if you want to use it. To download and run your script with sudo just run
curl -sL https://gist.githubusercontent.com/blah.sh | sudo sh
Be warned this is very risky and not advised for security reasons. See this related question why-using-curl-sudo-sh-is-not-advised
Yes, it is possible using curl and piping the result to sh.
Try the following command.
curl https://url-to-your-script-file/scriptFile.sh | sh
No, sudo only works from a command line prompt in a shell

Create a bash script that doesn't prompt user for trivial responses like 'yes/Y or no/N'

I am working on a bash server setup script for ubuntu 14.03 LTS. For some of the commands the script is executing, it prompts the user to input 'yes/no' or 'Y/N'. For some of these commands I have been able to pass a flag to the command in question that will auto respond with a yes. For example: sudo apt-get install -y gcc doesn't prompt the user.
On the other hand, I can't seem to find a way to do this for
sudo gem source -a http://rubygems.org/.
It keeps prompting me with Do you want to add this insecure source? [yn].
So far I've tried the following:
yes | gem source -a http://rubygems.org/ which I found here
Any Suggestions?
First add this certificate via script in this folder: {rubyfolder}\lib\ruby\2.1.0\rubygems\ssl_certs

Detecting if a command is executable by sudo

I am wanting to detect in a shell script if a command I am going to run via sudo can in fact run via sudo. On newer versions of sudo I can do sudo -l "command" and this gives me exactly the result I want.
However, some of the systems have an old version of sudo in which -l "Command" isn't available. Another way I was thinking about doing it was to just try running the command then see if sudo prompted for the password. However, I do not see an easy way to do this as sudo writes the password prompt to the TTY and not via stdout.
Does anyone else know of a straight forward way to do this?
I should also mention "expect" doesn't seem to be available on the systems with the older sudo revisions, either.
Just for reference the "difficult" version of sudo appears to version 1.6.8
On Linux, on (at least) Debian-like systems, you can have a look at /etc/sudoers (and the optional /etc/sudoers.d/* files, if created, and included in the main /etc/sudoers) that give (among others)
the search path to where (which dir) a command can be issued
the sudo user (root) privileges
groups who can use sudo and their privileges
This is the sudoers man page for more information.
if you're only wanting to check that a password is required to run a command then you should be able to run:
$ sudo -n <command>
E.g.
$ sudo -n echo
sudo: sorry, a password is required to run sudo

Resources