Auto accept EULA in bash script - bash

I'm trying to write a bash script that (among other things) installs ubuntu-restricted-extras, but I can't seem to find a proper solution to automatically accept the EULA. This has been suggested in another post:
yes | apt-get install -y ubuntu-restricted-extras
But this is not working for me. Any ideas?

Related

Creating executable file with pip install command on MacOS

I'm both new here and with MacOS and coding.
I know in windows I can create bash file to have an executable command in cmd. I've researched and discovered I can use similar file with MacOS (shell files) but I'm struggling to understand how to make one. I've tried different route:
As first thing I've tried creating a file in txt editor with this code:
#!/bin/bash
pip3 install pgzero
echo Installing Pygame Zero
Using later 'chmod 700 Filename' in terminal. It did not worked
I then tried with Apple Scrip, with a code like:
tell application "Terminal"
activate
do script "pip3 install pgzero"
do script "echo Installing Pygame Zero"
end tell
and it kinda worked, but it wasn't an executable
Then I tried with another approach found on google:
echo '#!/bin/bash
pip3 install pgzero
echo Installing PyGame Zero'> ~/Desktop/PygameInstaller.command
chmod 740> ~/Desktop/PygameInstaller.command
and it still didn't worked D:
Can someone land a bit of help? I'm starting feeling lost q,q
Thank you in advance!
In terms of what you want in your shell script, your first attempt is probably close to what you want but the echo should precede the pip3 command. I guess if you change the verb from Installing to Installed, then you could leave it where it is.
$ cat <<EOF > ~/Desktop/PygameInstaller.command
#!/bin/bash
echo Installing Pygame Zero
pip3 install pgzero
EOF
$ chmod 700 ~/Desktop/PygameInstaller.command
The permissions you assign to the script and the script's location depend on who you want to grant execution. If it's only you, then your desktop and 700 should be fine.
Now, if you want to execute the script from a command line like what you would see if you opened an instance of Terminal.app, then you have options.
If you want to fully specify the command, then you would type this (showing prompt which you would not type):
$ ~/Desktop/PygameInstaller.command
If you want to specify only the name of the script, then you would type this after adding ~/Desktop to your PATH:
$ PATH="$HOME/Desktop:$PATH"
$ PygameInstaller.command
If you prefer to type only PygameInstaller, then don't put the code in a file named PygameInstaller.command. Instead, you put the code in a file called simply PygameInstaller.
If you need the script to be executable by everyone, then put it in /usr/local/bin because most people will either have that in their PATH or have no political problem doing so. But you'll have to use the sudo command to elevate your privileges to accomplish that task.
If, however, you want to have that script be treated like any other app that you can launch with a double-click, then you have significantly more work to do.

How to run a bash script from github?

This question might be silly, and I think it is something so basic that I can't even find the solution because it might be obvious to everyone.
Here's the thing:
I want to download a file from mega.nz using bash.
I found this bash script on github: https://github.com/tonikelope/megadown/blob/master/megadown
I donĀ“t know how to run this
Tried:
Copy-pasting the file to a file called "megadown.sh" and then running:
$ bash megadown.sh 'https://mega.nz/#F!BwQy2IAS!AwWpbCPzgLf_5jyj76q7qw'
this returns:
Reading link metadata...
Oooops, something went bad. EXIT CODE (3)
Which tells me that at least the code is running, but I don't know if I am doing it correctly.
This is better than my previous attempt $ megadown 'URL' (as the documentation suggested), which resulted in "command not found"
First, make sure you have installed the dependencies:
sudo apt-get install openssl curl pv jq
Then try running this command:
bash megadown.sh -o FILE_NAME "LINK"
It will download the file specified by the URL to a file called FILE_NAME.

Auto confirm an apt prompt in Bash

I am trying to make a bash script that will auto confirm the apt prompt when installing a package.
Here is what I try to auto confirm, and yes, I already tried "-y".
sudo apt install matchbox-keyboard -y
My rasp is in french and it keeps telling me that "-y" isn't recognized. Of course, since my rasp is in french, the prompt gets confirmed when I write "O" instead of "Y", but since I want my script to work with every language, I am looking for a way to use "-y" even on a french machine.
Does anyone of you know how to force the english confirm on a foreign language machine ?
Thanks in advance !

interactive shell script for execution of sudo commands

I installed gcc 5.2 with gmp, mpfr and mpc, plus the isl and cloog optimizations, works perfectly. All prefixes are in /usr/local so that I have to sudomy make install's. I had to redo the same install on the computer of a friend, and now, I have to do it on another computer of mine... It's enough, so that I wrote a script. (And broke my "script whatever you have to do twice" rule.) My problem is that at some places of the script I have sudo make install commands, and that I don't want to run my script as admin.
How could I modify my script so that the following happens : before each sudo make install command one is asked to elevate permissions, and if one accepts, one is asked the root password, and then, sudo make install is executed, and after, the next commands are executed with "normal" permissions, until the next sudo make install, etc... ?
(I tagged make but the question is of course independant of it.)
sudo doesn't ask you for the root password, but your own; and it only does this when you haven't sudoed recently enough.
So just put sudo : at the top of the script: then it will ask for the password right away, and after it has been supplied, all the other sudo commands will execute without asking anything.

run bash script without input

I have written a bash script which installs a number of packages, however for each consecutive package installation i am promoted with the following message:
After this operation, 1,006 kB of additional disk space will be used.
Do you want to continue [Y/n]?
Is there a way of setting the default to Y so no user input is required? My script is expected to run at night without any intervention
thanks in advance
Two methods come to mind. The first (and better option) is to use the options in your package manager. For example:
apt-get install -y [YOUR_PACKAGE]
if you use apt (type apt-get install --help for more help there).
The second is more of a quick-'n-dirty one...use a pipe after yes:
yes | apt-get install [YOUR_PACKAGE]
which always brings a smile to my face :p
The latter option also answers yes to ALL other questions, which can be handy (errors etc.) but can be risky (which is the reason those questions are there in the first place!)
I think that message looks like you are using apt-get.
In that case you can use the flag --assume-yes or shorter: -y, which should automatically answer yes to that question without prompting the user

Resources