-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprovision.sh
183 lines (144 loc) · 5.53 KB
/
provision.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bash
set -e
echo "[INFO ] Provision Progressing."
echo "[INFO ] DisableHistory Progressing."
unset HISTFILE
history -cw
echo "[INFO ] DisableHistory is Complete."
if [[ "$(id -u)" -ne 0 ]]
then
echo >&2 "[ERROR] This script requires privileged access to system files and must be run as root."
exit 99
fi
echo "[INFO ] SetEnvironmentVars Progressing."
export DEBIAN_FRONTEND="noninteractive"
export DEBCONF_NONINTERACTIVE_SEEN="true"
echo "[INFO ] SetEnvironmentVars is Complete."
echo "[INFO ] ConfigureApt Progressing."
cat <<'HEREDOC' >/etc/apt/apt.conf.d/90gzip-indexes
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
HEREDOC
cat <<'HEREDOC' >/etc/apt/apt.conf.d/90no-language
Acquire::Languages "none";
HEREDOC
cat <<'HEREDOC' >/etc/apt/apt.conf.d/90no-suggests-nor-recommends
APT::Install-Recommends "0";
APT::Install-Suggests "0" ;
HEREDOC
# open-vm-tools for arm64 can currently (2022-Mar-23rd) only be found in the bullseye-backports package repository
[ -f /etc/apt/sources.list.d/backports.list ] || cat <<'HEREDOC' >/etc/apt/sources.list.d/backports.list
deb http://deb.debian.org/debian bullseye-backports main contrib non-free
deb-src http://deb.debian.org/debian bullseye-backports main contrib non-free
HEREDOC
echo "[INFO ] ConfigureApt is Complete."
echo "[INFO ] InstallPackages Progressing."
apt-get -qq update
apt-get install -y -qq \
ca-certificates \
fuse3 \
linux-headers-$(uname -r) \
nfs-common \
open-vm-tools \
sudo \
wget \
;
echo "[INFO ] InstallPackages is Complete."
echo "[INFO ] ConfigureSshD Progressing."
sed -i \
-e '/UseDNS /s/.*\(UseDNS\) .*/\1 no/' \
-e '/GSSAPIAuthentication /s/.*\(GSSAPIAuthentication\) .*/\1 no/' \
/etc/ssh/sshd_config
# populate vagrant's default key (which is replaced upon :code:`$ vagrant up`)
wget -q https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /tmp/authorized_keys
for usr in /home/*; do
username="${usr##*/}"
install --directory --owner=vagrant --group=vagrant --mode=0700 /home/vagrant/.ssh
install --owner=vagrant --group=vagrant --mode=0600 --target-directory=/home/vagrant/.ssh /tmp/authorized_keys
done
rm -rf /tmp/authorized_keys
echo "[INFO ] ConfigureSshD is Complete."
echo "[INFO ] ConfigureModprobe Progressing."
# HACK: suppress flood of "Unknown ioctl 1976" on arm64 vms
# https://github.com/vmware/photon/issues/1117#issuecomment-786656054
#
[ -f /etc/modprobe.d/blacklist-for-unknown-ioctl-1976-on-arm64.conf ] || cat <<HEREDOC >/etc/modprobe.d/blacklist-for-unknown-ioctl-1976-on-arm64.conf
blacklist vsock_loopback
blacklist vmw_vsock_virtio_transport_common
install vsock_loopback /usr/bin/true
install vmw_vsock_virtio_transport_common /usr/bin/true
HEREDOC
echo "[INFO ] ConfigureModprobe is Complete."
echo "[INFO ] ConfigureGrub Progressing."
# make bootup LOUD
sed -i 's/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*/\1""/' /etc/default/grub
update-grub
echo "[INFO ] ConfigureGrub is Complete."
# System Cleanup removes caches and unneeded packages in order to produce the smallest box possible.
echo "[INFO ] SystemCleanup Progressing."
# remove old kernel versions and kernel header versions
apt-get -y -qq purge \
$(dpkg -l | grep "linux-image-[0-9]" | grep "^ii" | tac | tail -n +2 | awk '{ print $2 }') \
$(dpkg -l | grep "linux-headers-[0-9].*-arm64" | grep "^ii" | tac | tail -n +2 | awk '{ print $2 }') \
;
# including other no longer required packages
apt-get -y -qq autopurge
# and update grub incase there were entries for those kernels
update-grub
apt-get -y -qq purge \
dictionaries* \
emacs* \
iamerican* \
ibritish* \
ienglish* \
installation-report \
ispell \
libx11-6 \
libx11-data \
libxcb1 \
libxext6 \
libxmuu1 \
nfacct \
popularity-contest \
tcpd \
xauth \
> /dev/null 2>&1
apt-get -y -qq --purge autoremove > /dev/null 2>&1
apt-get autoclean
apt-get clean
rm -rf /usr/share/info/*
rm -rf /usr/share/man/*
rm -rf /var/cache/apt/*
rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/dhcp/*
rm -rf /var/log/*
rm -rf /var/tmp/{..?*,.[!.]*,*}
# remove ipv6 only libraries
rm -rf /lib/xtables/libip6t_*.so
find /home /root -type f -not \( -name '.bashrc' -o -name '.bash_logout' -o -name '.profile' -o -name 'authorized_keys' \) -delete
find /usr/share/locale -mindepth 1 -maxdepth 1 -type d -not \( -name 'en' -o -name 'en_US' \) -exec rm -r {} ';'
find /usr/share/doc -mindepth 1 -not -type d -not -name 'copyright' -delete
find /usr/share/doc -mindepth 1 -type d -empty -delete
find /var/cache -type f -delete
sed -i -e '/cdrom/d' /etc/fstab
# empty the swap file
swap_part="$(swapon --show=NAME --noheadings --raw)"
swapoff "${swap_part}"
dd if=/dev/zero of="${swap_part}" > /dev/null 2>&1 || echo 'dd exit code suppressed'
mkswap -L SWAP "${swap_part}"
swapon "${swap_part}"
echo "COMPRESS=xz" > /etc/initramfs-tools/conf.d/compress
echo "RESUME=none" > /etc/initramfs-tools/conf.d/resume
update-initramfs -u # -u => Update an existing initramfs
dd if=/dev/zero of=/EMPTY bs=1M > /dev/null 2>&1 || echo 'dd exit code suppressed'
rm -f /EMPTY
sync
echo "[INFO ] SystemCleanup is Complete."
echo "[INFO ] SystemInfo:"
echo '--------------------------------------------------'
printf 'Debian: ..... ' ; cat /etc/debian_version
printf 'Filessytem: . ' ; du -sh / --exclude=/proc
printf 'OpenVmTools: ' ; /usr/bin/vmware-toolbox-cmd -v
echo '--------------------------------------------------'
echo "[INFO ] Provision is Complete."
exit 0