Revision 173022fb image_creator/os_type/linux.py
b/image_creator/os_type/linux.py | ||
---|---|---|
48 | 48 |
self._uuid = dict() |
49 | 49 |
self._persistent = re.compile('/dev/[hsv]d[a-z][1-9]*') |
50 | 50 |
|
51 |
@sysprep(enabled=False) |
|
52 |
def remove_user_accounts(self, print_header=True):
|
|
51 |
@sysprep('Removing user accounts with id greater that 1000', enabled=False)
|
|
52 |
def remove_user_accounts(self): |
|
53 | 53 |
"""Remove all user accounts with id greater than 1000""" |
54 | 54 |
|
55 |
if print_header: |
|
56 |
self.out.output("Removing all user accounts with id greater than " |
|
57 |
"1000") |
|
58 |
|
|
59 | 55 |
if 'USERS' not in self.meta: |
60 | 56 |
return |
61 | 57 |
|
... | ... | |
105 | 101 |
if self.g.is_dir(home) and home.startswith('/home/'): |
106 | 102 |
self.g.rm_rf(home) |
107 | 103 |
|
108 |
@sysprep() |
|
109 |
def cleanup_passwords(self, print_header=True):
|
|
104 |
@sysprep('Cleaning up password & locking all user accounts')
|
|
105 |
def cleanup_passwords(self): |
|
110 | 106 |
"""Remove all passwords and lock all user accounts""" |
111 | 107 |
|
112 |
if print_header: |
|
113 |
self.out.output("Cleaning up passwords & locking all user " |
|
114 |
"accounts") |
|
115 |
|
|
116 | 108 |
shadow = [] |
117 | 109 |
|
118 | 110 |
for line in self.g.cat('/etc/shadow').splitlines(): |
... | ... | |
124 | 116 |
|
125 | 117 |
self.g.write('/etc/shadow', "\n".join(shadow) + '\n') |
126 | 118 |
|
127 |
@sysprep() |
|
128 |
def fix_acpid(self, print_header=True):
|
|
119 |
@sysprep('Fixing acpid powerdown action')
|
|
120 |
def fix_acpid(self): |
|
129 | 121 |
"""Replace acpid powerdown action scripts to immediately shutdown the |
130 | 122 |
system without checking if a GUI is running. |
131 | 123 |
""" |
132 | 124 |
|
133 |
if print_header: |
|
134 |
self.out.output('Fixing acpid powerdown action') |
|
135 |
|
|
136 | 125 |
powerbtn_action = '#!/bin/sh\n\nPATH=/sbin:/bin:/usr/bin\n' \ |
137 | 126 |
'shutdown -h now "Power button pressed"\n' |
138 | 127 |
|
... | ... | |
185 | 174 |
|
186 | 175 |
self.out.warn("No acpi power button event found!") |
187 | 176 |
|
188 |
@sysprep() |
|
189 |
def remove_persistent_net_rules(self, print_header=True):
|
|
177 |
@sysprep('Removing persistent network interface names')
|
|
178 |
def remove_persistent_net_rules(self): |
|
190 | 179 |
"""Remove udev rules that will keep network interface names persistent |
191 | 180 |
after hardware changes and reboots. Those rules will be created again |
192 | 181 |
the next time the image runs. |
193 | 182 |
""" |
194 | 183 |
|
195 |
if print_header: |
|
196 |
self.out.output('Removing persistent network interface names') |
|
197 |
|
|
198 | 184 |
rule_file = '/etc/udev/rules.d/70-persistent-net.rules' |
199 | 185 |
if self.g.is_file(rule_file): |
200 | 186 |
self.g.rm(rule_file) |
201 | 187 |
|
202 |
@sysprep() |
|
203 |
def remove_swap_entry(self, print_header=True):
|
|
188 |
@sysprep('Removing swap entry from fstab')
|
|
189 |
def remove_swap_entry(self): |
|
204 | 190 |
"""Remove swap entry from /etc/fstab. If swap is the last partition |
205 | 191 |
then the partition will be removed when shrinking is performed. If the |
206 | 192 |
swap partition is not the last partition in the disk or if you are not |
207 | 193 |
going to shrink the image you should probably disable this. |
208 | 194 |
""" |
209 | 195 |
|
210 |
if print_header: |
|
211 |
self.out.output('Removing swap entry from fstab') |
|
212 |
|
|
213 | 196 |
new_fstab = "" |
214 | 197 |
fstab = self.g.cat('/etc/fstab') |
215 | 198 |
for line in fstab.splitlines(): |
... | ... | |
222 | 205 |
|
223 | 206 |
self.g.write('/etc/fstab', new_fstab) |
224 | 207 |
|
225 |
@sysprep() |
|
226 |
def use_persistent_block_device_names(self, print_header=True):
|
|
208 |
@sysprep('Replacing fstab & grub non-persistent device references')
|
|
209 |
def use_persistent_block_device_names(self): |
|
227 | 210 |
"""Scan fstab & grub configuration files and replace all non-persistent |
228 | 211 |
device references with UUIDs. |
229 | 212 |
""" |
230 | 213 |
|
231 |
if print_header: |
|
232 |
self.out.output("Replacing fstab & grub non-persistent device " |
|
233 |
"references") |
|
234 |
|
|
235 | 214 |
# convert all devices in fstab to persistent |
236 | 215 |
persistent_root = self._persistent_fstab() |
237 | 216 |
|
Also available in: Unified diff