def __setup(self):
        """Construct the series of commands to execute"""

        if self.__extra_opts:
            self.__opts.extend(self.__extra_opts)

        apt_get_download = 'DEBIAN_FRONTEND=noninteractive apt-get download {}'.format(' '.join(self.__opts))
        apt_get_install = 'DEBIAN_FRONTEND=noninteractive apt-get install {}'.format(' '.join(self.__opts))

        if self.__keys:
            for key in self.__keys:
                if self.__apt_key:
                    self.__commands.append(
                        'wget -qO - {} | apt-key add -'.format(key))
                else:
                    self.__commands.extend([
                        'mkdir -p /usr/share/keyrings',
                        'rm -f /usr/share/keyrings/{}.gpg'.format(
                            os.path.splitext(os.path.basename(key))[0]),
                        'wget -qO - {0} | gpg --dearmor -o /usr/share/keyrings/{1}.gpg'.format(
                            key, os.path.splitext(os.path.basename(key))[0])])

        if self.__ppas:
            # Need to install apt-add-repository
            self.__commands.extend(['apt-get update -y',
                                    apt_get_install + ' software-properties-common'])
            for ppa in self.__ppas:
                self.__commands.append('apt-add-repository {} -y'.format(ppa))

        if self.__repositories:
            for repo in self.__repositories:
                if repo.startswith('http'):
                    # Repository is a URL to a repository configuration file
                    self.__commands.append(
                        self.download_step(directory='/etc/apt/sources.list.d',
                                           url=repo))
                else:
                    # Repository is a configuration string
                    self.__commands.append(
                        'echo "{}" >> /etc/apt/sources.list.d/hpccm.list'.format(repo))

        if self.ospackages:
            packages = []
            for pkg in sorted(self.ospackages):
                packages.append('        {}'.format(pkg))

            self.__commands.append('apt-get update -y')

            if self.__download:
                # Download packages
                # Assign mode 777 to work around warnings
                # Ubuntu 16: Can't drop privileges for downloading as file
                # Ubuntu 18: Download is performed unsandboxed as root as file
                self.__commands.append('mkdir -m 777 -p {0} && cd {0}'.format(
                    self.__download_directory))
                self.__commands.append(apt_get_download + ' \\\n' + ' \\\n'.join(packages))

                if self.__extract:
                    # Extract the packages to a prefix - not a "real"
                    # package manager install
                    self.__commands.append('mkdir -p {0}'.format(
                        self.__extract))

                    regex = posixpath.join(
                        self.__download_directory,
                        '(' + '|'.join(sorted(self.ospackages)) + ').*deb')
                    self.__commands.append('find {0} -regextype posix-extended -type f -regex "{1}" -exec dpkg --extract {{}} {2} \;'.format(self.__download_directory, regex, self.__extract))

                    # Cleanup downloaded packages
                    self.__commands.append(
                        'rm -rf {}'.format(self.__download_directory))

                # Cleanup repository file(s)
                for repo in self.__repositories:
                    if repo.startswith('http'):
                        # Repository is a URL to a repository
                        # configuration file
                        self.__commands.append(
                            'rm -f {}'.format(
                                posixpath.join('/etc/apt/sources.list.d',
                                               os.path.basename(repo))))
                    else:
                        # Repository is a configuration string
                        # Use '|' as separator to try to avoid conflicts or
                        # the need to escape the repo string.
                        self.__commands.append(
                            self.sed_step(
                                file='/etc/apt/sources.list.d/hpccm.list',
                                patterns=[r'\|^{}$|d'.format(repo)]))

            else:
                if self.__aptitude:
                    self.__commands.append(apt_get_install + ' aptitude')
                    install = 'aptitude install -y --without-recommends -o Aptitude::ProblemResolver::SolutionCost=\'100*canceled-actions,200*removals\' \\\n'
                    install = install + ' \\\n'.join(packages)
                    self.__commands.append(install)
                else:
                    self.__commands.append(apt_get_install + ' \\\n' + ' \\\n'.join(packages))

            self.__commands.append('rm -rf /var/lib/apt/lists/*')
Construct the series of commands to execute
hpccm/building_blocks/apt_get.py