Automating PC setup after fresh OS install

I have been using the company’s laptop for work since a long time, and I wanted to set up my own work environment. I do not own a laptop of my own and hence I had to use a PC that was laying around. So, I had to set up everything on my PC again.

I knew that in some time again, I will have to get a new laptop and I would have to do the entire setup again. So, to save the time to do all the setup again, I thought I should automate the entire process.

Who is this for?

If you are a software developer or someone interested in learning how you can automate things on your computer. If you wish to explore code and how using basic Linux tools, you can take advantage of automation.

What am I automating?

For now, I just want to automate the setup of my work environment so that I can just follow a few steps and have the same environment across any device.

So, here are the items that I am going to automate setup:

  • Install required tools
  • Perform any setup steps required for my tools
  • Load all the dotfiles for my tools

Current script and its status


# Install software
tools=$(tr '\n' ' ' < tools.txt)
sudo pacman -S $tools --needed --noconfirm

# Git setup
git config --global "Vivek Agrawal"
git config --global ""
git config --global init.defaultBranch main

# Manage and setup Dotfiles
read -p "Github Dotconfig Repo: " dotconfigRepo
git clone --bare $dotconfigRepo $HOME/.dotconfig 2> /dev/null

shopt -s expand_aliases
alias dotconfig='/usr/bin/git --git-dir=$HOME/.dotconfig/ --work-tree=$HOME'

dotconfig checkout 2> /dev/null || false

if [ $? -ne 0 ]; then
    dotconfig checkout 2>&1 | awk 'gsub(/^\s+|^\w.\s+/, ENVIRON["HOME"] "/", $0)' | xargs -I{} rm {}
    dotconfig checkout

dotconfig config --local status.showUntrackedFiles no

# Setup Doom Emacs
git clone --depth 1 ~/.config/emacs
~/.config/emacs/bin/doom install

# Setup tmux
git clone ~/.tmux/plugins/tpm

In the current script, I am first installing all the tools required by reading them from a file.

Next, I am setting up git on my system with the basic steps required.

After git is set up, I can download all my dotfiles and put them in proper place using a git bare repository. More about it later on.

Then, I set up two more tools:

  • Emacs
  • Tmux

Of course, there is a lot more work left on this, but this is just the basic.

What I learnt during this process

  • A lot of things can be automated via shell scripts
  • It is pretty simple to read files in shell using just the < operator
  • If a tool/software exists in the list of tools supported by your installer (pacman in my case), you can automate its installation
  • Every software follows a different installation and setup process
  • Taking user inputs from the shell is pretty simple. Just use the read command
  • aliases created in a script aren’t available in the scope of the script by default.
  • We can handle errors during program execution in the script
  • awk is a great text manipulation tool where we can search and replace strings with regex
  • regex is not for the light-hearted. It takes A LOT of hard work to get it right and it’s complicated
  • It is a great idea to manage all your config files in version control to make any tool grow along with your workflow
  • One should be familiar with vi as it is a great tool to learn and one feels comfortable no matter what system one is in
  • Having multiple terminals is A MUST. Otherwise going into different folders and typing commands over and over again takes up a lot of time

Future plans

In the future, the script will be broken down into multiple scripts where the setup for each tool will be in its own script to provide modularity to the shell script.

I will also add custom aliases, shortcuts and other key bindings required for OS level operations.

Till then, hope you had fun reading this article 😀 !

Automating PC setup after fresh OS install

One thought on “Automating PC setup after fresh OS install

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top