Debian / Ubuntu: Configure APT autoupdate with unattended-upgrades

# configure
wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/scripts/master/enable_auto_update.sh -O - | bash -

# install unattended-upgrades
apt-get install -y unattended-upgrades

# perform dry-run
unattended-upgrade --debug --dry-run

# download updates only
apt-get install -y unattended-upgrades
cat <> /etc/apt/apt.conf.d/10periodic
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
EOF

# v2
# update package list only
apt-get install cron cron-apt --no-install-recommends

http://wiesel.ece.utah.edu/redmine/projects/hacks/wiki/Automatic_Package_Update_for_Ubuntu

# view repository
apt-cache policy

# configuration
# https://raw.githubusercontent.com/panticz/preseed/master/late_command.sh
##sed -i '4s|//| |g' /etc/apt/apt.conf.d/50unattended-upgrades

#?# sed -i 's|//Unattended-Upgrade::Mail|Unattended-Upgrade::Mail|g' /etc/apt/apt.conf.d/50unattended-upgrades
#?# sed -i 's|//Unattended-Upgrade::MailOnlyOnError|Unattended-Upgrade::MailOnlyOnError|g' /etc/apt/apt.conf.d/50unattended-upgrades

# OPTIONAL: enable additional repository (icinga@debmon.org)
sed -i '/Unattended-Upgrade::Origins-Pattern {/ a\ "o=debmon.org,a=debmon-wheezy";' /etc/apt/apt.conf.d/50unattended-upgrades

grep -q 'APT::Periodic::Update-Package-Lists' /etc/apt/apt.conf.d/10periodic || echo 'APT::Periodic::Update-Package-Lists "1";' >> /etc/apt/apt.conf.d/10periodic
grep -q 'APT::Periodic::Unattended-Upgrade' /etc/apt/apt.conf.d/10periodic || echo 'APT::Periodic::Unattended-Upgrade "1";' >> /etc/apt/apt.conf.d/10periodic
grep -q 'APT::Periodic::AutocleanInterval' /etc/apt/apt.conf.d/10periodic || echo 'APT::Periodic::AutocleanInterval "1";' >> /etc/apt/apt.conf.d/10periodic
# sed -i 's|APT::Periodic::Download-Upgradeable-Packages "0";|APT::Periodic::Download-Upgradeable-Packages "1";|g' /etc/apt/apt.conf.d/10periodic

# Logfiles
cat /var/log/unattended-upgrades/unattended-upgrades.log
cat /var/log/unattended-upgrades/unattended-upgrades-dpkg_*.log

# test: apt-config, read only?
apt-config shell UpdateInterval APT::Periodic::Update-Package-Lists
apt-config dump
apt-config -o APT::Periodic::Unattended-Upgrade=1 shell

# Configuration files
Debian: /etc/apt/apt.conf.d/10periodic
Ubuntu: /etc/apt/apt.conf.d/20auto-upgrades

# sudo apt-get install update-notifier-common

#
# cron-apt
#
# automaticly update package list but not install
# http://wiki.ubuntuusers.de/cron-apt
apt-get install -y cron-apt --no-install-recommends

# test
sudo cron-apt -s

# configuration / actions directory
/etc/cron-apt/action.d/

# Configure cron-apt
apt-get install cron-apt

edit /etc/cron-apt/config
MAILTO="root"
MAILON="upgrade"

cp /usr/share/doc/cron-apt/examples/9-notify /etc/cron-apt/action.d/

##sudo dpkg-reconfigure -plow unattended-upgrades

# Links
http://koeritz.org/docs/unattended-upgrades/README
http://wiki.ubuntuusers.de/Aktualisierungen/Konfiguration
http://www.grosseosterhues.com/2011/02/unattended-security-updates-in-ubuntu-10-10/
https://help.ubuntu.com/10.04/serverguide/automatic-updates.html
http://www.vanutsteen.nl/2008/06/09/unattended-upgrades-on-a-ubuntu-hardy-server/