Implement preos

remotes/origin/feature/shell-lib
Darko Poljak 5 years ago
parent eab540bd0f
commit 799ec72369
  1. 6
      cdist/argparse.py
  2. 101
      cdist/preos.py
  3. 1
      cdist/preos/debootstrap/__init__.py
  4. 240
      cdist/preos/debootstrap/debootstrap.py
  5. 274
      cdist/preos/debootstrap/files/code
  6. 18
      cdist/preos/debootstrap/files/devuan-debootstrap/Makefile
  7. 65
      cdist/preos/debootstrap/files/devuan-debootstrap/README
  8. 11
      cdist/preos/debootstrap/files/devuan-debootstrap/TODO
  9. 6
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/.gitignore
  10. 15
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/README.DevuanSource
  11. 2655
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/changelog
  12. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/compat
  13. 26
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/control
  14. 30
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/copyright
  15. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/debootstrap.docs
  16. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/debootstrap.manpages
  17. 9
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/gbp.conf
  18. 47
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/rules
  19. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/debian/source/format
  20. 703
      cdist/preos/debootstrap/files/devuan-debootstrap/debootstrap
  21. 189
      cdist/preos/debootstrap/files/devuan-debootstrap/debootstrap.8
  22. 1735
      cdist/preos/debootstrap/files/devuan-debootstrap/functions
  23. 202
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/aequorea
  24. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/ascii
  25. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/bartholomea
  26. 163
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/breezy
  27. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/bullseye
  28. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/buster
  29. 218
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/ceres
  30. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/chromodoris
  31. 168
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/dapper
  32. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/dasyatis
  33. 187
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/edgy
  34. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/etch
  35. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/etch-m68k
  36. 190
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/feisty
  37. 230
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/gutsy
  38. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/hardy
  39. 179
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/hoary
  40. 159
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/hoary.buildd
  41. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/intrepid
  42. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/jaunty
  43. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/jessie
  44. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/jessie-kfreebsd
  45. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/karmic
  46. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/lenny
  47. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/lucid
  48. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/maverick
  49. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/natty
  50. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/oldoldstable
  51. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/oldstable
  52. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/oneiric
  53. 104
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/potato
  54. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/precise
  55. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/quantal
  56. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/raring
  57. 218
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/sarge
  58. 166
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/sarge.buildd
  59. 171
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/sarge.fakechroot
  60. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/saucy
  61. 214
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/sid
  62. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/squeeze
  63. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/stable
  64. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/stretch
  65. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/testing
  66. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/trusty
  67. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/unstable
  68. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/utopic
  69. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/vivid
  70. 166
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/warty
  71. 159
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/warty.buildd
  72. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/wheezy
  73. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/wily
  74. 203
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/woody
  75. 166
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/woody.buildd
  76. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/xenial
  77. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/yakkety
  78. 1
      cdist/preos/debootstrap/files/devuan-debootstrap/scripts/zesty
  79. 39
      cdist/preos/debootstrap/files/init-manifest-debian
  80. 39
      cdist/preos/debootstrap/files/init-manifest-devuan
  81. 39
      cdist/preos/debootstrap/files/init-manifest-ubuntu
  82. 8
      cdist/preos/debootstrap/files/remote-copy.sh
  83. 24
      cdist/preos/debootstrap/files/remote-exec.sh
  84. 2
      completions/bash/cdist-completion.bash
  85. 2
      completions/zsh/_cdist
  86. 1
      docs/changelog
  87. 137
      docs/src/cdist-preos.rst
  88. 3
      docs/src/cdist-reference.rst.sh
  89. 1
      docs/src/index.rst
  90. 172
      docs/src/man1/cdist.rst
  91. 32
      hacking/preos-sh/init
  92. 31
      hacking/preos-sh/preos.sh
  93. 8
      hacking/preos-sh/remote-copy.sh
  94. 24
      hacking/preos-sh/remote-exec.sh
  95. 3
      scripts/cdist

6
cdist/argparse.py vendored

@ -5,10 +5,11 @@ import logging
import collections
import functools
import cdist.configuration
import cdist.preos
# set of beta sub-commands
BETA_COMMANDS = set(('install', 'inventory', ))
BETA_COMMANDS = set(('install', 'inventory', 'preos', ))
# set of beta arguments for sub-commands
BETA_ARGS = {
'config': set(('tag', 'all_tagged_hosts', 'use_archiving', )),
@ -422,6 +423,9 @@ def get_parsers():
parser['inventory'].set_defaults(
func=cdist.inventory.Inventory.commandline)
# PreOs
parser['preos'] = parser['sub'].add_parser('preos', add_help=False)
# Shell
parser['shell'] = parser['sub'].add_parser(
'shell', parents=[parser['loglevel']])

101
cdist/preos.py vendored

@ -0,0 +1,101 @@
import os
import os.path
import sys
import inspect
import argparse
import cdist
import logging
_PREOS_CALL = "commandline"
_PREOS_NAME = "_preos_name"
_PREOS_MARKER = "_cdist_preos"
_PLUGINS_DIR = "preos"
_PLUGINS_PATH = [os.path.join(os.path.dirname(__file__), _PLUGINS_DIR), ]
cdist_home = cdist.home_dir()
if cdist_home:
cdist_home_preos = os.path.join(cdist_home, "preos")
if os.path.isdir(cdist_home_preos):
_PLUGINS_PATH.append(cdist_home_preos)
sys.path.extend(_PLUGINS_PATH)
log = logging.getLogger("PreOS")
def preos_plugin(obj):
"""It is preos if _PREOS_MARKER is True and has _PREOS_CALL."""
if hasattr(obj, _PREOS_MARKER):
is_preos = getattr(obj, _PREOS_MARKER)
else:
is_preos = False
if is_preos and hasattr(obj, _PREOS_CALL):
yield obj
def scan_preos_dir_plugins(dir):
for fname in os.listdir(dir):
if os.path.isfile(os.path.join(dir, fname)):
fname = os.path.splitext(fname)[0]
module_name = fname
try:
module = __import__(module_name)
yield from preos_plugin(module)
clsmembers = inspect.getmembers(module, inspect.isclass)
for cm in clsmembers:
c = cm[1]
yield from preos_plugin(c)
except ImportError as e:
log.warning("Cannot import '{}': {}".format(module_name, e))
def find_preos_plugins():
for dir in _PLUGINS_PATH:
yield from scan_preos_dir_plugins(dir)
def find_preoses():
preoses = {}
for preos in find_preos_plugins():
if hasattr(preos, _PREOS_NAME):
preos_name = getattr(preos, _PREOS_NAME)
else:
preos_name = preos.__name__.lower()
preoses[preos_name] = preos
return preoses
def check_root():
if os.geteuid() != 0:
raise cdist.Error("Must be run with root privileges")
class PreOS(object):
preoses = None
@classmethod
def commandline(cls, argv):
if not cls.preoses:
cls.preoses = find_preoses()
parser = argparse.ArgumentParser(
description="Create PreOS", prog="cdist preos")
parser.add_argument('preos', help='PreOS to create, one of: {}'.format(
set(cls.preoses)))
args = parser.parse_args(argv[1:2])
preos_name = args.preos
if preos_name in cls.preoses:
preos = cls.preoses[preos_name]
func = getattr(preos, _PREOS_CALL)
if inspect.ismodule(preos):
func_args = [preos, argv[2:], ]
else:
func_args = [argv[2:], ]
log.info("Running preos : {}".format(preos_name))
func(*func_args)
else:
log.error("Unknown preos: {}, available preoses: {}".format(
preos_name, set(cls.preoses.keys())))

@ -0,0 +1 @@
from debootstrap.debootstrap import Debian, Ubuntu, Devuan

@ -0,0 +1,240 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 2016 Darko Poljak (darko.poljak at ungleich.ch)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
import cdist
import cdist.config
import cdist.core
import cdist.preos
import argparse
import cdist.argparse
import logging
import os
import subprocess
class Debian(object):
_preos_name = 'debian'
_cdist_preos = True
_files_dir = os.path.join(os.path.dirname(__file__), "files")
@classmethod
def default_args(cls):
default_remote_exec = os.path.join(cls._files_dir, "remote-exec.sh")
default_remote_copy = os.path.join(cls._files_dir, "remote-copy.sh")
default_init_manifest = os.path.join(
cls._files_dir, "init-manifest-{}".format(cls._preos_name))
defargs = argparse.Namespace()
defargs.arch = 'amd64'
defargs.bootstrap = False
defargs.configure = False
defargs.cdist_params = '-v'
defargs.rm_bootstrap_dir = False
defargs.suite = 'stable'
defargs.remote_exec = default_remote_exec
defargs.remote_copy = default_remote_copy
defargs.manifest = default_init_manifest
return defargs
@classmethod
def get_parser(cls):
defargs = cls.default_args()
cdist_parser = cdist.argparse.get_parsers()
parser = argparse.ArgumentParser(
prog='cdist preos {}'.format(cls._preos_name),
parents=[cdist_parser['loglevel'], cdist_parser['beta']])
parser.add_argument('target_dir', nargs=1,
help=("target directory where PreOS will be "
"bootstrapped"))
parser.add_argument(
'-a', '--arch',
help="target debootstrap architecture, by default '{}'".format(
defargs.arch), dest='arch', default=defargs.arch)
parser.add_argument(
'-B', '--bootstrap',
help='do bootstrap step',
dest='bootstrap', action='store_true', default=defargs.bootstrap)
parser.add_argument(
'-C', '--configure',
help='do configure step',
dest='configure', action='store_true', default=defargs.configure)
parser.add_argument(
'-c', '--cdist-params',
help=("parameters that will be passed to cdist config, by default"
" '{}' is used".format(defargs.cdist_params)),
dest='cdist_params', default=defargs.cdist_params)
parser.add_argument(
'-D', '--drive-boot',
help='create bootable PreOS on specified drive',
dest='drive')
parser.add_argument(
'-e', '--remote-exec',
help=("remote exec that cdist config will use, by default "
"internal script is used"),
dest='remote_exec', default=defargs.remote_exec)
parser.add_argument(
'-i', '--init-manifest',
help=("init manifest that cdist config will use, by default "
"internal init manifest is used"),
dest='manifest', default=defargs.manifest)
parser.add_argument(
'-k', '--keyfile', action="append",
help=("ssh key files that will be added to cdist config; "
"'__ssh_authorized_keys root ...' type is appended to "
"initial manifest"),
dest='keyfile')
parser.add_argument(
'-m', '--mirror',
help='use specified mirror for debootstrap',
dest='mirror')
parser.add_argument(
'-P', '--root-password',
help='Set specified password for root, generated by default',
dest='root_password')
parser.add_argument('-p', '--pxe-boot-dir', help='PXE boot directory',
dest='pxe_boot_dir')
parser.add_argument(
'-r', '--rm-bootstrap-dir',
help='remove target directory after finishing',
dest='rm_bootstrap_dir', action='store_true',
default=defargs.rm_bootstrap_dir)
parser.add_argument(
'-S', '--script',
help='use specified script for debootstrap',
dest='script')
parser.add_argument('-s', '--suite',
help="suite used for debootstrap, "
"by default '{}'".format(defargs.suite),
dest='suite', default=defargs.suite)
parser.add_argument(
'-y', '--remote-copy',
help=("remote copy that cdist config will use, by default "
"internal script is used"),
dest='remote_copy', default=defargs.remote_copy)
parser.epilog = cdist.argparse.EPILOG
return parser
@classmethod
def update_env(cls, env):
pass
@classmethod
def commandline(cls, argv):
log = logging.getLogger(cls.__name__)
parser = cls.get_parser()
cdist.argparse.add_beta_command(cls._preos_name)
args = parser.parse_args(argv)
if args.script and not args.mirror:
raise cdist.Error("script option cannot be used without "
"mirror option")
args.command = cls._preos_name
cdist.argparse.check_beta(vars(args))
cdist.preos.check_root()
args.target_dir = os.path.realpath(args.target_dir[0])
args.os = cls._preos_name
args.remote_exec = os.path.realpath(args.remote_exec)
args.remote_copy = os.path.realpath(args.remote_copy)
args.manifest = os.path.realpath(args.manifest)
if args.keyfile:
new_keyfile = [os.path.realpath(x) for x in args.keyfile]
args.keyfile = new_keyfile
if args.pxe_boot_dir:
args.pxe_boot_dir = os.path.realpath(args.pxe_boot_dir)
cdist.argparse.handle_loglevel(args)
log.debug("preos: {}, args: {}".format(cls._preos_name, args))
try:
env = vars(args)
new_env = {}
for key in env:
if key == 'verbose':
if env[key] >= 3:
new_env['debug'] = "yes"
elif env[key] == 2:
new_env['verbose'] = "yes"
elif not env[key]:
new_env[key] = ''
elif isinstance(env[key], bool) and env[key]:
new_env[key] = "yes"
elif isinstance(env[key], list):
val = env[key]
new_env[key + "_cnt"] = str(len(val))
for i, v in enumerate(val):
new_env[key + "_" + str(i)] = v
else:
new_env[key] = str(env[key])
env = new_env
env.update(os.environ)
cls.update_env(env)
log.debug("preos: {} env: {}".format(cls._preos_name, env))
cmd = os.path.join(cls._files_dir, "code")
info_msg = ["Running preos: {}, suite: {}, arch: {}".format(
cls._preos_name, args.suite, args.arch), ]
if args.mirror:
info_msg.append("mirror: {}".format(args.mirror))
if args.script:
info_msg.append("script: {}".format(args.script))
if args.bootstrap:
info_msg.append("bootstrapping")
if args.configure:
info_msg.append("configuring")
if args.pxe_boot_dir:
info_msg.append("creating PXE")
if args.drive:
info_msg.append("creating bootable drive")
log.info(info_msg)
log.debug("cmd={}".format(cmd))
subprocess.check_call(cmd, env=env, shell=True)
except subprocess.CalledProcessError as e:
log.error("preos {} failed: {}".format(cls._preos_name, e))
class Ubuntu(Debian):
_preos_name = "ubuntu"
@classmethod
def default_args(cls):
defargs = super().default_args()
defargs.suite = 'xenial'
return defargs
class Devuan(Debian):
_preos_name = "devuan"
@classmethod
def default_args(cls):
defargs = super().default_args()
defargs.suite = 'jessie'
return defargs
@classmethod
def update_env(cls, env):
env['DEBOOTSTRAP_DIR'] = os.path.join(cls._files_dir,
'devuan-debootstrap')

@ -0,0 +1,274 @@
#!/bin/sh
##
## 2016 Darko Poljak (darko.poljak at ungleich.ch)
##
## This file is part of cdist.
##
## cdist is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## cdist 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.
##
## You should have received a copy of the GNU General Public License
## along with cdist. If not, see <http://www.gnu.org/licenses/>.
set -e
if [ "${debug}" ]
then
set -x
cdist_params="${cdist_params} -d"
fi
bootstrap_dir="${target_dir}"
case "${os}" in
ubuntu|debian|devuan)
# nothing, those are valid values
;;
*)
echo "ERROR: invalid os value: ${os}" >&2
exit 1
;;
esac
check_bootstrap_dir() {
if [ ! -e "$1" ]
then
echo "ERROR: bootstrap directory $1 does not exist" >&2
exit 1
fi
}
# bootstrap
if [ "${bootstrap}" ]
then
if [ "${DEBOOTSTRAP_DIR}" ]
then
debootstrap_cmd="${DEBOOTSTRAP_DIR}/debootstrap"
else
command -v debootstrap 2>&1 > /dev/null || {
echo "ERROR: debootstrap not found" >&2
exit 1
}
debootstrap_cmd="debootstrap"
fi
# If PreOS on drive then do not check for directory emptiness.
# Partition can at least contain 'lost+found' directory.
if [ ! "${drive}" ]
then
if [ -e "${bootstrap_dir}" ]
then
dir_content=$(ls -A "${bootstrap_dir}" | wc -l)
else
dir_content=0
fi
if [ "${dir_content}" -ne 0 ]
then
echo "ERROR: "${bootstrap_dir}" not empty " >&2
exit 1
fi
fi
if [ "${verbose}" -o "${debug}" ]
then
echo "bootstrapping..."
fi
mkdir -p "${bootstrap_dir}"
"${debootstrap_cmd}" --include=openssh-server --arch=${arch} ${suite} ${bootstrap_dir} \
${mirror} ${script}
if [ "${verbose}" -o "${debug}" ]
then
echo "bootstrap finished"
fi
fi
chroot_mount() {
mount -t proc none "${bootstrap_dir}/proc" || true
mount -t sysfs none "${bootstrap_dir}/sys" || true
mount -o bind /dev "${bootstrap_dir}/dev" || true
mount -t devpts none "${bootstrap_dir}/dev/pts" || true
}
chroot_umount() {
umount "${bootstrap_dir}/dev/pts" || true
umount "${bootstrap_dir}/dev" || true
umount "${bootstrap_dir}/sys" || true
umount "${bootstrap_dir}/proc" || true
}
TRAPFUNC="umount \"${bootstrap_dir}/dev/pts\" || true; \
umount \"${bootstrap_dir}/dev\" || true; \
umount \"${bootstrap_dir}/sys\" || true; \
umount \"${bootstrap_dir}/proc\" || true;"
# config
if [ "${configure}" ]
then
if [ ! -f "${manifest}" ]
then
echo "ERROR: ${manifest} does not exist" >&2
exit 1
fi
if [ ! -f "${remote_exec}" ]
then
echo "ERROR: ${remote_exec} does not exist" >&2
exit 1
fi
if [ ! -f "${remote_copy}" ]
then
echo "ERROR: ${remote_copy} does not exist" >&2
exit 1
fi
if [ "${keyfile_cnt}" -a "${keyfile_cnt}" -gt 0 ]
then
i="$((keyfile_cnt - 1))"
keyfiles=""
while [ "${i}" -ge 0 ]
do
kf_var="keyfile_${i}"
eval kf='$'"${kf_var}"
if [ ! -f "${kf}" ]
then
echo "ERROR: ${kf} does not exist" >&2
exit 1
fi
key=$(cat "${kf}")
keyfiles="${keyfiles} --key '${key}'"
i=$((i - 1))
done
ssh_auth_keys_line="__ssh_authorized_keys root ${keyfiles}\n"
else
ssh_auth_keys_line=""
fi
check_bootstrap_dir "${bootstrap_dir}"
if [ "${verbose}" -o "${debug}" ]
then
echo "configuring..."
fi
trap "${TRAPFUNC}" 0 1 2 3 15
chroot_mount
chroot "${bootstrap_dir}" /usr/bin/apt-get update
if [ "${drive}" ]
then
grub_manifest_line="__package grub-pc --state present\n"
grub_kern_params_line="__line linux_kernel_params \
--file /etc/default/grub \
--line 'GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash net.ifnames=0\"'\n"
else
grub_manifest_line=""
grub_kern_params_line=""
fi
grub_lines="${grub_manifest_line}${grub_kern_params_line}"
printf "${ssh_auth_keys_line}${grub_lines}" \
| cat "${manifest}" - |\
cdist config \
${cdist_params} -i - \
--remote-exec "${remote_exec}" \
--remote-copy "${remote_copy}" \
"${bootstrap_dir}"
# __hostname with systmed uses hostnamectl which needs dbus running
# set hostname explicitly here instead
printf "preos\n" > "${bootstrap_dir}/etc/hostname"
chroot "${bootstrap_dir}" /usr/bin/apt-get autoclean
chroot "${bootstrap_dir}" /usr/bin/apt-get clean
chroot "${bootstrap_dir}" /usr/bin/apt-get autoremove
chroot_umount
trap - 0 1 2 3 15
if [ "${verbose}" -o "${debug}" ]
then
echo "configuring finished"
fi
fi
if [ "${pxe_boot_dir}" ]
then
check_bootstrap_dir "${bootstrap_dir}"
if [ "${verbose}" -o "${debug}" ]
then
echo "creating pxe..."
fi
mkdir -p "${pxe_boot_dir}"
cp "${bootstrap_dir}"/boot/vmlinuz-* "${pxe_boot_dir}/kernel"
cd "${bootstrap_dir}"
find . -print0 | cpio --null -o --format=newc | gzip -9 > "${pxe_boot_dir}/initramfs"
mkdir -p "${pxe_boot_dir}/pxelinux.cfg"
cat <<EOPXEF > "${pxe_boot_dir}/pxelinux.cfg/default"
DEFAULT preos
LABEL preos
KERNEL kernel
APPEND utf8 load_ramdisk=1 root=/dev/ram nofb initrd=initramfs console=ttyS1,115200 net.ifnames=0
EOPXEF
cp "${bootstrap_dir}/usr/lib/PXELINUX/pxelinux.0" "${pxe_boot_dir}/pxelinux.0"
cp "${bootstrap_dir}/usr/lib/syslinux/modules/bios/ldlinux.c32" \
"${pxe_boot_dir}/ldlinux.c32"
# network boot need all files world readable
chmod -R 644 "${pxe_boot_dir}"/*
if [ "${verbose}" -o "${debug}" ]
then
echo "pxe creation finished"
fi
fi
if [ "${drive}" ]
then
trap "${TRAPFUNC}" 0 1 2 3 15
chroot_mount
chroot "${bootstrap_dir}" grub-install ${drive}
chroot "${bootstrap_dir}" /bin/sh -c "GRUB_DISABLE_OS_PROBER=true update-grub"
# set root password
if [ ! "${root_password}" ]
then
if ! which strings >/dev/null 2>&1
then
printf "strings is missing\n" >&2
exit 1
fi
root_password="$(head -n 1000 /dev/urandom | strings | \
grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n')"
printf "Generated root password (without quotes):'${root_password}'\n"
fi
chroot "${bootstrap_dir}" /bin/sh -c "echo \"root:${root_password}\" | \
chpasswd"
# /etc/securetty must not be world writeable.
chmod 644 "${bootstrap_dir}"/etc/securetty
chroot_umount
trap - 0 1 2 3 15
fi
if [ "${rm_bootstrap_dir}" ]
then
if [ "${verbose}" -o "${debug}" ]
then
echo "removing bootstrap dir..."
fi
rm -r -f "${bootstrap_dir}"
if [ "${verbose}" -o "${debug}" ]
then
echo "removing bootstrap dir finished"
fi
fi

@ -0,0 +1,18 @@
# avoid dpkg-dev dependency; fish out the version with sed
VERSION := $(shell sed 's/.*(\(.*\)).*/\1/; q' debian/changelog)
all:
clean:
DSDIR=$(DESTDIR)/usr/share/debootstrap
install:
mkdir -p $(DSDIR)/scripts
mkdir -p $(DESTDIR)/usr/sbin
cp -a scripts/* $(DSDIR)/scripts/
install -o root -g root -m 0644 functions $(DSDIR)/
sed 's/@VERSION@/$(VERSION)/g' debootstrap >$(DESTDIR)/usr/sbin/debootstrap
chown root:root $(DESTDIR)/usr/sbin/debootstrap
chmod 0755 $(DESTDIR)/usr/sbin/debootstrap

@ -0,0 +1,65 @@
README for debootstrap
======================
See the manpage for (some) documentation.
Running debootstrap from source
-------------------------------
You can run debootstrap from its source tree without installing it. This
can be useful if you want a quick way to make a Debian chroot on another
system, or if you are testing modifications to debootstrap.
First, get the source.
* Either by using git
git clone https://anonscm.debian.org/git/d-i/debootstrap.git
* Or by visiting <https://packages.debian.org/source/sid/debootstrap>
and downloading the tar.gz file
Then in the debootstrap source directory:
export DEBOOTSTRAP_DIR=`pwd`
sudo ./debootstrap stable my-stable-dir
If you are running a multi-stage boot strap (for example for a QEMU
rootfs) you don't even need root:
export DEBOOTSTRAP_DIR=`pwd`
fakeroot ./debootstrap --foreign --arch=armhf testing my-testing-dir http://deb.debian.org/debian
Of course you will need to execute the second stage as root to finish the bootstrap:
(on foreign hardware)
/debootstrap/debootstrap --second-stage
Future
------
* Cross-strap support - so you can bootstrap a filesystem to the
point where it will successfully boot, and finish installing itself
without having to be running the target architecture or OS yourself.
debootstrap --arch powerpc sarge ./sarge-ppc-chroot ...
on an i386 system, boot a powerpc box with sarge-ppc-chroot as its
root files system, and have it "work". The cross-hurd package does
something similar, and should be replaced by this feature.
* There should be some (better) way of telling debootstrap what "base"
packages you want to install -- this varies between making a chroot,
doing an install, and doing a buildd. Also, some installs want
different base packages (to setup networking, or kernels, eg)
NMUing
------
If there's a problem with debootstrap that you need fixed, feel free to do
an NMU to fix it. Usual rules: try not to break anything, and mail the
patch to the BTS. Don't worry about asking first though.
However, note that debootstrap is now team maintained. Anyone in d-i can do
a release without the bother of a NMU.

@ -0,0 +1,11 @@
Features:
++ second stage via chroot debootstrap/debootstrap
++ debootstrap/deb file to record deb destinations/information
-- configuration file
-- versus command line
-- support for sources (vs mirrors)
-- faux-pinning for packages
++ makedev in second stage

@ -0,0 +1,6 @@
debootstrap
debootstrap-udeb
files
*.debhelper.log
*.substvars

@ -0,0 +1,15 @@
To sync up with debians source for inspiration you should run the following:
`git remote add alioth-git git://anonscm.debian.org/d-i/debootstrap.git`
`git fetch alioth-git`
After that you can either cherry-pick or merge releases from debian. To
merge a release, it's do:
`git tag` to list the release tags
and
`git merge <tag>`
followed by all the fixups and then commit with an appropriate message like
"Merging Release <tag> from debian"
Copyright 2016 Daniel Reurich <daniel@centurion.net.nz>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,26 @@
Source: debootstrap
Section: admin
Priority: extra
Maintainer: Franco (nextime) Lanza <nextime@devuan.org>
Uploaders: Franco (nextime) Lanza <nextime@devuan.org>, Daniel Reurich <daniel@centurion.net.nz>
Build-Depends: debhelper (>= 9), makedev (>= 2.3.1-69) [linux-any], git
Standards-Version: 3.9.8
Vcs-Browser: https://git.devuan.org/devuan-packages/debootstrap
Vcs-Git: https://git.devuan.org/devuan-packages/debootstrap.git
Package: debootstrap
Architecture: all
Depends: ${misc:Depends}, wget
Recommends: gnupg, ${keyring}, devuan-keyring
Description: Bootstrap a basic Devuan system
debootstrap is used to create a Devuan base system from scratch,
without requiring the availability of dpkg or apt. It does this by
downloading .deb files from a mirror site, and carefully unpacking them
into a directory which can eventually be chrooted into.
Package: debootstrap-udeb
Section: debian-installer
Package-Type: udeb
Architecture: all
Depends: ${misc:Depends}, mounted-partitions
Description: Bootstrap the Devuan system

@ -0,0 +1,30 @@
This package was debianized by Anthony Towns <ajt@debian.org> on
Tue, 30 Jan 2001 10:54:45 +1000.
It was written from scratch for Debian by Anthony Towns <ajt@debian.org>
based loosely on the code for constructing base tarballs as part of the
boot-floppies package.
Copyright:
Copyright (c) 2001-2005 Anthony Towns
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,9 @@
[DEFAULT]
compression = xz
pristine-tar = false
upstream-tag = devuan/1.0.85
[git-buildpackage]
upstream-tree = tag
tarball-dir = ../tarballs/
export-dir = ../build-area/

@ -0,0 +1,47 @@
#! /usr/bin/make -f
ifeq (0,$(shell dpkg-vendor --derives-from Ubuntu; echo $$?))
KEYRING := ubuntu-keyring
else ifeq (0,$(shell dpkg-vendor --derives-from Devuan; echo $$?))
KEYRING := devuan-keyring
else ifeq (0,$(shell dpkg-vendor --derives-from Tanglu; echo $$?))
KEYRING := tanglu-archive-keyring
else
KEYRING := debian-archive-keyring
endif
%:
dh $@
# need to be root to make devices, so build is done in install target
override_dh_auto_build:
override_dh_auto_install:
dh_auto_build
$(MAKE) install DESTDIR=$(CURDIR)/debian/debootstrap
$(MAKE) install DESTDIR=$(CURDIR)/debian/debootstrap-udeb
# remove scripts not needed by d-i
-rm -f debian/debootstrap-udeb/usr/share/debootstrap/scripts/potato \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/woody \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/sarge \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/warty \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/hoary \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/breezy \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/dapper \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/edgy \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/feisty \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/*.buildd \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/*.fakechroot \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/stable \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/testing \
debian/debootstrap-udeb/usr/share/debootstrap/scripts/unstable
override_dh_gencontrol:
dh_gencontrol -- -Vkeyring=$(KEYRING)
# Specify gzip to mitigate #770217:
override_dh_builddeb:
dh_builddeb -pdebootstrap -- -Zgzip
dh_builddeb -pdebootstrap-udeb -- -Zxz

@ -0,0 +1,703 @@
#!/bin/sh
set -e
VERSION='@VERSION@'
unset TMP TEMP TMPDIR || true
# might not be exported if we're running from init=/bin/sh or similar
export PATH
###########################################################################
if [ -z "$DEBOOTSTRAP_DIR" ]; then
if [ -x /debootstrap/debootstrap ]; then
DEBOOTSTRAP_DIR=/debootstrap
else
DEBOOTSTRAP_DIR=/usr/share/debootstrap
fi
fi
. $DEBOOTSTRAP_DIR/functions
exec 4>&1
LANG=C
USE_COMPONENTS=main
KEYRING=""
DISABLE_KEYRING=""
FORCE_KEYRING=""
VARIANT=""
MERGED_USR="no"
ARCH=""
HOST_ARCH=""
HOST_OS=""
KEEP_DEBOOTSTRAP_DIR=""
USE_DEBIANINSTALLER_INTERACTION=""
SECOND_STAGE_ONLY=""
PRINT_DEBS=""
CHROOTDIR=""
MAKE_TARBALL=""
EXTRACTOR_OVERRIDE=""
UNPACK_TARBALL=""
ADDITIONAL=""
EXCLUDE=""
VERBOSE=""
CERTIFICATE=""
CHECKCERTIF=""
PRIVATEKEY=""
DEF_MIRROR="http://packages.devuan.org/merged"
DEF_HTTPS_MIRROR="https://packages.devuan.org/merged"
export LANG USE_COMPONENTS EXCLUDE
umask 022
###########################################################################
## phases:
## finddebs dldebs printdebs first_stage second_stage
RESOLVE_DEPS=true
WHAT_TO_DO="finddebs dldebs first_stage second_stage"
am_doing_phase () {
# usage: if am_doing_phase finddebs; then ...; fi
local x;
for x in "$@"; do
if echo " $WHAT_TO_DO " | grep -q " $x "; then return 0; fi
done
return 1
}
###########################################################################
usage_err()
{
info USAGE1 "usage: [OPTION]... <suite> <target> [<mirror> [<script>]]"
info USAGE2 "Try \`${0##*/} --help' for more information."
error "$@"
}
usage()
{
echo "Usage: ${0##*/} [OPTION]... <suite> <target> [<mirror> [<script>]]"
echo "Bootstrap a Debian base system into a target directory."
echo
cat <<EOF
--help display this help and exit
--version display version information and exit
--verbose don't turn off the output of wget
--download-only download packages, but don't perform installation
--print-debs print the packages to be installed, and exit
--arch=A set the architecture to install (use if no dpkg)
[ --arch=powerpc ]
--include=A,B,C adds specified names to the list of base packages
--exclude=A,B,C removes specified packages from the list
--components=A,B,C use packages from the listed components of the
archive
--variant=X use variant X of the bootstrap scripts
(currently supported variants: buildd, fakechroot,
minbase)
--merged-usr make /{bin,sbin,lib}/ symlinks to /usr/
--keyring=K check Release files against keyring K
--no-check-gpg avoid checking Release file signatures
--force-check-gpg force checking Release file signatures
(also disables automatic fallback to HTTPS in case
of a missing keyring), aborting otherwise
--no-resolve-deps don't try to resolve dependencies automatically
--unpack-tarball=T acquire .debs from a tarball instead of http
--make-tarball=T download .debs and create a tarball (tgz format)
--second-stage-target=DIR
Run second stage in a subdirectory instead of root
(can be used to create a foreign chroot)
(requires --second-stage)
--extractor=TYPE override automatic .deb extractor selection
(supported: $EXTRACTORS_SUPPORTED)
--debian-installer used for internal purposes by debian-installer
--private-key=file read the private key from file
--certificate=file use the client certificate stored in file (PEM)
--no-check-certificate do not check certificate against certificate authorities
EOF
}
###########################################################################
if [ -z "$PKGDETAILS" ]; then
error 1 NO_PKGDETAILS "No pkgdetails available; either install perl, or build pkgdetails.c from the base-installer source package"
fi
###########################################################################
if [ $# != 0 ] ; then
while true ; do
case "$1" in
--help)
usage
exit 0
;;
--version)
echo "debootstrap $VERSION"
exit 0
;;
--debian-installer)
if ! (echo -n "" >&3) 2>/dev/null; then
error 1 ARG_DIBYHAND "If running debootstrap by hand, don't use --debian-installer"
fi
USE_DEBIANINSTALLER_INTERACTION=yes
shift
;;
--foreign)
if [ "$PRINT_DEBS" != "true" ]; then
WHAT_TO_DO="finddebs dldebs first_stage"
fi
shift
;;
--second-stage)
WHAT_TO_DO="second_stage"
SECOND_STAGE_ONLY=true
shift
;;
--second-stage-target|--second-stage-target=?*)
if [ "$SECOND_STAGE_ONLY" != "true" ] ; then
error 1 STAGE2ONLY "option %s only applies in the second stage" "$1"
fi
if [ "$1" = "--second-stage-target" -a -n "$2" ] ; then
CHROOTDIR="$2"
shift 2
elif [ "$1" != "${1#--second-stage-target=}" ]; then
CHROOTDIR="${1#--second-stage-target=}"
shift
else
error 1 NEEDARG "option requires an argument: %s" "$1"
fi
;;
--print-debs)
WHAT_TO_DO="finddebs printdebs kill_target"
PRINT_DEBS=true
shift
;;
--download-only)
WHAT_TO_DO="finddebs dldebs"
shift
;;
--make-tarball|--make-tarball=?*)
WHAT_TO_DO="finddebs dldebs maketarball kill_target"
if [ "$1" = "--make-tarball" -a -n "$2" ] ; then
MAKE_TARBALL="$2"
shift 2
elif [ "$1" != "${1#--make-tarball=}" ]; then
MAKE_TARBALL="${1#--make-tarball=}"
shift
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--resolve-deps)
# redundant, but avoids breaking compatibility
RESOLVE_DEPS=true
shift
;;
--no-resolve-deps)
RESOLVE_DEPS=false
shift
;;
--keep-debootstrap-dir)
KEEP_DEBOOTSTRAP_DIR=true
shift
;;
--arch|--arch=?*)
if [ "$1" = "--arch" -a -n "$2" ] ; then
ARCH="$2"
shift 2
elif [ "$1" != "${1#--arch=}" ]; then
ARCH="${1#--arch=}"
shift
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--extractor|--extractor=?*)
if [ "$1" = "--extractor" -a -n "$2" ] ; then
EXTRACTOR_OVERRIDE="$2"
shift 2
elif [ "$1" != "${1#--extractor=}" ]; then
EXTRACTOR_OVERRIDE="${1#--extractor=}"
shift
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
if valid_extractor "$EXTRACTOR_OVERRIDE"; then
if ! type "$EXTRACTOR_OVERRIDE" >/dev/null 2>&1; then
error 1 MISSINGEXTRACTOR "The selected extractor cannot be found: %s" "$EXTRACTOR_OVERRIDE"
fi
else
error 1 BADEXTRACTOR "%s: unknown extractor" "$EXTRACTOR_OVERRIDE"
fi
;;
--unpack-tarball|--unpack-tarball=?*)
if [ "$1" = "--unpack-tarball" -a -n "$2" ] ; then
UNPACK_TARBALL="$2"
shift 2
elif [ "$1" != "${1#--unpack-tarball=}" ]; then
UNPACK_TARBALL="${1#--unpack-tarball=}"
shift
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
if [ ! -f "$UNPACK_TARBALL" ] ; then
error 1 NOTARBALL "%s: No such file or directory" "$UNPACK_TARBALL"
fi
;;
--include|--include=?*)
if [ "$1" = "--include" -a -n "$2" ]; then
ADDITIONAL="$2"
shift 2
elif [ "$1" != "${1#--include=}" ]; then
ADDITIONAL="${1#--include=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
ADDITIONAL="$(echo "$ADDITIONAL" | tr , " ")"
;;
--exclude|--exclude=?*)
if [ "$1" = "--exclude" -a -n "$2" ]; then
EXCLUDE="$2"
shift 2
elif [ "$1" != "${1#--exclude=}" ]; then
EXCLUDE="${1#--exclude=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
EXCLUDE="$(echo "$EXCLUDE" | tr , " ")"
;;
--verbose)
VERBOSE=true
export VERBOSE
shift 1
;;
--components|--components=?*)
if [ "$1" = "--components" -a -n "$2" ]; then
USE_COMPONENTS="$2"
shift 2
elif [ "$1" != "${1#--components=}" ]; then
USE_COMPONENTS="${1#--components=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
USE_COMPONENTS="$(echo "$USE_COMPONENTS" | tr , "|")"
;;
--variant|--variant=?*)
if [ "$1" = "--variant" -a -n "$2" ]; then
VARIANT="$2"
shift 2
elif [ "$1" != "${1#--variant=}" ]; then
VARIANT="${1#--variant=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--merged-usr)
MERGED_USR=yes
shift
;;
--no-merged-usr)
MERGED_USR=no
shift
;;
--keyring|--keyring=?*)
if ! gpgv --version >/dev/null 2>&1; then
error 1 NEEDGPGV "gpgv not installed, but required for Release verification"
fi
if [ "$1" = "--keyring" -a -n "$2" ]; then
KEYRING="$2"
shift 2
elif [ "$1" != "${1#--keyring=}" ]; then
KEYRING="${1#--keyring=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--no-check-gpg)
shift 1
DISABLE_KEYRING=1
;;
--force-check-gpg)
shift 1
FORCE_KEYRING=1
;;
--certificate|--certificate=?*)
if [ "$1" = "--certificate" -a -n "$2" ]; then
CERTIFICATE="--certificate=$2"
shift 2
elif [ "$1" != "${1#--certificate=}" ]; then
CERTIFICATE="--certificate=${1#--certificate=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--private-key|--private-key=?*)
if [ "$1" = "--private-key" -a -n "$2" ]; then
PRIVATEKEY="--private-key=$2"
shift 2
elif [ "$1" != "${1#--private-key=}" ]; then
PRIVATEKEY="--private-key=${1#--private-key=}"
shift 1
else
error 1 NEEDARG "option requires an argument %s" "$1"
fi
;;
--no-check-certificate)
CHECKCERTIF="--no-check-certificate"
shift
;;
-*)
error 1 BADARG "unrecognized or invalid option %s" "$1"
;;
*)
break
;;
esac
done
fi
###########################################################################
if [ -n "$DISABLE_KEYRING" -a -n "$FORCE_KEYRING" ]; then
error 1 BADARG "Both --no-check-gpg and --force-check-gpg specified, please pick one (at most)"
fi
###########################################################################
if [ "$SECOND_STAGE_ONLY" = "true" ]; then
SUITE=$(cat $DEBOOTSTRAP_DIR/suite)
ARCH=$(cat $DEBOOTSTRAP_DIR/arch)
if [ -e $DEBOOTSTRAP_DIR/variant ]; then
VARIANT=$(cat $DEBOOTSTRAP_DIR/variant)
SUPPORTED_VARIANTS="$VARIANT"
fi
if [ -z "$CHROOTDIR" ]; then
TARGET=/
else
TARGET=$CHROOTDIR
fi
SCRIPT=$DEBOOTSTRAP_DIR/suite-script
else
if [ -z "$1" ] || [ -z "$2" ]; then
usage_err 1 NEEDSUITETARGET "You must specify a suite and a target."
fi
SUITE="$1"
TARGET="$2"
USER_MIRROR="$3"
TARGET="${TARGET%/}"
if [ "${TARGET#/}" = "${TARGET}" ]; then
if [ "${TARGET%/*}" = "$TARGET" ] ; then
TARGET="$(echo "`pwd`/$TARGET")"
else
TARGET="$(cd "${TARGET%/*}"; echo "`pwd`/${TARGET##*/}")"
fi
fi
SCRIPT="$DEBOOTSTRAP_DIR/scripts/$1"
if [ -n "$VARIANT" ] && [ -e "${SCRIPT}.${VARIANT}" ]; then
SCRIPT="${SCRIPT}.${VARIANT}"
SUPPORTED_VARIANTS="$VARIANT"
fi
if [ "$4" != "" ]; then
SCRIPT="$4"
fi
fi
###########################################################################
if in_path dpkg && \
dpkg --print-architecture >/dev/null 2>&1; then
HOST_ARCH=`/usr/bin/dpkg --print-architecture`
elif in_path udpkg && \
udpkg --print-architecture >/dev/null 2>&1; then
HOST_ARCH=`/usr/bin/udpkg --print-architecture`
elif [ -e $DEBOOTSTRAP_DIR/arch ]; then
HOST_ARCH=`cat $DEBOOTSTRAP_DIR/arch`
fi
HOST_OS="$HOST_ARCH"
# basic host OS guessing for non-Debian systems
if [ -z "$HOST_OS" ]; then
case `uname` in
Linux)
HOST_OS=linux
;;
GNU/kFreeBSD)
HOST_OS=kfreebsd
;;
GNU)
HOST_OS=hurd
;;
FreeBSD*)
HOST_OS=freebsd
;;
esac
fi
if [ -z "$ARCH" ]; then
ARCH=$HOST_ARCH
fi
if [ -z "$ARCH" ] || [ -z "$HOST_OS" ]; then
error 1 WHATARCH "Couldn't work out current architecture"
fi
if [ "$HOST_OS" = "kfreebsd" ] || [ "$HOST_OS" = "freebsd" ]; then
for module in linprocfs fdescfs tmpfs linsysfs; do
kldstat -m "$module" > /dev/null 2>&1 || warning SANITYCHECK "Probably required module %s is not loaded" "$module"
done
fi
if [ "$TARGET" = "/" ]; then
CHROOT_CMD=""
else
CHROOT_CMD="chroot $TARGET"
fi
if [ -z "$SHA_SIZE" ]; then
SHA_SIZE=256
fi
if ! in_path "sha${SHA_SIZE}sum" && ! in_path "sha${SHA_SIZE}"; then
SHA_SIZE=1
fi
DEBOOTSTRAP_CHECKSUM_FIELD="SHA$SHA_SIZE"
export ARCH SUITE TARGET CHROOT_CMD SHA_SIZE DEBOOTSTRAP_CHECKSUM_FIELD
if am_doing_phase first_stage second_stage; then
if in_path id && [ `id -u` -ne 0 ]; then
error 1 NEEDROOT "debootstrap can only run as root"
fi
# Ensure that we can create working devices and executables on the target.
if ! check_sane_mount "$TARGET"; then
error 1 NOEXEC "Cannot install into target '$TARGET' mounted with noexec or nodev"
fi
fi
if [ ! -e "$SCRIPT" ]; then
error 1 NOSCRIPT "No such script: %s" "$SCRIPT"
fi
###########################################################################
if [ "$TARGET" != "" ]; then
mkdir -p "$TARGET/debootstrap"
fi
###########################################################################
# Use of fd's by functions/scripts:
#
# stdin/stdout/stderr: used normally
# fd 4: I:/W:/etc information
# fd 5,6: spare for functions
# fd 7,8: spare for scripts
if [ "$USE_DEBIANINSTALLER_INTERACTION" = yes ]; then
# stdout=stderr: full log of debootstrap run
# fd 3: I:/W:/etc information
exec 4>&3
elif am_doing_phase printdebs; then
# stderr: I:/W:/etc information
# stdout: debs needed
exec 4>&2
else
# stderr: used in exceptional circumstances only
# stdout: I:/W:/etc information
# $TARGET/debootstrap/debootstrap.log: full log of debootstrap run
exec 4>&1
exec >>"$TARGET/debootstrap/debootstrap.log"
exec 2>&1
fi
###########################################################################
if [ "$UNPACK_TARBALL" ]; then
if [ "${UNPACK_TARBALL#/}" = "$UNPACK_TARBALL" ]; then
error 1 TARPATH "Tarball must be given a complete path"
fi
if [ "${UNPACK_TARBALL%.tar}" != "$UNPACK_TARBALL" ]; then
(cd "$TARGET" && tar -xf "$UNPACK_TARBALL")
elif [ "${UNPACK_TARBALL%.tgz}" != "$UNPACK_TARBALL" ]; then
(cd "$TARGET" && zcat "$UNPACK_TARBALL" | tar -xf -)
else
error 1 NOTTAR "Unknown tarball: must be either .tar or .tgz"
fi
fi
###########################################################################
. "$SCRIPT"
if [ "$SECOND_STAGE_ONLY" = "true" ]; then
MIRRORS=null:
else
MIRRORS="$DEF_MIRROR"
if [ "$USER_MIRROR" != "" ]; then
MIRRORS="$USER_MIRROR"
MIRRORS="${MIRRORS%/}"
fi
fi
export MIRRORS
ok=false
for v in $SUPPORTED_VARIANTS; do
if doing_variant $v; then ok=true; fi
done
if ! $ok; then
error 1 UNSUPPVARIANT "unsupported variant"
fi
###########################################################################
if am_doing_phase finddebs; then
if [ "$FINDDEBS_NEEDS_INDICES" = "true" ] || \
[ "$RESOLVE_DEPS" = "true" ]; then
download_indices
GOT_INDICES=true
fi
work_out_debs
base=$(without "$base $ADDITIONAL" "$EXCLUDE")
if [ "$RESOLVE_DEPS" = true ]; then
requiredX=$(echo $(echo $required | tr ' ' '\n' | sort | uniq))
baseX=$(echo $(echo $base | tr ' ' '\n' | sort | uniq))