[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Fresh and updated qemu image



Am Mittwoch, 21. April 2010 13:55:32 schrieb Michael Banck:
> On Tue, Apr 20, 2010 at 10:53:44AM +0000, Jose Luis Alarcon Sanchez wrote:
> > I think the updated qemu img file is a bit big, 225,3 Mb. But "it is" and
> > the system is all "ready to use" as GNU/Hurd can be right now.
> 
> Another problem is anonymizing it, e.g. resetting the hostname and users
> to a default, if you setup the old qemu image to your needs beforehand.

Can’t that be done via a script? 

Some time ago I created a preliminary one for a GentooXO box (attached). Only 
needs some more additions (hostname and such). 

Best wishes, 
Arne
#!/usr/bin/env python
# encoding: utf-8

"""Strip personal data from a Gentoo install.

This reverts various changes to personal data, using .bak files if available.

usage: 
    - python strip_personal_data.py [options]

options: 
    --dry-run - don't actually change anything
    --help - print this text

"""
### provide help output

# this is the first to do, so the prog responds quickly. 
from sys import argv
if "--help" in argv:
    print __doc__
    exit()


### config

#: Modified files and folders which need to be removed or replaced with backups (.bak). Format: path: reason
nodes = {
    "/etc/wpa_supplicant/wpa_supplicant.conf": "contains the wlan settings and could compromise network security."
}

#: personal user accounts
users = {
    "arne": "My personal main user."
}

# We should also reset the root password
#: root password
root_password = "olpc"


WAIT_TIME = 5


DRY_RUN = "--dry-run" in argv


### remove the personal data -> Make computer pristine

# Require confirmation before irrevocably destroying personal data.
answer = raw_input("""Note: This removes all personal data! Be sure only to use it on a copy of your system, IN A CHROOT. Proceed and destroy all personal data? (yes, No) """)

if not answer.lower() in ["yes", "y"]: 
    print("Quit. Nothing was changed.")
    exit()

print("Proceeding to strip all personal data in " + str(WAIT_TIME) + "s.")

from time import sleep
for i in range(WAIT_TIME): 
    print(WAIT_TIME - i)
    sleep(1)

# Actually remove the files

print("\nremoving dangerous files and folders")

from os import rename, remove
from os.path import exists
from subprocess import call # for rm -r

for f in nodes: 
    print("removing " + f + ": " + nodes[f])
    # if we want a dry run, we do nothing
    if DRY_RUN: 
        continue

    # if we have a backup we just move it over the current file.
    if exists(f + ".bak"): 
        rename(f + ".bak", f)
    # if we don't have a backup, we just remove the file or dir
    else: 
        call(["rm", "-r", f])
    

print("\nremoving the users")

for u in users: 
    print("removing " + u + ": " + users[u])
    # if we want a dry run, we do nothing
    if DRY_RUN: 
        continue

    # use userdel to remove the user and home dir. 
    try: 
        call(["userdel", "-f", "-r", u]) 
        # -r: remove the homedir. 
        # -f: also remove it if not all files belong to the user. 
    except OSError: 
        print("OSError: Most likely you don't have the right to use userdel.")



print("""
That's it. All personal data should be removed, now. 
To finish it, we now call "passwd root" so you can change the root password.
""")

call(["passwd", "root"])

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: