1 # Initialize a debian chroot using debootstrap into the provided directory
3 # Parameters that I want on the command line:
4 # <arch> <suite> <repo>
6 [ "$(which debootstrap 2>&-)" ] || pebkac "j_init: debian: debootstrap not found"
11 : ${include=curl,file,less,locales,sudo,vim,whois}
13 [ "${arch}" ] || pebkac "Debian seed needs <arch> <suite> [repo]"
16 x86|i386) arch=i386 ;;
17 amd64|x86_64|x64) arch=amd64 ;;
18 *) pebkac "Unsupported arch '${arch}'" ;;
21 [ "${suite}" ] || pebkac "Debian seed needs <arch> <suite> [repo]"
24 if [ -f "${jseed}/debian/dists/${suite}/Release" ]
26 repo="file://${jseed}/debian"
28 repo="http://archive.debian.org/debian"
32 keyring="${jseed}/debian/debian-archive-keyring.gpg"
33 [ -f "${keyring}" ] || unset keyring
35 mkdir -p "${jroot}/var/cache/apt/archives"
37 [ ! -d "${jseed}/debian/debs" ] || {
38 echo "Seeding deb archives" >&2
39 ( cd "${jseed}/debian/debs"; find . | cpio -pl "${jroot}/var/cache/apt/archives" )
42 cmd="debootstrap '--arch=${arch}' ${keyring+'--keyring=${jseed}/debian/debian-archive-keyring.gpg'} '--include=${include}' '${suite}' '${jroot}' '${repo}'"
43 echo "Executing: ${cmd}"
46 # Make sure locales are generated on first start
47 mkdir -p "${jroot}/etc/rcJ.d"
48 cat > "${jroot}/etc/rcJ.d/S00localegen" <<"EOF"
50 /bin/sed -i '/en_US/s/^# //' /etc/locale.gen
54 chmod 755 "${jroot}/etc/rcJ.d/S00localegen"
57 sed -i '/%sudo/s/^# *//' "${jroot}/etc/sudoers"
59 uid="$(id -u "${ORIG_USER}")"
60 [ "${user}" -a "${uid}" ] || { echo "Cannot add nonexistent user"; false; }
61 chroot "${jroot}" /usr/sbin/useradd -m -o -u "${uid}" -G root,sudo "${user}"
62 echo "Propagating password hash"
63 [ -f /etc/shadow ] && {
64 hash="$(grep "^${user}:" /etc/shadow | cut -d: -f2)"
65 [ "${hash}" ] && sed -i "s?^${user}:[^:]*:?${user}:${hash}:?" ${jroot}/etc/shadow