def InstallComputeImagePackages(packages_dir): utils.LogStep('Install compute-image-packages') utils.Run([ "egrep -lRZ 'python' %s | " "xargs -0 -l sed -i -e '/#!.*python/c\#!/usr/bin/env python2'" % packages_dir ], shell=True) utils.CopyFiles(os.path.join(packages_dir, 'google-daemon', '*'), '/') utils.CopyFiles(os.path.join(packages_dir, 'google-startup-scripts', '*'), '/') utils.SecureDeleteFile('/README.md') # TODO: Fix gcimagebundle does not work with Arch yet. #InstallGcimagebundle(packages_dir) # Patch Google services to run after the network is actually available. PatchGoogleSystemdService( '/usr/lib/systemd/system/google-startup-scripts.service') PatchGoogleSystemdService( '/usr/lib/systemd/system/google-accounts-manager.service') PatchGoogleSystemdService( '/usr/lib/systemd/system/google-address-manager.service') PatchGoogleSystemdService('/usr/lib/systemd/system/google.service') utils.EnableService('google-accounts-manager.service') utils.EnableService('google-address-manager.service') utils.EnableService('google.service') utils.EnableService('google-startup-scripts.service') utils.DeleteDirectory(packages_dir)
def CreateArchImage(args, aur_packages): logging.info('Creating Arch Image') logging.info('========================') image_path = os.path.join(os.getcwd(), IMAGE_FILE) CreateBlankImage(image_path, size_gb=int(args.size_gb), fs_type=args.fs_type) mount_path = utils.CreateTempDirectory(base_dir='/') image_mapping = utils.ImageMapper(image_path, mount_path) try: image_mapping.InstallLoopback() image_mapping.Map() primary_mapping = image_mapping.GetFirstMapping() image_mapping_path = primary_mapping['path'] FormatImage(image_mapping_path) try: image_mapping.Mount() utils.CreateDirectory('/run/shm') utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm')) InstallArchLinux(mount_path) disk_uuid = SetupFileSystem(mount_path, image_mapping_path, args.fs_type) ConfigureArchInstall( args, mount_path, primary_mapping['parent'], disk_uuid, aur_packages) utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm')) PurgeDisk(mount_path) finally: image_mapping.Unmount() ShrinkDisk(image_mapping_path) finally: image_mapping.Unmap() utils.Run(['parted', image_path, 'set', '1', 'boot', 'on']) utils.Sync() logging.info('========================') return image_path
def ConfigureArchInstall(args, mount_path, parent_path, disk_uuid, aur_packages): relative_builder_path = utils.CopyBuilder(mount_path) packages_dir = utils.CreateTempDirectory(mount_path) utils.Run(['git', 'clone', COMPUTE_IMAGE_PACKAGES_GIT_URL, packages_dir]) utils.CreateDirectory(os.path.join(mount_path, '')) aur_packages_dir = os.path.join(packages_dir, 'aur') for aur_package in aur_packages: utils.CopyFiles(aur_package, aur_packages_dir + '/') packages_dir = os.path.relpath(packages_dir, mount_path) params = { 'packages_dir': '/%s' % packages_dir, 'device': parent_path, 'disk_uuid': disk_uuid, 'accounts': args.accounts, 'debugmode': args.debug, 'quiet': args.quiet, 'verbose': args.verbose, 'packages': args.packages, 'size_gb': args.size_gb } config_arch_py = os.path.join( '/', relative_builder_path, 'arch-image.py') utils.RunChroot(mount_path, '%s "%s"' % (config_arch_py, utils.EncodeArgs(params)), use_custom_path=False) utils.DeleteDirectory(os.path.join(mount_path, relative_builder_path))
def main(): args = utils.DecodeArgs(sys.argv[1]) utils.SetupLogging(quiet=args['quiet'], verbose=args['verbose']) logging.info('Setup Bootstrapper Environment') utils.SetupArchLocale() InstallPackagesForStagingEnvironment() image_path = os.path.join(os.getcwd(), IMAGE_FILE) CreateImage(image_path, size_gb=int(args['size_gb'])) mount_path = utils.CreateTempDirectory(base_dir='/') image_mapping = utils.ImageMapper(image_path, mount_path) try: image_mapping.Map() primary_mapping = image_mapping.GetFirstMapping() image_mapping_path = primary_mapping['path'] FormatImage(image_mapping_path) try: image_mapping.Mount() utils.CreateDirectory('/run/shm') utils.CreateDirectory(os.path.join(mount_path, 'run', 'shm')) InstallArchLinux(mount_path) disk_uuid = SetupFileSystem(mount_path, image_mapping_path) ConfigureArchInstall(args, mount_path, primary_mapping['parent'], disk_uuid) utils.DeleteDirectory(os.path.join(mount_path, 'run', 'shm')) PurgeDisk(mount_path) finally: image_mapping.Unmount() ShrinkDisk(image_mapping_path) finally: image_mapping.Unmap() utils.Run(['parted', image_path, 'set', '1', 'boot', 'on']) utils.Sync()
def ConfigureArchInstall(args, mount_path, parent_path, disk_uuid): relative_builder_path = utils.CopyBuilder(mount_path) utils.LogStep('Download compute-image-packages') packages_dir = utils.CreateTempDirectory(mount_path) utils.Run(['git', 'clone', COMPUTE_IMAGE_PACKAGES_GIT_URL, packages_dir]) utils.CreateDirectory(os.path.join(mount_path, '')) packages_dir = os.path.relpath(packages_dir, mount_path) params = { 'packages_dir': '/%s' % packages_dir, 'device': parent_path, 'disk_uuid': disk_uuid, 'accounts': args['accounts'], 'debugmode': args['debugmode'], } params.update(args) config_arch_py = os.path.join('/', relative_builder_path, 'arch-image.py') utils.RunChroot(mount_path, '%s "%s"' % (config_arch_py, utils.EncodeArgs(params)), use_custom_path=False) utils.DeleteDirectory(os.path.join(mount_path, relative_builder_path))
def main(): args = ParseArgs() utils.SetupLogging(quiet=args.quiet, verbose=args.verbose) logging.info('Arch Linux Image Builder') logging.info('========================') workspace_dir = None image_file = None try: aur_packages = InstallPackagesOnHostMachine() image_path = CreateArchImage(args, aur_packages) image_name, image_filename, image_description = GetImageNameAndDescription( args.outfile) image_file = SaveImage(image_path, image_filename) if args.upload and image_file: UploadImage(image_file, args.upload, make_public=args.public) if args.register: AddImageToComputeEngineProject( image_name, args.upload, image_description) finally: if not args.nocleanup and workspace_dir: utils.DeleteDirectory(workspace_dir)
def main(): args = ParseArgs() utils.SetupLogging(quiet=args.quiet, verbose=args.verbose) workspace_dir = None image_file = None try: workspace_dir = utils.CreateTempDirectory() bootstrap_file = DownloadArchBootstrap(args.bootstrap) utils.Untar(bootstrap_file, workspace_dir) arch_root = PrepareBootstrap(workspace_dir, args.mirror, not args.nopacmankeys) relative_builder_path = utils.CopyBuilder(arch_root) ChrootIntoArchAndBuild(arch_root, relative_builder_path, args) image_name, image_filename, image_description = GetImageNameAndDescription( args.outfile) image_file = SaveImage(arch_root, image_filename) if args.upload and image_file: UploadImage(image_file, args.upload, make_public=args.public) if args.register: AddImageToComputeEngineProject(image_name, args.upload, image_description) finally: if not args.nocleanup and workspace_dir: utils.DeleteDirectory(workspace_dir)
def PurgeDisk(mount_path): paths = ['/var/cache', '/var/log', '/var/lib/pacman/sync'] for path in paths: utils.DeleteDirectory(os.path.join(mount_path, path))