Automatically Configuring Ubuntu 20.04

I find myself constantly installing new Ubuntu Desktop operating systems; from testing something in a VM, to updating one of my computers or reformatting my main.  Reinstalling and configuring the same thing over and over gets tedious.  So, why not automate the process?

I have set up a repository that contains two bash scripts; one for escalated privileges (installing packages) and one user changes.  Using these two scripts as a basis, I am have an almost complete system for me to get up and go.  After these scripts I would merely have to log into my services.

Privileges Script ( Explained

This script follows a basic step-by-step process. It can be easily replicated and reproduced.  It is ordered as such:

  1. Update and Upgrade the operating system
  2. Install snaps
  3. Install repository packages
  4. Download and install manual packages
  5. Fix missing dependencies

Using the below sections you can easily make your own script.  You can think of this as one of your most basic automation projects!

This script will not include the "sudo" aspect of each command because the script itself will be run with "sudo".  That is why this is the escalation script.

Update and Upgrade the Operating System

If you have ever installed a package or followed a tutorial using the command line you have probably seen these.

Update the repositories (update), install the new version of the packages (upgrade) then clean up unnecessary packages (autoclean)

echo =========================
echo ==== Updating Ubuntu ====
echo =========================

apt-get update
apt-get upgrade -y
apt-get autoclean
The echo statements are just outputs to the console signifying what section is processing. 

Install Snaps

According to Canonical's Snapcraft, a "_snap is a bundle of an app and its dependencies that works without modification across Linux distributions"._

Installing the Discord snap looks like this.

echo =!=!=!= INSTALLING Snaps =!=!=!=

echo ============================
echo ==== Installing Discord ====
echo ============================

snap install discord

Rinse and repeat for any snaps you wish to install.  If you are curious if a snap is available visit snapcraft.  If you click the install button on an application page it will even tell you what the command is to install.  

Note that we do not require sudo within the script. The important part is the package name.

Install Repository Packages

Grab those packages from the Ubuntu repositories the old school way.

echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
echo =!=!=!= INSTALLING Packages =!=!=!=
echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=

echo ==============================
echo ==== Installing flameshot ====
echo ==============================

apt install flameshot -y
The "-y" is to automatically "yes" the prompt to install the required dependencies

I found some applications work better through the repository packages (or third party ppas) as they use the OS resources better than the container resources.  Two examples of this are Flameshot and Rambox.  In both cases, they reference container resources instead of the base operating system.  Rambox seems to crash when I try to access photos to upload.  I assume this may be the cause.  Repos live on...

Download and Install Manual Packages

Change to the correct directory, download the correct package and install the package!

echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!
echo =!=!=!= INSTALLING Manual Packages !=!=!=!
echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!

echo =======================================
echo ==== Moving to Downloads directory ====
echo =======================================

# executed with sudo, use absolute path!
cd /home/seanland/Downloads/

echo ==========================
echo ==== Downloading Zoom ====
echo ==========================


echo =========================
echo ==== Installing Zoom ====
echo =========================

dpkg -i zoom_amd64.deb

Once that is done...

Fix Missing Dependencies

The manual packages will not be installed with their dependencies.  By running the below command it will install all broken packages by installing their missing dependencies.

echo ====================================
echo ==== Fixing Broken Dependencies ====
echo ====================================
sudo apt --fix-broken install -y

User Changes Script ( Explained

This is the script that is run without using escalated privileges.  It is execute to modify the local user's workspace.  I have set my user changes script into two sections:

  1. Automated Configuration
  2. Manual Configuration

Automated Configuration

Gsettings can be used to manipulate the application settings within gnome.  If you see below the settings can be accessed via the command line.  Here are a few examples of the ones I use in my script.

echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
echo =!=!=!= Automated Configuration =!=!=!=
echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=

echo ======================================
echo ==== Setting Dash Icon Size to 24 ====
echo ======================================

gsettings set dash-max-icon-size 24

echo ================================
echo ==== Setting Favourite Apps ====
echo ================================

gsettings set favorite-apps "['vivaldi-stable.desktop', 'org.remmina.Remmina.desktop', 'atom_atom.desktop', 'gimp_gimp.desktop', 'rambox_rambox.desktop', 'moonlight_moonlight.desktop', 'vlc_vlc.desktop', 'filezilla.desktop', 'org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop', 'flameshot.desktop', 'putty.desktop', 'Zoom.desktop']"

Essentially this portion of the script resizes the icons on the dock and sets which icons are included on the dock.  No more, adding each applications to favourite!

You can see which gsettings are available in a gui form by using dconf-editor.  At the same time, you can also manipulate them in that tool.

Manual Configuration

The part of automation no one likes.  The stuff you don't or can't automate!  But, you can make it easier.  I like to add a little section for the manual steps I have to complete after the scripts have run.  It just makes life a little easier.

echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
echo =!=!=!= Manual Configuration Required =!=!=!=
echo =!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=

#, in order to automate shortcut.

echo 1. Remove print hotkey for screenshot
echo 2. Set flameshot gui as print shortcut
To be honest, this can be automated. I just haven't gotten around to doing it.

These two scripts alone can save quite a bit of time on a new install, especially if you are installing a large number of apps.  Make your life easier!  One reason to be less afraid of formatting your machine.