]> CyberLeo.Net >> Repos - CDN/j.git/blob - seeds/debian.sh
j/seeds/debian: support a sane local pool layout, and legacy releases
[CDN/j.git] / seeds / debian.sh
1 # Initialize a debian chroot using debootstrap into the provided directory
2
3 # Parameters that I want on the command line:
4 # <arch> <suite> <repo>
5
6 [ "$(which debootstrap 2>&-)" ] || pebkac "j_init: debian: debootstrap not found"
7
8 : ${arch=${1}}
9 : ${suite=${2}}
10 : ${repo=${3}}
11 : ${include=bash-completion,curl,file,less,locales,sudo,vim,whois}
12
13 [ "${arch}" ] || pebkac "Debian seed needs <arch> <suite> [repo]"
14
15 case "${arch}" in
16 x86|i386) arch=i386 ;;
17 amd64|x86_64|x64) arch=amd64 ;;
18 *) pebkac "Unsupported arch '${arch}'" ;;
19 esac
20
21 [ "${suite}" ] || pebkac "Debian seed needs <arch> <suite> [repo]"
22
23 [ "${repo}" ] || {
24   if [ -f "${jseed}/debian/dists/${suite}/Release" ]
25   then
26     echo "Using local ${suite} pool for installation" >&2
27     repo="file://${jseed}/debian"
28   else
29     case "${suite}" in
30     buzz|rex|bo|hamm|slink|potato|woody|sarge|etch|lenny)
31       repo="http://archive.debian.org/debian" ;;
32     squeeze|wheezy|sid|*)
33       repo="http://ftp.debian.org/debian" ;;
34     esac
35     echo "Using site '${repo}' for installation" >&2
36   fi
37 }
38
39 keyring="${jseed}/debian/debian-archive-keyring.gpg"
40 [ -f "${keyring}" ] || unset keyring
41
42
43 [ ! -d "${jseed}/debian/pool" ] || {
44   echo "Seeding deb archives from local pool" >&2
45   mkdir -p "${jroot}/var/cache/apt/archives"
46   find "${jseed}/debian/pool" -name '*.deb' -exec cp -l {} "${jroot}/var/cache/apt/archives" \;
47 }
48
49 cmd="debootstrap '--arch=${arch}' ${keyring+'--keyring=${jseed}/debian/debian-archive-keyring.gpg'} '--include=${include}' '${suite}' '${jroot}' '${repo}'"
50 echo "Executing: ${cmd}"
51 eval "${cmd}"
52
53 # Make sure locales are generated on first start
54 mkdir -p "${jroot}/etc/rcJ.d"
55 cat > "${jroot}/etc/rcJ.d/S00localegen" <<"EOF"
56 #!/bin/sh
57 /bin/sed -i '/en_US/s/^# //' /etc/locale.gen
58 /usr/sbin/locale-gen
59 /bin/rm -f "${0}"
60 EOF
61 chmod 755 "${jroot}/etc/rcJ.d/S00localegen"
62
63 echo "Adding user"
64 printf '$a\n%%sudo ALL=(ALL) NOPASSWD: ALL' | ed "${jroot}/etc/sudoers"
65 user="${ORIG_USER}"
66 uid="$(id -u "${ORIG_USER}")"
67 [ "${user}" -a "${uid}" ] || { echo "Cannot add nonexistent user"; false; }
68 chroot "${jroot}" /usr/sbin/useradd -m -o -u "${uid}" -G root,sudo "${user}"
69 echo "Propagating password hash"
70 [ -f /etc/shadow ] && {
71   hash="$(grep "^${user}:" /etc/shadow | cut -d: -f2)"
72   [ "${hash}" ] && sed -i "s?^${user}:[^:]*:?${user}:${hash}:?" "${jroot}/etc/shadow"
73 }