Skip to content

Instantly share code, notes, and snippets.

@dkubb
Forked from jbfavre/ubuntu_precise_ec2_post_install
Last active December 21, 2015 15:18
Show Gist options
  • Save dkubb/6325281 to your computer and use it in GitHub Desktop.
Save dkubb/6325281 to your computer and use it in GitHub Desktop.
#!/bin/bash
unset UCF_FORCE_CONFFOLD
export UCF_FORCE_CONFFNEW=YES
export DEBIAN_FRONTEND=noninteractive
export MAKEFLAGS="-j"
export CONCURRENCY_LEVEL=$(($(nproc) + 1))
# Configure apt to not install recommended or suggested packages
tee /etc/apt/apt.conf.d/10recommended <<-CONFIG
APT::Install-Recommends "0";
APT::Install-Suggests "0";
CONFIG
# Remove grub menu config
ucf --purge /boot/grub/menu.lst
# Update system package list
apt-get update
# Set default locate
tee /etc/default/locale <<-DEFAULT_LOCALE
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
DEFAULT_LOCALE
# Remove unnused locales
apt-get -o Dpkg::Options::="--force-confnew" -fuy install localepurge
tee /etc/locale.nopurge <<-LOCALES
# Remove localize man pages
MANDELETE
# Delete all new locales
DONTBOTHERNEWLOCALE
# Locales to keep
en
en_US
en_US.UTF-8
LOCALES
localepurge
# Upgrade system packages
apt-get -o Dpkg::Options::="--force-confnew" -fuy upgrade
# Remove unnecessary packages
aptitude -y purge accountsservice acpid apport apport-symptoms apt-transport-https apt-xapian-index at bind9-host busybox-static byobu cloud-initramfs-growroot cloud-initramfs-rescuevol console-setup curl dbus dmidecode dnsutils dosfstools ed eject fonts-ubuntu-font-family-console friendly-recovery ftp fuse geoip-database gir1.2-gudev-1.0 hdparm iputils-ping iputils-tracepath irqbalance iw kbd keyboard-configuration krb5-locales landscape-client landscape-common language-selector-common laptop-detect libaccountsservice0 libbind9-80 libcap-ng0 libcurl3 libdate-manip-perl libdbus-glib-1-2 e2 libgc1c2 libgudev-1.0-0 libiw30 libparted0debian1 libpcap0.8 libpolkit-gobject-1-0 libsasl2-modules libusb-1.0-0 libuuid1 libxmuu1 libyaml-syck-perl logwatch lshw ltrace memtest86+ mlocate nano ntfs-3g os-prober parted popularity-contest postfix powermgmt-base ppp pppconfig pppoeconf python-apport python-chardet python-dbus python-dbus-dev python-debian python-gi python-httplib2 python-keyring python-launchpadlib python-lazr.restfulclient python-lazr.uri python-newt python-openssl python-pam python-pkg-resources python-problem-report python-serial python-simplejson python-twisted-bin python-twisted-core python-twisted-names python-twisted-web python-wadllib python-xapian python-zope.interface sgml-base ssh-import-id tasksel tasksel-data tcpd tcpdump ubuntu-minimal ubuntu-standard update-manager-core update-notifier-common ureadahead usbutils uuid-runtime w3m whoopsie wireless-tools wpasupplicant xauth xkb-data xml-core
# Add back removed dependencies
apt-get -o Dpkg::Options::="--force-confnew" -fuy install vim-tiny debconf-utils
# Clean up downloaded packages
dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg --purge
apt-get autoremove
apt-get clean
# Configure automatic security updates
apt-get -o Dpkg::Options::="--force-confnew" -fuy install unattended-upgrades
tee /etc/apt/apt.conf.d/10periodic <<-CONFIG
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
CONFIG
# Disable unnecessary services
update-rc.d -f quotarpc remove
update-rc.d -f ondemand remove
rm -v /etc/init.d/ondemand
rm -v /etc/init.d/plymouth*
rm -v /etc/init/plymouth*
rm -v /etc/init/rpcbind-boot.conf
rm -v /etc/init/tty*.conf
rm -v /etc/init/upstart-socket-bridge.conf
# Remove unnecessary configuration
rm -v /etc/alternatives/vtrgb
rm -v /etc/gai.conf
rm -v /etc/vtrgb
rm -vr /etc/calendar
rm -vr /etc/dbus-1
rm -vr /etc/ppp
# Remove logs
rm -v /var/log/ufw.log
rm -vr /lib/recovery-mode
rm -vr /var/lib/update-manager
rm -vr /var/lib/update-notifier
rm -vr /var/log/news
find /var/log/ -type f -name '*.gz*' -print0 | xargs -r0 rm -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment