Commits

stacklet  committed f329a73

Slackware 14 tasks

  • Participants
  • Parent commits 5a63d39

Comments (0)

Files changed (1)

File src/stacklet/task/distro/slack14.py

+# Copyright (C) 2009, dfn@stacklet.com
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+"""Tasks for creating slackware images.
+
+Please see docstring of each class for usage.
+
+"""
+from stacklet.util.objectify import _XO_
+from stacklet.util.objectify import *
+from stacklet.task.stacktask import *
+from stacklet.task.stackerror import *
+
+class _XO_bootstrap(_XO_, StackTask):
+    """Bootstrap a slackware image.  Image will be chrootable upon completion
+       of this task with network access to a package repository.
+
+      Internally it downloads all packages listed in <buildContext.mountPoint>/bootstrap/corePackages
+      from argument url. Install the packages to buildContext.mountPoint.
+      Finally, copy the hosts's resolv.conf into the image.
+
+    Task Arguments:
+    url -- the location to download packages from.  Ftp server is required if corePackages uses wildcards
+    repository -- appended to url arg when downloading files, will be 'slackware' or 'slackware64'
+    proxy -- (optional) proxyhost[:port]
+
+    """
+    _TASK_NAME = 'bootstrap'
+
+    def __init__(self):
+        pass
+
+    def process(self, buildContext):
+        try:
+            try:
+                self._buildContext = buildContext
+                self.log_info(buildContext, 'entering')
+                self.precheck(buildContext)
+                env = {'http_proxy': self._proxy}
+
+                slackURL = self._url + self._repository + '/'
+                cmd = 'wget -4 -c -nv --base=' + slackURL + ' -P ' + buildContext.mountPoint + '/bootstrap -i ' + self._corePackages
+                self.exec_command(buildContext, cmd, env=env)
+
+                cmd='tar --use-compress-program xz -xpf ' + buildContext.mountPoint + '/bootstrap/aaa_base-*.txz' + ' -C ' + buildContext.mountPoint
+                self.exec_command(buildContext, cmd)
+
+                cmd='cp ' + buildContext.inputDocAbsoluteFilePath + '/assets/busybox ' + buildContext.mountPoint + '/bin/'
+                self.exec_command(buildContext, cmd)
+
+                cmd='cp /etc/resolv.conf ' + buildContext.mountPoint + '/etc/'
+                self.exec_command(buildContext, cmd)
+
+                commands = list()
+                commands.append('. /install/doinst.sh')
+                self.exec_command_chroot_busybox(buildContext, commands)
+
+                self._install_bootstrap_package('etc', buildContext)
+                self._install_bootstrap_package('devs', buildContext)
+
+                cmd='tar --use-compress-program xz -xpf ' + buildContext.mountPoint + '/bootstrap/glibc-2*.txz' + ' -C ' + buildContext.mountPoint
+                self.exec_command(buildContext, cmd)
+
+                commands = list()
+                commands.append('ln -sf /bin/busybox /bin/cp')
+                commands.append('. /install/doinst.sh')
+                commands.append('rm /bin/cp')
+                self.exec_command_chroot_busybox(buildContext, commands)
+
+                self._install_bootstrap_package('coreutils', buildContext)
+                self._install_bootstrap_package('libtermcap', buildContext)
+                self._install_bootstrap_package('grep', buildContext)
+                self._install_bootstrap_package('bash', buildContext)
+                self._install_bootstrap_package('tar', buildContext, compressProgram = None)
+                self._install_bootstrap_package('gzip', buildContext)
+                self._install_bootstrap_package('bin', buildContext)
+                self._install_bootstrap_package('pkgtools', buildContext, compressProgram = None)
+                self._install_bootstrap_package('which', buildContext)
+                self._install_bootstrap_package('sed', buildContext)
+                self._install_bootstrap_package('aaa_elflibs', buildContext)
+                self._install_bootstrap_package('gawk', buildContext)
+                self._install_bootstrap_package('wget', buildContext)
+                self._install_bootstrap_package('openssl-solibs', buildContext)
+                self._install_bootstrap_package('bzip2', buildContext)
+                self._install_bootstrap_package('util-linux', buildContext)
+                self._install_bootstrap_package('xz', buildContext, compressProgram = None)
+                self._install_bootstrap_package('slackpkg', buildContext, compressProgram = None)
+
+                commands = list()
+                commands.append("installpkg /bootstrap/*.t*z")
+                commands.append("sed -i.save -e 's/DIALOG=on/DIALOG=off/' /etc/slackpkg/slackpkg.conf")
+                commands.append("sed -i -e 's/BATCH=off/BATCH=on/' /etc/slackpkg/slackpkg.conf")
+                commands.append("sed -i -e 's/DEFAULT_ANSWER=n/DEFAULT_ANSWER=y/' /etc/slackpkg/slackpkg.conf")
+                commands.append("sed -i -e 's/CHECKGPG=on/CHECKGPG=off/' /etc/slackpkg/slackpkg.conf")
+                if not self.is_empty(self._arch):
+                    commands.append("echo ARCH=%s >> /etc/slackpkg/slackpkg.conf" % (self._arch))
+
+                commands.append('echo ' + self._url + ' >> /etc/slackpkg/mirrors')
+                commands.append('slackpkg update')
+                self.exec_command_chroot(buildContext, commands, env=env)
+
+            except TaskError, taskErr:
+                if taskErr.criticality == TaskError.ABORT_BUILD:
+                    raise
+                self.log_error(buildContext, taskErr)
+        finally:
+            self.log_info(buildContext, 'leaving')
+
+    def precheck(self, buildContext):
+        self.is_valid_build_context(buildContext)
+
+        self._url = self.get_value('url')
+        self._repository = self.get_value('repository')
+        self._arch = self.get_value('arch')
+        self._corePackages = buildContext.mountPoint + '/bootstrap/corePackages'
+        self._proxy = self.get_value('proxy')
+
+        if self.is_empty(self._url):
+            raise FieldError(self._TASK_NAME, TaskError.ABORT_TASK, 'url is required')
+
+        if self.is_empty(self._repository):
+            raise FieldError(self._TASK_NAME, TaskError.ABORT_TASK, 'repository is required')
+
+	if not os.access(self._corePackages, os.F_OK):
+            raise BuildError(self._TASK_NAME, TaskError.ABORT_TASK, 'Could not find ' + self._corePackages)
+
+
+    def _install_bootstrap_package(self, package, buildContext, compressProgram = 'xz'):
+
+      if compressProgram:
+        cmd='tar  --use-compress-program ' + compressProgram + ' -xpf ' + buildContext.mountPoint + '/bootstrap/' + package + '*.txz' + ' -C ' + buildContext.mountPoint
+      else:
+        cmd='tar -xzpf ' + buildContext.mountPoint + '/bootstrap/' + package + '*.tgz' + ' -C ' + buildContext.mountPoint
+      self.exec_command(buildContext, cmd)
+
+      commands = list()
+      commands.append('. /install/doinst.sh')
+      self.exec_command_chroot_busybox(buildContext, commands)
+
+
+
+stacklet.util.objectify._XO_bootstrap = _XO_bootstrap
+stacklet.util.objectify._XO_stk_bootstrap = _XO_bootstrap
+