forked from chef/bento
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request chef#394 from chef/refactor-ubuntu-templates
[ubuntu-*] Improve DRYness, correctness, and speed of Ubuntu templates.
- Loading branch information
Showing
19 changed files
with
517 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh -eux | ||
|
||
mkdir -p /etc | ||
cp /tmp/bento-metadata.json /etc/bento-metadata.json | ||
chmod 0444 /etc/bento-metadata.json | ||
rm -f /tmp/bento-metadata.json | ||
mkdir -p /etc; | ||
cp /tmp/bento-metadata.json /etc/bento-metadata.json; | ||
chmod 0444 /etc/bento-metadata.json; | ||
rm -f /tmp/bento-metadata.json; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
#!/bin/sh -eux | ||
|
||
# Whiteout the swap partition to reduce box size | ||
# Swap is disabled till reboot | ||
readonly swapuuid=$(/sbin/blkid -o value -l -s UUID -t TYPE=swap) | ||
readonly swappart=$(readlink -f /dev/disk/by-uuid/"$swapuuid") | ||
/sbin/swapoff "$swappart" | ||
dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed" | ||
/sbin/mkswap -U "$swapuuid" "$swappart" | ||
# Whiteout the swap partition to reduce box size | ||
# Swap is disabled till reboot | ||
swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`"; | ||
swappart="`readlink -f /dev/disk/by-uuid/$swapuuid`"; | ||
/sbin/swapoff "$swappart"; | ||
dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed"; | ||
/sbin/mkswap -U "$swapuuid" "$swappart"; | ||
|
||
dd if=/dev/zero of=/EMPTY bs=1M | ||
rm -f /EMPTY | ||
dd if=/dev/zero of=/EMPTY bs=1M || echo "dd exit code $? is suppressed"; | ||
rm -f /EMPTY; | ||
# Block until the empty file has been removed, otherwise, Packer | ||
# will try to kill the box while the disk is still full and that's bad | ||
sync | ||
sync; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash -eux | ||
#!/bin/sh -eux | ||
|
||
echo "UseDNS no" >> /etc/ssh/sshd_config | ||
echo "GSSAPIAuthentication no" >> /etc/ssh/sshd_config | ||
echo "UseDNS no" >>/etc/ssh/sshd_config; | ||
echo "GSSAPIAuthentication no" >>/etc/ssh/sshd_config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
#!/bin/bash -eux | ||
|
||
# delete all linux headers | ||
dpkg --list | awk '{ print $2 }' | grep linux-headers | xargs apt-get -y purge | ||
|
||
# this removes specific linux kernels, such as | ||
# linux-image-3.11.0-15-generic but | ||
# * keeps the current kernel | ||
# * does not touch the virtual packages, e.g.'linux-image-generic', etc. | ||
# | ||
dpkg --list | awk '{ print $2 }' | grep 'linux-image-3.*-generic' | grep -v `uname -r` | xargs apt-get -y purge | ||
|
||
# delete linux source | ||
dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge | ||
|
||
# delete development packages | ||
dpkg --list | awk '{ print $2 }' | grep -- '-dev$' | xargs apt-get -y purge | ||
|
||
# delete compilers and other development tools | ||
apt-get -y purge cpp gcc g++ | ||
|
||
# delete X11 libraries | ||
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6 | ||
|
||
# delete obsolete networking | ||
apt-get -y purge ppp pppconfig pppoeconf | ||
|
||
# delete oddities | ||
apt-get -y purge popularity-contest | ||
|
||
apt-get -y autoremove | ||
apt-get -y clean | ||
rm -rf VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.? | ||
rm -f /tmp/chef*deb | ||
#!/bin/sh -eux | ||
|
||
# Delete all Linux headers | ||
dpkg --list \ | ||
| awk '{ print $2 }' \ | ||
| grep 'linux-headers' \ | ||
| xargs apt-get -y purge; | ||
|
||
# Remove specific Linux kernels, such as linux-image-3.11.0-15-generic but | ||
# keeps the current kernel and does not touch the virtual packages, | ||
# e.g. 'linux-image-generic', etc. | ||
dpkg --list \ | ||
| awk '{ print $2 }' \ | ||
| grep 'linux-image-3.*-generic' \ | ||
| grep -v `uname -r` \ | ||
| xargs apt-get -y purge; | ||
|
||
# Delete Linux source | ||
dpkg --list \ | ||
| awk '{ print $2 }' \ | ||
| grep linux-source \ | ||
| xargs apt-get -y purge; | ||
|
||
# Delete development packages | ||
dpkg --list \ | ||
| awk '{ print $2 }' \ | ||
| grep -- '-dev$' \ | ||
| xargs apt-get -y purge; | ||
|
||
# Delete compilers and other development tools | ||
apt-get -y purge cpp gcc g++; | ||
|
||
# Delete X11 libraries | ||
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6; | ||
|
||
# Delete obsolete networking | ||
apt-get -y purge ppp pppconfig pppoeconf; | ||
|
||
# Delete oddities | ||
apt-get -y purge popularity-contest; | ||
|
||
apt-get -y autoremove; | ||
apt-get -y clean; | ||
|
||
rm -f VBoxGuestAdditions_*.iso VBoxGuestAdditions_*.iso.?; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
#!/bin/bash -eux | ||
#!/bin/sh -eux | ||
|
||
rm /etc/udev/rules.d/70-persistent-net.rules | ||
mkdir /etc/udev/rules.d/70-persistent-net.rules | ||
rm /lib/udev/rules.d/75-persistent-net-generator.rules | ||
rm -rf /dev/.udev/ /var/lib/dhcp3/* | ||
echo "pre-up sleep 2" >> /etc/network/interfaces | ||
# Disable automatic udev rules for network interfaces in Ubuntu, | ||
# source: http://6.ptmc.org/164/ | ||
rm -f /etc/udev/rules.d/70-persistent-net.rules; | ||
mkdir -p /etc/udev/rules.d/70-persistent-net.rules; | ||
rm -f /lib/udev/rules.d/75-persistent-net-generator.rules; | ||
rm -rf /dev/.udev/ /var/lib/dhcp3/*; | ||
|
||
# Adding a 2 sec delay to the interface up, to make the dhclient happy | ||
echo "pre-up sleep 2" >>/etc/network/interfaces; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
#!/bin/bash -eux | ||
#!/bin/sh -eux | ||
|
||
# https://help.ubuntu.com/community/CheckingYourUbuntuVersion | ||
if [ lsb_release > /dev/null 2>&1 ] | ||
then | ||
# Get the major version (like "12" from the version string (like "12.04") | ||
major_version=$(lsb_release -r | cut -f 2 | cut -d . -f 1) | ||
fi | ||
major_version="`lsb_release -r | awk '{print $2}' | awk -F. '{print $1}'`"; | ||
|
||
if [ ! -z "$major_version" -a "$major_version" -lt 12 ] | ||
then | ||
sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers | ||
sed -i -e 's/%admin\s*ALL=(ALL) ALL/%admin\tALL=(ALL) NOPASSWD:ALL/g' /etc/sudoers | ||
if [ ! -z "$major_version" -a "$major_version" -lt 12 ]; then | ||
sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=admin' /etc/sudoers; | ||
sed -i -e 's/%admin\s*ALL=(ALL) ALL/%admin\tALL=(ALL) NOPASSWD:ALL/g' /etc/sudoers; | ||
else | ||
sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=sudo' /etc/sudoers | ||
sed -i -e 's/%sudo\s*ALL=(ALL:ALL) ALL/%sudo\tALL=(ALL) NOPASSWD:ALL/g' /etc/sudoers | ||
sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=sudo' /etc/sudoers; | ||
sed -i -e 's/%sudo\s*ALL=(ALL:ALL) ALL/%sudo\tALL=(ALL) NOPASSWD:ALL/g' /etc/sudoers; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
#!/bin/bash -eux | ||
#!/bin/sh -eux | ||
|
||
UBUNTU_VERSION=`lsb_release -r | awk '{print $2}'` | ||
# on 12.04 work around bad cached lists | ||
if [[ "$UBUNTU_VERSION" == '12.04' ]]; then | ||
apt-get clean | ||
rm -rf /var/lib/apt/lists | ||
ubuntu_version="`lsb_release -r | awk '{print $2}'`"; | ||
ubuntu_major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; | ||
|
||
# Work around bad cached lists on Ubuntu 12.04 | ||
if [ "$ubuntu_version" = "12.04" ]; then | ||
apt-get clean; | ||
rm -rf /var/lib/apt/lists; | ||
fi | ||
|
||
# Update the package list | ||
apt-get update | ||
apt-get update; | ||
|
||
# Upgrade all installed packages incl. kernel and kernel headers | ||
apt-get -y upgrade linux-server linux-headers-server | ||
if [ "$ubuntu_major_version" -lt 14 ]; then | ||
apt-get -y upgrade linux-server linux-headers-server; | ||
else | ||
apt-get -y upgrade linux-generic; | ||
fi | ||
|
||
# ensure the correct kernel headers are installed | ||
apt-get -y install linux-headers-$(uname -r) | ||
apt-get -y install linux-headers-`uname -r`; | ||
|
||
# update package index on boot | ||
cat <<EOF > /etc/init/refresh-apt.conf | ||
cat <<EOF >/etc/init/refresh-apt.conf; | ||
description "update package index" | ||
start on networking | ||
task | ||
exec /usr/bin/apt-get update | ||
EOF | ||
|
||
# on 12.04 manage broken indexes on distro disc 12.04.5 | ||
if [[ $UBUNTU_VERSION == '12.04' ]]; then | ||
apt-get -y install libreadline-dev dpkg | ||
# Manage broken indexes on distro disc 12.04.5 | ||
if [ "$ubuntu_version" = "12.04" ]; then | ||
apt-get -y install libreadline-dev dpkg; | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash -eux | ||
|
||
pubkey_url="https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub"; | ||
mkdir -p $HOME_DIR/.ssh; | ||
if command -v wget >/dev/null 2>&1; then | ||
wget --no-check-certificate "$pubkey_url" -O $HOME_DIR/.ssh/authorized_keys; | ||
elif command -v curl >/dev/null 2>&1; then | ||
curl --insecure --location "$pubkey_url" > $HOME_DIR/.ssh/authorized_keys; | ||
else | ||
echo "Cannot download vagrant public key"; | ||
exit 1; | ||
fi | ||
chown -R vagrant $HOME_DIR/.ssh; | ||
chmod -R go-rwsx $HOME_DIR/.ssh; |
Oops, something went wrong.