Skip to main content

Automating My Linux Setup With Bash Scripting

I recently made a blog post about automating tasks with bash scripts and why it can be useful. I just finished a script that can (mostly) automate my setup in Linux.

The script is called setup.sh, and can be found on my Github repo.


Virtualbox: My Testing Environment

I wanted to test my script in a controlled environment, and decided to use Virtualbox to setup a virtual environment to work in. Virtualbox also gave me the option to create snapshots of my virtual machine. When my script made changes to my machine, I could easily go back to a previous version and undo the changes.

Here is a good resource if you want to learn more about virtual machines.


Vagrant: Automated Virtual Machines

 I didn't want to go through the process of setting up a virtual machine and having to install an operating system manually, so I automated this with Vagrant. I didn't know anything about Vagrant before this project, but I found a video on YouTube that did a good job at helping me get started: Automated virtual machine deployment with Vagrant 

Vagrant Boxes

Vagrant uses "boxes", which is a package format that is used to setup the environment. Here is the one I used:

Using the command vagrant init ubuntu/focal64 created a Vagrantfile with the necessary configurations to get my machine up and running.


After making changes to my Vagrantfile, I tried running the vagrant up command, and got an error:

Vagrant was having trouble starting the virtual machine from the command line, so I started it manually through the Virtualbox GUI, and that worked.

The setup script is simple; lets take a look at it:

1. First I start by updating my repositories. Repositories are a useful resource in Linux distributions that allow us to search and download applications. Making sure these are up to date is important before upgrading our system. The sudo command allows a user to run a command with root privileges. Windows users might know this as Administrator privileges. Apt is the package manager for my operating system.

2. After updates are done, I install any software that I need.

3. These two commands look confusing, so here is a breakdown at whats going on:

the ln command can create links between files, or in other words, a shortcut. My original file vimrc is located in the directory (folder) called dotfiles, which is inside a directory called linux_files. The symbol ~/ at the beginning of the command just refers to my users home directory (Here you'll have your pictures, downloads, documents, etc). Here is the command in plain English:

ln command /path/to/original_file /path/to/my_shortcut.

The echo command prints out text to my terminal. It can be a useful way to give yourself context to what's going on.

Here are some additional resources if you want to learn more:

- What is a package manager?

- Hard and soft links

 

Running The Script

At the beginning of this blog post, I said that this script would mostly automate my setup. The reason for this is because when I install Oh My Zsh, it has to run its own script that the user has to interact with. I have the installation towards the end of my script, so it isn't a big deal for now. After making revisions, the script was ready to run:

The script ran successfully! That's it for now. Give bash scripting a shot; you might like it.

Comments

Popular posts from this blog

Download Files With JDownloader: A Basic Guide

 JDownloader is a download management tool that has many features, such as allowing users to download multiple files from websites, setting bandwidth limitations, automatically extracting archives, and much more. This blog post will be a basic rundown of the software's functionality, and not an in-depth guide. Let's get started.   Downloading JDownloader JDownloader has a few different download options for various operating systems, such as Windows, Linux, MacOS, and a few other options. Pick the one that corresponds with your operating system. - Link to downloads page Since I'm using Linux Mint , I decided to check if it was available as a Flatpak . Luckily for me, it was! I installed it with the following command: flatpak install org.jdownloader.JDownloader   Starting Up JDownloader This is what the program looks like once it starts up: It can look confusing and overwhelming with all the text and buttons, but I'll guide you through some of the options. We are curren...