# Initialize a debian chroot using debootstrap into the provided directory # Parameters that I want on the command line: # [ "$(which debootstrap 2>&-)" ] || pebkac "j_init: debian: debootstrap not found" : ${arch=${1}} : ${suite=${2}} : ${repo=${3}} : ${include=bash-completion,curl,ed,file,less,locales,sudo,vim,whois} [ "${arch}" ] || pebkac "Debian seed needs [repo]" case "${arch}" in x86|i386) arch=i386 ;; amd64|x86_64|x64) arch=amd64 ;; *) pebkac "Unsupported arch '${arch}'" ;; esac [ "${suite}" ] || pebkac "Debian seed needs [repo]" [ "${repo}" ] || { if [ -f "${jseed}/debian/dists/${suite}/Release" ] then echo "Using local ${suite} pool for installation" >&2 repo="file://${jseed}/debian" else case "${suite}" in buzz|rex|bo|hamm|slink|potato|woody|sarge|etch|lenny) repo="http://archive.debian.org/debian" ;; squeeze|wheezy|sid|*) repo="http://ftp.debian.org/debian" ;; esac echo "Using site '${repo}' for installation" >&2 fi } keyring="${jseed}/debian/debian-archive-keyring.gpg" [ -f "${keyring}" ] || unset keyring [ ! -d "${jseed}/debian/pool" ] || { echo "Seeding deb archives from local pool" >&2 mkdir -p "${jroot}/var/cache/apt/archives" find "${jseed}/debian/pool" -name '*.deb' -exec cp -l {} "${jroot}/var/cache/apt/archives" \; } cmd="debootstrap '--arch=${arch}' ${keyring+'--keyring=${jseed}/debian/debian-archive-keyring.gpg'} '--include=${include}' '${suite}' '${jroot}' '${repo}'" echo "Executing: ${cmd}" eval "${cmd}" # Make sure locales are generated on first start mkdir -p "${jroot}/etc/rcJ.d" cat > "${jroot}/etc/rcJ.d/S00localegen" <<"EOF" #!/bin/sh /bin/sed -i '/en_US/s/^# //' /etc/locale.gen /usr/sbin/locale-gen /bin/rm -f "${0}" EOF chmod 755 "${jroot}/etc/rcJ.d/S00localegen" echo "Adding user" ed "${jroot}/etc/sudoers" <<"EOF" H $a %sudo ALL=(ALL) NOPASSWD: ALL . w EOF user="${ORIG_USER}" uid="$(id -u "${ORIG_USER}")" [ "${user}" -a "${uid}" ] || { echo "Cannot add nonexistent user"; false; } chroot "${jroot}" /usr/sbin/useradd -m -o -u "${uid}" -G root,sudo "${user}" echo "Propagating password hash" [ -f /etc/shadow ] && { hash="$(grep "^${user}:" /etc/shadow | cut -d: -f2)" [ "${hash}" ] && sed -i "s?^${user}:[^:]*:?${user}:${hash}:?" "${jroot}/etc/shadow" }