1. Yes/no. Certainly it should be possible, but the various migrations have been thought about in packaging regarding only debian or ubuntu releases. Currently (for a week or so) however almost all Ubuntu packages are >= version number to Debian testing/sid, making things a bit simpler. But you mentioned "writing a shell script", and certainly you can automate various error situation recoveries with a shell script. Start with apt-get dist-upgrade and resolve possible errors. Currently testing -> raring could be very easy, normally you should handle the not so normal situation of needing to upgrade some packages and downgrade some others, version number wise.
I updated an i386 distro to x86_64. That was ugly and completely unsupported and made no sense, but there could have been theoretically a shell script to do that as well.
2. Most core packages have been modified/updated by Ubuntu, although the majority of the archive is untouched still. Every half year a sync period of two months is open where everything that can be automatically synced from Debian is synced. For the modified packages developers look at Merge-O-Matic (https://merges.ubuntu.com/) to see what needs merging next. Many Ubuntu teams contribute directly to Debian, so even with some differences the delta is often not huge. It's vital to Ubuntu to keep within the same distance (or shorter) of Debian.
Zero absolutely non-free packages (no proprietary graphics drivers, Flash or such) are installed by default in Ubuntu, but 1-3 (?) borderline packages like linux-firmware are considered 'free enough' by Ubuntu to ship in the main repository. I'm not sure but there might be some stuff in the Linux kernel as well that is in upstream but Debian has removed and Ubuntu not. Debian does not however strip everything ~non-free away either, like some microcode sections from kernel (GNewSense does).
The 'restricted' repository in Ubuntu is enabled by default, although nothing is installed automatically from there. It contains different versions of 4 driver packages (broadcom WLAN, AMD and NVIDIA graphics, slmodem). There's also 'multiverse' repository, which contains more either problematic (shaky patent situation, which is debatable) or simply non-free packages. I don't personally have restricted or multiverse enabled on my computers.