I did something similar as I install to two computers and every 6 months with multiple installs of the next version.
All I did was run the command from command line and then list history. Then copied history to bash file. Of course I had a lot of typos errors in my command line, but it let me test & verify which lines really worked.
I wanted to find some checking and add some distribution based variables. You then can add whatever works.
#!/usr/bin/env bash -x
# -x adds debugging mode set +x or set -x
# Repositoires - Normally users have the first 4 enabled - main, universe, multiverse, restricted
# Check if we are on Ubuntu
if [ "$(lsb_release -is)" != "Ubuntu" ] ; then
echo "This script is only intended to run on Ubuntu"
# Check if we are root
if [ $UID -ne 0 ] ; then
echo "Please run this as root!"
# Get distro
#save your original sources.list file.
echo "Backing Up The sources.list"
cp -i /etc/apt/sources.list /etc/apt/sources.list_backup
#this updates everything
#would upgrade you to the latest kernel in the repositories