| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | import sys |
|---|
| 4 | import os |
|---|
| 5 | import shutil |
|---|
| 6 | import tempfile |
|---|
| 7 | from subprocess import call |
|---|
| 8 | |
|---|
| 9 | data_dir = '/srv/guest-installer' |
|---|
| 10 | |
|---|
| 11 | def make_debian_cd(name, passhashfile): |
|---|
| 12 | basetree = os.path.join(data_dir, name) |
|---|
| 13 | tmptree = tempfile.mkdtemp('', 'auto-install.', '/tmp') |
|---|
| 14 | cdtree = os.path.join(tmptree, 'cdrom') |
|---|
| 15 | shutil.copytree(os.path.join(basetree, 'cdrom'), cdtree, symlinks=True) |
|---|
| 16 | new_preseed = file(os.path.join(cdtree, 'preseed.cfg'), 'w') |
|---|
| 17 | old_preseed = file(os.path.join(basetree, 'preseed.cfg')) |
|---|
| 18 | new_preseed.write(old_preseed.read()) |
|---|
| 19 | passhash = file(passhashfile).read() |
|---|
| 20 | new_preseed.write('d-i passwd/root-password-crypted password '+passhash+'\n') |
|---|
| 21 | new_preseed.close() |
|---|
| 22 | output_iso = os.path.join(tmptree, 'install.iso') |
|---|
| 23 | call('''mkisofs -r -V "SIPB-Xen_Custom_Install_CD" -cache-inodes -J -l |
|---|
| 24 | -b isolinux/isolinux.bin -c isolinux/boot.cat |
|---|
| 25 | -no-emul-boot -boot-load-size 4 -boot-info-table'''.split() |
|---|
| 26 | + ['-o', output_iso, cdtree]) |
|---|
| 27 | return output_iso |
|---|
| 28 | |
|---|
| 29 | if __name__ == '__main__': |
|---|
| 30 | print make_debian_cd(*sys.argv[1:]) |
|---|