-
Notifications
You must be signed in to change notification settings - Fork 0
/
99-packer-virt-sysprep-control-script.sh
128 lines (108 loc) · 4.16 KB
/
99-packer-virt-sysprep-control-script.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
#!/usr/bin/env bash
#
# Run Packer-Virt-Sysprep operations.
#
# Each virt-sysprep style operation is individually controlled through the
# use of user variables in the Packer template. Each user variable is then
# exported as an environment variable that this script uses to determine
# if each operation below should be executed
# Packer logging
echo "Running the packer-virt-sysprep control script..."
# The directory that is to be used to hold all packer-virt-sysprep files
# and operations scripts is specified in the Packer configuration template
# and exported as an environment variable
PREFIX="${PACKER_VIRT_SYSPREP_DIR}"
# The packer-virt-sysprep scripts will only run within a Bash shell. If we
# can't find Bash we mush exit.
SH="$(command -v bash)"
if [ "x${SH}" = "x" ]; then
echo "ERROR: Could not enumerate path for bash executable. Exiting"
exit -1
fi
# Run each Packer-Virt-Sysprep operation as requested
# bash_history: Remove all users bash history. Remove:
# * /home/*/.bash_history
# * /root/.bash_history
if [ "${SYSPREP_OP_BASH_HISTORY}" = true ]; then
echo "* Removing Bash history for root and all users under /home "
${SH} ${PREFIX}/sysprep-op-bash-history.sh
fi
# crash_data: Remove crash data generated by kexec-tools by removing:
# * /var/crash/*
# * /var/log/dump/*
if [ "${SYSPREP_OP_CRASH_DATA}" = true ]; then
echo "* Removing any crash data or dumps created by kexec-tools"
${SH} ${PREFIX}/sysprep-op-crash-data.sh
fi
# dhcp-client-state: Remove DHCP client release by removing:
# * /var/lib/dhclient/*
# * /var/lib/dhcp/*
if [ "${SYSPREP_OP_DHCP_CLIENT_STATE}" = true ]; then
echo "* Removing any DHCP client lease information"
${SH} ${PREFIX}/sysprep-op-dhcp-client-state.sh
fi
# firewall-rules: Remove custom firewall rules by removing:
# * /etc/sysconfig/iptables
# * /etc/firewalld/services/*
# * /etc/firewalld/zones/*
if [ "${SYSPREP_OP_FIREWALL_RULES}" = true ]; then
echo "* Removing any custom firewall rules or firewalld configuration"
${SH} ${PREFIX}/sysprep-op-firewall-rules.sh
fi
# logfiles: Remove logfiles at:
# * ...a ton of different locations!
if [ "${SYSPREP_OP_LOGFILES}" = true ]; then
echo "* Removing log files from various locations"
${SH} ${PREFIX}/sysprep-op-logfiles.sh
fi
# machine-id: Remove the local machine ID by removing content from:
# * /etc/machine-id
# * /var/lib/dbus/machine-id
if [ "${SYSPREP_OP_MACHINE_ID}" = true ]; then
echo "* Deleting the machine-ID. A new ID will be generated at next boot"
${SH} ${PREFIX}/sysprep-op-machine-id.sh
fi
# mail-spool: Remove email from the local mail spool directory
# # /var/spool/mail/*
# * /var/mail/*
if [ "${SYSPREP_OP_MAIL_SPOOL}" = true ]; then
echo "* Removing any mail from the local mail spool"
${SH} ${PREFIX}/sysprep-op-mail-spool.sh
fi
# package-manager-cache: Remove package manager cache by removing files
# under:
# * /var/cache/apt/archives/
# * /var/cache/dnf/
# * /var/cache/yum/
# * /var/cache/zypp*
if [ "${SYSPREP_OP_PACKAGE_MANAGER_CACHE}" = true ]; then
echo "* Removing cache files associated with the system package manager"
${SH} ${PREFIX}/sysprep-op-package-manager-cache.sh
fi
# rpm-db: Remove host-specific RPM database files by removing:
# # /var/lib/rpm/__db.*
if [ "${SYSPREP_OP_RPM_DB}" = true ]; then
echo "* Removing RPM database files. RPM will recreate these as required"
${SH} ${PREFIX}/sysprep-op-rpm-db.sh
fi
# ssh-hostkeys: Remove the SSH host keys in the guest by removing:
# * /etc/ssh/*_host_*
if [ "${SYSPREP_OP_SSH_HOSTKEYS}" = true ]; then
echo "* Removing host ssh keys. New keys will be generated at next boot"
${SH} ${PREFIX}/sysprep-op-ssh-hostkeys.sh
fi
# tmp-files: Remove all temporary files and directories by removing:
# * /tmp/*
# * /var/tmp/*
if [ "${SYSPREP_OP_TMP_FILES}" = true ]; then
echo "* Removing all temporary files"
${SH} ${PREFIX}/sysprep-op-tmp-files.sh
fi
# yum-uuid: Remove the yum UUID
# * /var/lib/yum/uuid
if [ "${SYSPREP_OP_YUM_UUID}" = true ]; then
echo "* Removing host specific Yum UUID"
${SH} ${PREFIX}/sysprep-op-yum-uuid.sh
fi
echo "Complete"
exit 0