2013-11-05 09:39:10 -01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
## live-build(7) - Live System Build Components
|
|
|
|
## Copyright (C) 2006-2013 Daniel Baumann <mail@daniel-baumann.ch>
|
|
|
|
##
|
|
|
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
|
|
|
## This is free software, and you are welcome to redistribute it
|
|
|
|
## under certain conditions; see COPYING for details.
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import configparser
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2013-11-05 10:32:59 -01:00
|
|
|
import urllib.request
|
2013-11-05 09:39:10 -01:00
|
|
|
|
|
|
|
|
|
|
|
# TODO:
|
|
|
|
# * logfile output
|
|
|
|
# * lockfile handling
|
|
|
|
# * use gettext for i18n
|
|
|
|
|
|
|
|
def main():
|
|
|
|
## Parsing Arguments
|
|
|
|
arguments = argparse.ArgumentParser(
|
|
|
|
prog = 'lb init',
|
|
|
|
usage = '%(prog)s [arguments]',
|
|
|
|
description = '''live-build contains the components to build a live system from a configuration directory.
|
2013-11-05 10:13:30 -01:00
|
|
|
The init command creates an empty configuration directory or reinitialize an existing one.''',
|
2013-11-05 09:39:10 -01:00
|
|
|
epilog = 'See \'man lb-init\' for more information.',
|
|
|
|
formatter_class = argparse.ArgumentDefaultsHelpFormatter
|
|
|
|
)
|
|
|
|
|
2013-11-05 10:13:30 -01:00
|
|
|
arguments.add_argument('--version', help='show program\'s version number and exit', action='version', version='live-build 4')
|
|
|
|
arguments.add_argument('--verbose', help='set verbose option', action='store_true')
|
2013-11-05 09:39:10 -01:00
|
|
|
|
2013-11-05 10:13:30 -01:00
|
|
|
arguments.add_argument('--distribution', help='set default distribution')
|
|
|
|
arguments.add_argument('--project', help='set project defaults')
|
2013-11-05 09:39:10 -01:00
|
|
|
|
|
|
|
args = arguments.parse_args()
|
|
|
|
|
|
|
|
# --verbose
|
|
|
|
verbose = args.verbose
|
|
|
|
|
2013-11-05 10:13:30 -01:00
|
|
|
# --distribution
|
|
|
|
distribution = args.distribution
|
|
|
|
|
2013-11-05 09:39:10 -01:00
|
|
|
# --project
|
|
|
|
project = args.project
|
|
|
|
|
2013-11-05 10:32:59 -01:00
|
|
|
## Setting defaults
|
|
|
|
|
|
|
|
if not project:
|
|
|
|
# FIXME: hardcoded project information
|
|
|
|
project = 'debian'
|
|
|
|
|
|
|
|
if not distribution:
|
|
|
|
# FIXME hardcoded release information
|
|
|
|
default_distribution = { 'debian' : 'wheezy',
|
|
|
|
'progress-linux' : 'baureo',
|
|
|
|
'ubuntu' : 'saucy',
|
|
|
|
}
|
|
|
|
|
|
|
|
distribution = default_distribution[project]
|
|
|
|
|
2013-11-05 09:39:10 -01:00
|
|
|
## Creating configuration directory
|
|
|
|
|
|
|
|
# stagefile
|
|
|
|
if os.path.isdir('.build'):
|
|
|
|
if verbose:
|
|
|
|
print('I: configuration directory already initialized - nothing to do')
|
|
|
|
|
2013-11-05 10:32:59 -01:00
|
|
|
# Notes:
|
|
|
|
# * until further tests, we do not allow to re-run lb init on an already initialized directory.
|
2013-11-05 09:39:10 -01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2013-11-05 10:32:59 -01:00
|
|
|
# Configuring default archive-keys
|
|
|
|
if (project == 'progress-linux'):
|
|
|
|
# dependencies
|
|
|
|
if not os.path.isfile('/usr/bin/gpgv'):
|
|
|
|
print('E: /usr/bin/gpgv - no such file', file=sys.stderr)
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print('I: gnupg can be obtained from:\n'
|
|
|
|
'I: http://www.gnupg.org/\n'
|
|
|
|
'I: On Debian based systems, gnupg can be installed with:\n'
|
|
|
|
'I: # sudo apt-get install gnupg')
|
|
|
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
os.makedirs('config/archives', exist_ok=True)
|
|
|
|
|
|
|
|
# FIXME hardcoded release information
|
|
|
|
archive_keys_url = 'http://cdn.archive.progress-linux.org/packages/project/keys/'
|
|
|
|
|
|
|
|
archive_keys = { 'artax' : [ 'archive-key-1-artax.asc' , 'archive-key-1+-artax-backports.asc' ],
|
|
|
|
'artax-backports' : [ 'archive-key-1-artax.asc' , 'archive-key-1+-artax-backports.asc' ],
|
|
|
|
'baureo' : [ 'archive-key-2-baureo.asc' , 'archive-key-2+-baureo-backports.asc' ],
|
|
|
|
'baureo-backports' : [ 'archive-key-2-baureo.asc' , 'archive-key-2+-baureo-backports.asc' ],
|
|
|
|
'cairon' : [ 'archive-key-3-cairon.asc' , 'archive-key-3+-cairon-backports.asc' ],
|
|
|
|
'cairon-backports' : [ 'archive-key-3-cairon.asc' , 'archive-key-3+-cairon-backports.asc' ],
|
|
|
|
}
|
|
|
|
|
|
|
|
keys = archive_keys[distribution]
|
|
|
|
|
|
|
|
for key in keys:
|
|
|
|
url = archive_keys_url + key
|
|
|
|
target = os.path.splitext(os.path.basename(key))
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
print('I: Downloading ' + url)
|
|
|
|
|
|
|
|
r = urllib.request.urlopen(url)
|
|
|
|
f = open('config/archives/' + target[0] + '.key', 'b+w')
|
|
|
|
|
|
|
|
f.write(r.read())
|
|
|
|
|
|
|
|
# FIXME: download signatures and verify them against debian-keyring
|
|
|
|
|
2013-11-05 09:39:10 -01:00
|
|
|
# Configuring default hooks
|
|
|
|
os.makedirs('config/hooks', exist_ok=True)
|
|
|
|
|
|
|
|
for hook in glob.glob('/usr/share/live/build/hooks/*.hook*'):
|
|
|
|
os.symlink(hook, os.path.join('config/hooks/' + os.path.basename(hook)))
|
|
|
|
|
|
|
|
# Configuring default includes
|
|
|
|
os.makedirs('config/includes', exist_ok=True)
|
|
|
|
os.makedirs('config/includes.bootstrap', exist_ok=True)
|
|
|
|
os.makedirs('config/includes.chroot', exist_ok=True)
|
|
|
|
os.makedirs('config/includes.binary', exist_ok=True)
|
|
|
|
os.makedirs('config/includes.source', exist_ok=True)
|
|
|
|
|
|
|
|
# Configuring default package lists
|
|
|
|
os.makedirs('config/package-lists', exist_ok=True)
|
|
|
|
|
|
|
|
f = open('config/package-lists/live.list.chroot', 'a')
|
|
|
|
f.write('live-boot\nlive-config\nlive-config-sysvinit\n')
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
## stagefile
|
|
|
|
os.makedirs('.build', exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|