Enabling unattended-upgrades from a shell script

Just make a copy of /etc/apt/apt.conf.d/20auto-upgrades after configuring it the way you like, and drop that into place on your target machine. You could embed it in your script, or you could rsync or wget it in from a server, or whatever.

So basically your script might do something like this:

apt-get install unattended-upgrades
wget -O /etc/apt/apt.conf.d/20auto-upgrades http://myserver.mytld/confs/20auto-upgrades
/etc/init.d/unattended-upgrades restart

There's really no reason to monkey with the dpkg-reconfigure script at all.

If you don't want to fetch the conf file from a remote server, it's VERY very short and simple - the default version, which fetches and installs security updates only, looks like this:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

So you can just echo those lines into the config file directly with the following:

echo -e "APT::Periodic::Update-Package-Lists \"1\";\nAPT::Periodic::Unattended-Upgrade \"1\";\n" > /etc/apt/apt.conf.d/20auto-upgrades

If you want to use dpkg-reconfigure, you can set the value with "debconf-set-selections", and then reconfigure it in a noninteractive way.

echo "unattended-upgrades       unattended-upgrades/enable_auto_updates boolean true" | debconf-set-selections; dpkg-reconfigure -f noninteractive unattended-upgrades