first commit

This commit is contained in:
Tyler
2022-03-06 15:30:05 -05:00
commit 14a1d3f2ea
10 changed files with 349 additions and 0 deletions

98
ubuntu/scripts/cleanup.sh Normal file
View File

@ -0,0 +1,98 @@
#!/bin/sh -eux
echo "remove linux-headers"
dpkg --list \
| awk '{ print $2 }' \
| grep 'linux-headers' \
| xargs apt-get -y purge;
echo "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"
dpkg --list \
| awk '{ print $2 }' \
| grep 'linux-image-.*-generic' \
| grep -v `uname -r` \
| xargs apt-get -y purge;
echo "remove old kernel modules packages"
dpkg --list \
| awk '{ print $2 }' \
| grep 'linux-modules-.*-generic' \
| grep -v `uname -r` \
| xargs apt-get -y purge;
echo "remove linux-source package"
dpkg --list \
| awk '{ print $2 }' \
| grep linux-source \
| xargs apt-get -y purge;
echo "remove all development packages"
dpkg --list \
| awk '{ print $2 }' \
| grep -- '-dev\(:[a-z0-9]\+\)\?$' \
| xargs apt-get -y purge;
echo "remove docs packages"
dpkg --list \
| awk '{ print $2 }' \
| grep -- '-doc$' \
| xargs apt-get -y purge;
echo "remove X11 libraries"
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6;
echo "remove obsolete networking packages"
apt-get -y purge ppp pppconfig pppoeconf;
echo "remove packages we don't need"
apt-get -y purge popularity-contest command-not-found friendly-recovery bash-completion fonts-ubuntu-font-family-console laptop-detect motd-news-config usbutils grub-legacy-ec2
# 21.04+ don't have this
echo "remove the installation-report"
apt-get -y purge popularity-contest installation-report || true;
echo "remove the console font"
apt-get -y purge fonts-ubuntu-console || true;
echo "removing command-not-found-data"
# 19.10+ don't have this package so fail gracefully
apt-get -y purge command-not-found-data || true;
# Exclude the files we don't need w/o uninstalling linux-firmware
echo "Setup dpkg excludes for linux-firmware"
cat <<_EOF_ | cat >> /etc/dpkg/dpkg.cfg.d/excludes
#BENTO-BEGIN
path-exclude=/lib/firmware/*
path-exclude=/usr/share/doc/linux-firmware/*
#BENTO-END
_EOF_
echo "delete the massive firmware files"
rm -rf /lib/firmware/*
rm -rf /usr/share/doc/linux-firmware/*
echo "autoremoving packages and cleaning apt data"
apt-get -y autoremove;
apt-get -y clean;
echo "remove /usr/share/doc/"
rm -rf /usr/share/doc/*
echo "remove /var/cache"
find /var/cache -type f -exec rm -rf {} \;
echo "truncate any logs that have built up during the install"
find /var/log -type f -exec truncate --size=0 {} \;
echo "blank netplan machine-id (DUID) so machines get unique ID generated on boot"
truncate -s 0 /etc/machine-id
echo "remove the contents of /tmp and /var/tmp"
rm -rf /tmp/* /var/tmp/*
echo "force a new random seed to be generated"
rm -f /var/lib/systemd/random-seed
echo "clear the history so our install isn't there"
rm -f /root/.wget-hsts
export HISTSIZE=0

13
ubuntu/scripts/hyperv.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/sh -eux
ubuntu_version="`lsb_release -r | awk '{print $2}'`";
major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
case "$PACKER_BUILDER_TYPE" in
hyperv-iso)
echo "installing packaging for hyper-v"
if [ "$major_version" -eq "16" ]; then
apt-get install -y linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial;
else
apt-get -y install linux-image-virtual linux-tools-virtual linux-cloud-tools-virtual;
fi
esac

View File

@ -0,0 +1,23 @@
#!/bin/sh -eux
ubuntu_version="`lsb_release -r | awk '{print $2}'`";
major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
if [ "$major_version" -ge "18" ]; then
echo "Create netplan config for eth0"
cat <<EOF >/etc/netplan/01-netcfg.yaml;
network:
version: 2
ethernets:
eth0:
dhcp4: true
EOF
else
# Adding a 2 sec delay to the interface up, to make the dhclient happy
echo "pre-up sleep 2" >> /etc/network/interfaces;
fi
# Disable Predictable Network Interface names and use eth0
[ -e /etc/network/interfaces ] && sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces;
sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub;
update-grub;

35
ubuntu/scripts/update.sh Normal file
View File

@ -0,0 +1,35 @@
#!/bin/sh -eux
export DEBIAN_FRONTEND=noninteractive
echo "disable release-upgrades"
sed -i.bak 's/^Prompt=.*$/Prompt=never/' /etc/update-manager/release-upgrades;
echo "disable systemd apt timers/services"
systemctl stop apt-daily.timer;
systemctl stop apt-daily-upgrade.timer;
systemctl disable apt-daily.timer;
systemctl disable apt-daily-upgrade.timer;
systemctl mask apt-daily.service;
systemctl mask apt-daily-upgrade.service;
systemctl daemon-reload;
# Disable periodic activities of apt to be safe
cat <<EOF >/etc/apt/apt.conf.d/10periodic;
APT::Periodic::Enable "0";
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
APT::Periodic::Unattended-Upgrade "0";
EOF
echo "remove the unattended-upgrades and ubuntu-release-upgrader-core packages"
rm -rf /var/log/unattended-upgrades;
apt-get -y purge unattended-upgrades ubuntu-release-upgrader-core;
echo "update the package list"
apt-get -y update;
echo "upgrade all installed packages incl. kernel and kernel headers"
apt-get -y dist-upgrade -o Dpkg::Options::="--force-confnew";
reboot

11
ubuntu/scripts/vmware.sh Normal file
View File

@ -0,0 +1,11 @@
#!/bin/sh -eux
case "$PACKER_BUILDER_TYPE" in
vmware-iso|vmware-vmx)
echo "install open-vm-tools"
apt-get install -y open-vm-tools;
mkdir /mnt/hgfs;
systemctl enable open-vm-tools
systemctl start open-vm-tools
echo "platform specific vmware.sh executed";
esac