Automated reinstall of software from package list

If I need to reinstall a Ubuntu/Debian-based Linux OS (or mirror a software selection to another machine), this is how it can be done. On the source machine:

su
dpkg --get-selections > ~/Package.list
cp -R /etc/apt/sources.list* ~/
apt-key exportall > ~/repository.keys

Then just copy the files to the target machine:

su
apt-key add ~/repository.keys
cp -R ~/sources.list* /etc/apt/
apt-get update
apt-get install dselect
dselect update
dpkg --set-selections < ~/Package.list
apt-get dselect-upgrade -y

If some packages are not available, this will fail. This concerns in my case manually installed packages like teamviewer or snapgene/snapgene_viewer. I usually remove those packages manually from the list (there are luckily not many of them).

However, the upgrade is not fully automatic, since you need to e.g. agree to various licenses (e.g. for Microsoft's True Type fonts) and acknowledge manually other stuff (e.g. libdvd-pkg legal issues), which kind of defeats the purpose of making this automatic and painless...