Ubuntu – How to make post-install scripts


How do I make post-install scripts so when I reinstall ubuntu everything is as I want it?

Things I want to achive:

  • Installing PPA
  • installing my programs
  • themes needs to be installed
  • Settings needs to be changed (power management, short commands, startup applications, etc.)
  • system reboots

Best Answer

Easiest way is to gather all the commands you need and put them in a text file and make the text file executable.

We start out with going command line and do this:

touch post_install_script
sudo 775 post_install_script
gedit post_install_script

And you start putting in commands you want to be executed.

Installing packages that are in Ubuntu Software Center.

Start with enabling all repositories and refreshing the software list because the LiveCD is outdated:

sudo sed 's/# deb/deb/' -i /etc/apt/sources.list
sudo apt-get update

Look up inside USC what already is there and check the package name. Examples with VLC and smplayer:

sudo apt-get install vlc
sudo apt-get install smplayer

In the same way of adding software like this you can also remove packages with:

sudo apt-get remove {package_name}

(just be careful to check dependencies first)

PPA for installing nautilus elementary:

sudo add-apt-repository ppa:am-monkeyd/nautilus-elementary-ppa
sudo apt-get update && sudo apt-get upgrade


Those are either in USC or have a PPA so you can add these with either one of the 2. For instance I like the equinox themes and I can add them like this:

sudo add-apt-repository ppa:tiheum/equinox
sudo apt-get update && sudo apt-get install gtk2-engines-equinox

or the Faenza icon sets:

sudo add-apt-repository ppa:tiheum/equinox
sudo apt-get update && sudo apt-get install faenza-icon-theme

So you gather all the installation instructions that you want to add and put them in your script each on a new line. You can speed things up by removing duplicate entries: sudo apt-get upgrade does not need to be done with every PPA: you can do that after adding all the PPAs but(!) before you install the software from the PPA.

Theoretically you can have 1 of these script files for all Ubuntu installations but you might need to tweak them for every system.

This is my newest attempt to creating a post install script:

enter image description here

What does this do?

  1. update sources list
  2. remove all directories in my home and create them again in /discworld2/ After that I recreate my home directory directories using symlinks. This way I am able to format my home and keep my files (they are not only on another partition but even on another disc);
  3. install software I want;
  4. set power management the way I want it.
  5. add ppa's I want

After installing I just execute my post_install file and it will run for a long time but it will take care of everything I want (well I will be adding more and more things over time so it will get longer).

I probably can improve it by making compound statements of some of these lines

Related Question