How to script general configuration after install


I have a number of Raspberry Pi (and Pi 2) installs of OSMC around my house and every now an again something tends to go wrong with an install - bad update, bad SD card etc.

I’ve had limited success with SD Card backups in the past due to the problems with some SD cards being bigger than others (so restores fail).

Therefore, what I’d like to do is get most of my common setup scripted so that a fresh install is ready for primetime with minimal effort.

Things that I’d like to script:

  1. Install the latest updates
  2. Add file locations for add on repositories
  3. Add file locations for my media (external NAS connected via SMB/CIFS)
  4. Install favourite addons
  5. Set the device name (prompted by script?)
  6. Scan the media libraries

Ideally, I’d like to just copy a script across to a new install then SSH in to run and leave it to do its thing.

Has any got an example script that they can share?


You would just need to make a backup of your home directory and do an apt upgrade:


sudo apt-get update
sudo apt-get dist-upgrade
cp -r /path/to/backup/home/osmc /home/osmc

Thanks @mcobit.

I assume that you are suggesting that I can take a backup of the home directory from one installation and overwrite it in a new install? And that this will include all virtual folders, login credentials, media library indexes?

Can you set the device name via the command line (preferably prompting the user or by feeding it in as an argument to the script)?

I’m assuming that there is nothing specific in the home dir that would be different between Raspberry Pi 1 & 2?

I’m also assuming that if I take a home dir backup from a fully up-to-date install and overwrite to a fully up-to-date install, then the chances of hitting an incompatibility are nil?

Many thanks,