on a script
here is what I am doing. My disclaimer is that my scripting knowledge is sketchy, but what I create works. If there is a better way or I am in error, I invite jas
@JasKinasis to qualify. Jas is the man for scripting, lol.
Start by assigning a spot to house your custom-built scripts.
Many use /usr/local/bin. If you are one who takes their home folder or partition with them to use in another distro, you could store it in home.
If you use /usr/remainder_of_path bear in mind that is under root control. Home is always available to the designated user. If you have other users on the computer, you may consider housing scripts in a /share/ subfolder.
For this exercise, I am generating a script called bravedeb.sh – so named because I will also make ones called braverpm.sh and bravearc.sh for rpm-based and arch-based distros I use. I am going to create a folder in home called bin – you might choose bin/scripts, or other, just make the adjustments below.
For our shell – in most cases, bash – to locate and execute our scripts, where we store them should either be in our Path, or added to our Path. To see your current path, type and enter, in terminal
echo $PATH
mine in linux mint 19.3 ‘tricia’ cinnamon looks as follows – the entries are separated by a colon :
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
STAGE 1
STEPS TO CREATE OUR SCRIPT FILE
1. in a fresh instance of terminal, type and enter as follows:
echo $PATH
mine shows as follows, yours may differ
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
2. making the folder to store the script/s -
mkdir bin
3. create an empty file for the script
touch bin/bravedeb.sh
4. open the file with a text editor – I will be using nano, but if you prefer gui-based you could use xed in mint, or gedit in ubuntu, kate in a kde environment. If so, just call it from terminal (needs sudo) so that when you exit the editor, you are returned to terminal.
nano bin/bravedeb.sh
5. copy the text nik-ken-bah had above, which you can also find at
https://brave-browser.readthedocs.io/en/latest/installing-brave.html#linux
and use ctrl-shift-v to paste it into the nano shell, or just ctrl-v if using a gui-based editor.
Again, that text was
sudo apt install apt-transport-https curl
curl -s
https://brave-browser-apt-release.s3.brave.com/brave-core.asc | sudo apt-key --keyring /etc/apt/trusted.gpg.d/brave-browser-release.gpg add -
echo "deb [arch=amd64]
https://brave-browser-apt-release.s3.brave.com/ stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt update
sudo apt install brave-browser
6. navigate to the top of your text editor, and at ‘s’ for sudo, place at least 2 enters to get a couple of lines
7. with the first line enter
#!/bin/bash
this tells linux that it is dealing with a bash script, and it is the only line starting with a hash that linux takes notice of.
I then type in a couple of lines prefaced with a hash, which means they are explanatory comments – helpful for others who use the script, or you if you forget, lol.
Including those comments, my final text for the script looks as follows:
#!/bin/bash
# A script to install Brave Browser on Debian-based Distros
# My first script for the folks at linux.org
# Written by wizardfromoz 20/03/11 ... enjoy your Linux!
# Source code from
https://brave-browser.readthedocs.io/en/latest/installing-brave.html#linux
sudo apt install apt-transport-https curl
curl -s
https://brave-browser-apt-release.s3.brave.com/brave-core.asc | sudo apt-key --keyring /etc/apt/trusted.gpg.d/brave-browser-release.gpg add -
echo "deb [arch=amd64]
https://brave-browser-apt-release.s3.brave.com/ stable main" | sudo tee /etc/apt/sources.list.d/brave-browser-release.list
sudo apt update
sudo apt install brave-browser
8. save and close the file and its editor and you will be returned to your terminal prompt.
In nano, this is done by
pressing ^x (ctrl-x)
which returns
Save modified buffer? (Answering "No" will DISCARD changes.)
enter uppercase Y for yes
which returns
File Name to Write: bin/bravedeb.sh
if you want to do a save as feature or name it something completely different now is your chance. Otherwise press enter.
9. now we need to make our script executable. We can look at its attributes and permissions with
ls -l bin/bravedeb.sh
which for me returns
-rw-r--r-- 1 chris chris 656 Mar 11 16:10 bin/bravedeb.sh
which shows me the file, 656 bytes in size, created today, can be read and written to by root, read by me and read by others.
To make that simply executable, for now you could use the command
sudo chmod +x bin/bravedeb.sh
which with the ls -l command would return
-rwxr-xr-x 1 chris chris 656 Mar 11 16:10 bin/bravedeb.sh
which means that root can read, write and execute the file, I can read and execute but not write to it, and other users can read it and execute it.
That will do if you want to just install the Brave Browser, and if so, skip now to the next step.
I, however, may wish to alter the script later, so I am using
sudo chmod 775 bin/bravedeb.sh
which, using our ls, returns
-rwxrwxr-x 1 chris chris 656 Mar 11 14:15 bin/bravedeb.sh
… what I desire.
10. Check using terminal or your file manager that all is in order and where it should be. If using your file manager, you can right-click the file and check its properties to see that it is executable.
Then move on.
STAGE 2
STEPS TO ACCESS THE SCRIPT FROM ANYWHERE IN TERMINAL (OPTIONAL)
if you are in /var reading logs, or /usr exporting .jpegs to .png backgrounds ala wallpapers, you may decide you wish to install Brave Browser using the script.
You can either add it to your Path, or else choose the full path for the script.
If the latter then simply type an enter
sudo /home/your_username/bin/bravedeb.sh and away you go.
i’ll stop here for now, so the op can do so if he wishes, and be back with stage 2 (thankfully short, lol) in 24.
wizard