Skip to content

Commit

Permalink
Merge branch 'master' into rewrite-bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoneybun authored May 10, 2024
2 parents b5be1fb + 64fccef commit 96289ed
Show file tree
Hide file tree
Showing 83 changed files with 487 additions and 256 deletions.
165 changes: 165 additions & 0 deletions content/bash-scripting-basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
---
title: Bash Scripting Basics
description: >
Creating scripts using Bash.
keywords:
- bash
- script

facebookImage: /_social/article
twitterImage: /_social/article

hidden: false
section: about-your-os
tableOfContents: true
---

We will be writing a script for [BASH (Bourne Again Shell)](https://en.wikipedia.org/wiki/Bash_(Unix_shell)). There are many different languages and tools to create scripts for your tasks. Some languages are better suited for specific tasks than others. Bash is a great starting point, as it uses the same language as your built in terminal commands that already exist in your Linux OS.

**NOTE:** This tutorial assumes you are running Pop!_OS or Ubuntu, but the script will work on any Linux/Unix OS with Bash.

## Creating a working script

There are 2 important details for writing a Bash script that make it functional. The first is called the [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)). The shebang tells your OS what scripting language is being used (in this case, we are using Bash). The shebang is usually the first line in the script.

Open your text editor of choice (I will be using <u>gedit</u>, as it comes with Pop!_OS by default). In the text editor, add the following line to as the very first line in your script:

```
#!/usr/bin/env bash
```

The line above is the shebang. There are many ways to create scripts, and the shebang will be crucial for the OS to handle your script correctly.

Let's create a directory to save your scripts. This will keep your Home directory tidy, and also keep a dedicated place for things you are working on. In my case, I have chosen to create a directory named `scripts` in my Home directory. Next, let's save our script that we are writing to this newly created `~/scripts/` directory. You can name this script whatever you like, but for the sake of this tutorial, I am going to name this script `basics.sh`. Note that I gave the file a `.sh` extension. This is not necessary for the script to work, but it will help you as a user know that this is a Bash script because it ends with `.sh`. Other scripting languages use similar naming conventions (Python scripts end with `.py`, or LUA scripts end with `.lua`).

The second crucial detail for your OS to properly run your script is to make it executable. As of right now, your script is just a regular text file. In order for your OS to run your script, we will need to make this text file executable. This can be done by navigating to our `~/scripts/` directory with our File Manager. Once you locate your script file, right click on the file to bring up with context menu and select "Properties". This will bring up the various details about the file we are looking at. Click on the tab labelled "Permissions". There will be a checkbox labelled "Allow executing file as program". Make sure to check this box. Once this is enabled, the script will be able to run.

At the moment, the script will do nothing if we decided to execute it, so let's add some commands and then test our script. Open the script and add the following line below your first `shebang` line:

```bash
echo "The script executed correctly."
```

We can now attempt to run our script. Open the terminal from your Application Launcher. I am going to assume that you have followed along and created a directory in your Home directory called `scripts` and that you have named this script `basics.sh` (if you have placed it in a separate directory or named it differently, the steps are the same, but you must substitute the file names and paths). First, we need to navigate in our terminal to our `scripts` directory. Input the following command in your terminal to change directory to `~/scripts`:

```bash
cd ~/scripts
```

You can now run your script by running the following command in your terminal:

```bash
./basics.sh
```

If it worked, your terminal should output the following line:

`The script executed correctly.`

Congratulations! You have created a working Bash script. Of course, outputting a single line does not provide much functionality, so we will be doing just that in the next section.

## Adding functionality

At this point, our script does one thing: It outputs a single line in our terminal. The script works, but it isn't very useful yet. There are many things you can do with a script, especially once you start combining several commands together. Here are some websites that can be helpful in the search for more commands:

- [Stack Overflow](https://stackoverflow.com)
- [AskUbuntu](https://askubuntu.com)

Once you find commands that you want to add to your script, you can run them in a terminal to test them and see how they work.

It may also be helpful to read the *manual pages* (often shortened to "man pages") for commands that you're using. To view a command's manual page, simply run `man command` where "command" is substituted for the command you are looking up. To exit the manual page viewer, hit the `q` key.

### Variables

Let's start with asking the user for information like their name and favorite color. In order to output this information, we will need to first ask for this input, and then after it is input, we will store the information into a `variable`. Variables can hold values, and can be changed after the variable is created, so you can adjust values later on.

In our script file, we should have 2 lines already created: the shebang and our `echo` command that outputs a line. Let's change the `echo` command to match the "theme" of our script. Open the script in your text editor and edit the 2nd line with the `echo` command to ask the user for their First Name:

```bash
echo "What is your first name?"
```

Next, we will be using the `read` command to allow the user to input text. The text they enter will be stored in a variable that we can choose the name of. In this case, we will call the variable `firstName`. You can name the variable whatever you would like, but be sure to adjust your script accordingly. In our text editor, create a new line below our first `echo` command and input the following line:

```bash
read firstName
```

If we were to run our script in our terminal, it will first output a line that asks "What is your first name?". It will then sit and wait for the user to input text. Once the user inputs text and presses Enter, the script will end. We have not given the script any commands to use this information that the user has input. Let's add some output that shows what the user has typed in their terminal. Add a new line to your script:

```bash
echo "Your first name is: $firstName"
```

Notice that in order to use our `firstName` variable, we use the `$` in front of it. This will tell our terminal that we intend to use the variable called `firstName`. If I were to run the script, it will ask for my first name. I will input the name "Garrett", and the script will then output the following line:
`Your first name is: Garrett`

Now, let's add another question to this script. This time, we will ask for the user's favorite color. We will then use the `read` command again to get user input and store it in a variable called `favoriteColor` and then finally output a sentence that shows what the user input:

```bash
echo "What is your favorite color?"
read favoriteColor
echo "Your favorite color is: $favoriteColor"
```

At this point, you should have a working script that asks the user for their name and their favorite color and then reacts to this information by outputting a sentence that reflects this information. The full script at this point should look like this:

```bash
#!/usr/bin/env bash
echo "What is your first name?"
read firstName
echo "Your first name is: $firstName"
echo "What is your favorite color?"
read favoriteColor
echo "Your favorite color is: $favoriteColor"
```

### If-Then Statements

Sometimes we want different things to happen depending on what inputs/variables are stored. For instance: if a file exists, then do *a*, but if the file does not exist, then do *b*. Or if a number is higher than *x* then do *a*, but if the number is lower than *x*, then do *b*. We can do this with an `if` statement.

For this, we will be asking the user to input a number. If the number is higher than *x* we will do *a*, but if the number is lower than *x*, we will do *b*.

Add a new line to your script. We will be making the target number 23, but you can pick any number you want. We will be putting the target number into a variable called `targetNumber`. Add the following line to your script:

```bash
targetNumber=23
```

We will now ask the user to input a number, and store that number to a variable called `guess`. Add the following lines to your script:

```bash
echo "Guess the number:"
read guess
```

We now need to create and `if` statement to compare the `targetNumber` to the user input `guess` variable. The script will output different sentences depending on whether the user is too low, too high, or if they guess correctly. Add the following lines to your script:

```bash
if [ $guess == $targetNumber ]
then
echo "You guessed the correct number!"
elif [ $guess -lt $targetNumber ]
then
echo "You guessed lower than the target number."
elif [ $guess -gt $targetNumber ]
then
echo "You guessed higher than the target number."
else
echo "Something went wrong."
fi
```

If you run the script, it will ask the user for their name and their favorite color. It will then ask the user to input a number. After the user inputs the number, depending on whether it was lower, higher or correct, the script will dynamically adapt to the user input.

## Conclusion

Bash scripting can be very useful in many different cases. I use scripting to automatically create a new work note with the current date as the title of the note document. I also have scripts to open certain applications or change my desktop theme. I have developed scripts to convert audio files to a specific format, or fill out PDF documents quickly. There is a lot to learn, so don't get discouraged or frustrated. Try to keep at it. As you make mistakes, you will learn for the next script you write. There are so many resources to help with your project. I have listed a few places to help with this below.

## Useful places to find information

Scripting can get advanced and complicated very quickly. There are numerous resources online for tips, tutorials, and forums to get help. Here are a few places to find ideas:

- [GNU Bash Manual](https://www.gnu.org/software/bash/manual/bash.html)
- [Pure BASH Bible - Dylan Araps](https://github.com/dylanaraps/pure-sh-bible)
- [Free Code Camp - Bash Scripting](https://www.freecodecamp.org/news/bash-scripting-tutorial-linux-shell-script-and-command-line-for-beginners/)
2 changes: 1 addition & 1 deletion content/boot-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The BIOS or boot menu can be accessed by holding specific keys down during boot.

| Model | BIOS key | Boot Menu key |
|:-----------------------------------------------------------:|:--------:|:---------------------------------:|
| Laptops:<br/>All Open Firmware models<br/>Pangolin (pang12) | ESC | ESC:<br/>Select `One Time Boot` (Open Firmware)<br/>or `Save & Exit``Boot Override`. |
| Laptops:<br/>All Open Firmware models<br/>Pangolin (pang12 and above) | ESC | ESC:<br/>Select `One Time Boot` (Open Firmware)<br/>or `Save & Exit``Boot Override`. |
| Laptops:<br/>Most proprietary firmware models | F2 | F7 |
| Older laptops | Depends on the system | F1 |
| Thelio desktops | Del | F8/F11/F12 |
Expand Down
12 changes: 7 additions & 5 deletions content/desktop-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Pop!\_OS and Ubuntu both include the GNOME desktop environment by default. A des

You can install an alternative desktop environment using the instructions below.

**NOTE:** be careful when installing other desktop environments, as they may affect the default GNOME desktop (both Ubuntu and Pop).
> **Warning:** Installing other desktop environments may affect the visual style and functionality of the default GNOME desktop (on both Ubuntu and Pop!_OS).
If you run into trouble while using an alternative desktop environment, you may wish to revert to the default environment. To ensure the default GNOME desktop environment is installed in Pop!\_OS, install the `pop-desktop` package:

Expand Down Expand Up @@ -229,14 +229,16 @@ gsettings set org.cinnamon.desktop.lockdown disable-lock-screen false

### Removing Desktop Environments

If you no longer want to use a desktop environment, it can be removed by using:
If you no longer want to use a desktop environment, it can be removed by using the `sudo apt autoremove --purge` command with the name of the package you originally installed. For example, if you installed LXDE with `sudo apt install lxde`, you can remove it using the following command:

```bash
sudo apt autoremove --purge ...
sudo apt autoremove --purge lxde
```

For example, to remove KDE:
Some desktop environments (such as KDE) may leave behind additional packages even after uninstalling the original package with the `autoremove` command. To more thoroughly remove packages related to a desktop environment, use a regular expression to remove all packages beginning with the name of the environment followed by a hyphen (for example, `kde-`):

> **Warning:** Because regular expressions can match packages you don't expect, inspect the list of packages being removed before confirming the operation, and be prepared to reinstall any packages you wish to keep afterwards.
```bash
sudo apt autoremove --purge kde-standard
sudo apt autoremove --purge 'name?(^kde-)'
```
8 changes: 4 additions & 4 deletions content/difference-between-pop-ubuntu.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ While Pop!_OS is designed to be [easy to use](https://www.forbes.com/sites/jason

The installer offers encryption out of the box and takes care of setting up your user preferences (language, keyboard layout, installation method). On first use, the installer also makes it easy to select your time zone and integrate any online accounts into your desktop.

![Intel/AMD + NVIDIA](/images/difference-between-pop-ubuntu/intel-amd-nvidia-1904.png)
![Intel/AMD + NVIDIA](/images/difference-between-pop-ubuntu/intel-nvidia-rpi.png)

Pop!_OS comes in two versions: Intel/AMD and NVIDIA. This allows us to include different settings, and the proprietary NVIDIA driver for NVIDIA systems. Ensuring the best performance, and use of CUDA tools is one command away.
Pop!_OS comes in two versions: Intel/AMD and NVIDIA. This allows us to include different settings, and the proprietary NVIDIA driver for NVIDIA systems. Ensuring the best performance, and use of CUDA tools is one command away. Pop!_OS also provides an ISO for the Raspberry Pi 4.

## Privacy

Expand All @@ -47,7 +47,7 @@ With encryption enabled by default, and reporting through Ubuntu disabled, Pop!\

## Custom Keyboard Shortcuts

After conducting a study of Ubuntu and GNOME keyboard shortcuts, we decided to make some shortcuts more efficient for common user behaviors. The shortcut for switching workspaces, for example, is <kbd>Super</kbd> + <kbd>Arrow</kbd> <kbd>Up</kbd> or <kbd>Down</kbd>.
After conducting a study of Ubuntu and GNOME keyboard shortcuts, we decided to make some shortcuts more efficient for common user behaviors. The shortcut for switching workspaces, for example, is <kbd>Super</kbd> + <kbd>Ctrl</kbd> + <kbd>Arrow</kbd> <kbd>Up</kbd> or <kbd>Down</kbd>.
[See all keyboard shortcuts](/articles/pop-keyboard-shortcuts/)

## Default Apps: Slimming down on bloatware
Expand All @@ -71,4 +71,4 @@ Pop!\_OS is built from Ubuntu repositories, meaning you get the same access to s

## Recovery Partition

The recovery partition on this operating system is a full copy of the Pop!\_OS installation media. It can be used exactly the same as if a live disk copy of Pop!\_OS was booted from a USB drive. The existing operating system can be repaired or reinstalled from the recovery mode. You can either do a refresh install, which allows you to reinstall without losing any user data or data in your Home folder. You can otherwise opt to do a fresh install, which will recreate the partitions and files to reset data. Refresh Installs are only available on a fresh install of either Pop!\_OS 19.04 and newer (18.04 has this feature backpored in lastest releases of the ISO). To learn more about the Recovery Partition read about it [here](/articles/pop-recovery/).
The recovery partition on this operating system is a full copy of the Pop!\_OS installation media. It can be used exactly the same as if a live disk copy of Pop!\_OS was booted from a USB drive. The existing operating system can be repaired or reinstalled from the recovery mode. You can either do a refresh install, which allows you to reinstall without losing any user data or data in your Home folder. You can otherwise opt to do a fresh install, which will recreate the partitions and files to reset data. Refresh Installs are only available on a fresh install of either Pop!\_OS 19.04 and newer (18.04 has this feature backported in lastest releases of the ISO). To learn more about the Recovery Partition read about it [here](/articles/pop-recovery/).
12 changes: 10 additions & 2 deletions content/fix-pvpn-killswitch.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ tableOfContents: true

ProtonVPN's kill switch will disable internet connectivity when you are not connected to a VPN server. This ensures the true IP address if your computer is never leaked to the internet. If the kill switch is set to `Permanent`, then your computer will be unable to connect to the internet, even if ProtonVPN isn't running (i.e., at system start up), the GUI application becomes inaccessible, or if ProtonVPN was improperly removed from the system.

![ProtonVPN Kill Switch](images/fix-pvpn-killswitch/proton-killswitch.png)
![ProtonVPN Settings](images/fix-pvpn-killswitch/ProtonVPN-Settings.png)

> ℹ️ ProtonVPN installs to the entire system; not just for a single user. If ProtonVPN is installed under another user account and has the kill switch enabled, other users will not be able to connect to the internet until ProtonVPN connects to a server.
![ProtonVPN Kill switch](images/fix-pvpn-killswitch/ProtonVPN-Killswitch.png)

> **NOTE:** ProtonVPN installs to the entire system; not just for a single user. If ProtonVPN is installed under another user account and has the kill switch enabled, other users will not be able to connect to the internet until ProtonVPN connects to a server.
<!-- v4 of ProtonVPN does not have a CLI version like v3 did per this support article: https://protonvpn.com/support/linux-vpn-setup/
We can enable this again (with new option(s) as needed when it is available again) .
## ProtonVPN GUI Application is Inaccessible
Expand All @@ -33,6 +39,8 @@ If the ProtonVPN GUI application suddenly becomes inaccessible, but you still ha
protonvpn-cli ks --off
```
-->

## Permanent Kill Switch Persists After System Refresh

Pop!\_OS's [Refresh Install](/articles/pop-recovery) feature is a convenient tool for recovering a broken installation while preserving some of the user's data.
Expand Down
12 changes: 4 additions & 8 deletions content/graphics-switch-pop.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ description: >
keywords:
- System76
- Pop
- 18.04
- 19.10
- 20.04
- 20.10
- 21.04
- 21.10
- 22.04
- 24.04
- NVIDIA
- Hybrid
- Integrated
Expand All @@ -28,12 +24,12 @@ tableOfContents: true
Many modern laptops with NVIDIA graphics cards have switchable graphics, which allows users to switch their primary GPU between the CPU's integrated graphics processor and the dedicated NVIDIA graphics card.
The following System76 laptops have these switchable graphics capabilities:

- Adder WS (addw1, addw2, addw3)
- Adder WS (addw1 and newer)
- Bonobo WS (bonw15)
- Galago Pro (galp5 - NVIDIA models only)
- Gazelle (gaze14, gaze15, gaze16, gaze17, gaze18)
- Gazelle (gaze14 and newer)
- Kudu (kudu6)
- Oryx Pro (oryp4, oryp4-b, oryp5, oryp6, oryp7, oryp8, oryp9, oryp10, oryp11)
- Oryx Pro (oryp4 and newer)
- Serval WS (serw13)

Pop!\_OS includes utilities for switching between these modes, which you can learn more about below.
Expand Down
Loading

0 comments on commit 96289ed

Please sign in to comment.