]> CyberLeo.Net >> Repos - CDN/j.git/blob - seeds/debian.sh
j/seeds: use local repo cache if it exists; otherwise use archive
[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=curl,file,less,locales,sudo,vim,whois}
12
13 case "${arch}" in
14 x86|i386) arch=i386 ;;
15 amd64|x86_64|x64) arch=amd64 ;;
16 *) pebkac "Unsupported arch '${arch}'" ;;
17 esac
18
19 [ "${suite}" ] || pebkac "Debian seed needs <arch> <suite> [repo]"
20
21 [ "${repo}" ] || {
22   if [ -f "${jseed}/debian/dists/${suite}/Release" ]
23   then
24     repo="file://${jseed}/debian"
25   else
26     repo="http://archive.debian.org/debian"
27   fi
28 }
29
30 keyring="${jseed}/debian/debian-archive-keyring.gpg"
31 [ -f "${keyring}" ] || unset keyring
32
33 mkdir -p "${jroot}/var/cache/apt/archives"
34
35 [ ! -d "${jseed}/debian/debs" ] || {
36   echo "Seeding deb archives" >&2
37   ( cd "${jseed}/debian/debs"; find . | cpio -pl "${jroot}/var/cache/apt/archives" )
38 }
39
40 cmd="debootstrap '--arch=${arch}' ${keyring+'--keyring=${jseed}/debian/debian-archive-keyring.gpg'} '--include=${include}' '${suite}' '${jroot}' '${repo}'"
41 echo "Executing: ${cmd}"
42 eval "${cmd}"
43
44 # Make sure locales are generated on first start
45 mkdir -p "${jroot}/etc/rcJ.d"
46 cat > "${jroot}/etc/rcJ.d/S00localegen" <<"EOF"
47 #!/bin/sh
48 /bin/sed -i '/en_US/s/^# //' /etc/locale.gen
49 /usr/sbin/locale-gen
50 /bin/rm -f "${0}"
51 EOF
52 chmod 755 "${jroot}/etc/rcJ.d/S00localegen"
53
54 echo "Adding user"
55 sed -i '/%sudo/s/^# *//' "${jroot}/etc/sudoers"
56 user="${ORIG_USER}"
57 uid="$(id -u "${ORIG_USER}")"
58 [ "${user}" -a "${uid}" ] || { echo "Cannot add nonexistent user"; false; }
59 chroot "${jroot}" /usr/sbin/useradd -m -o -u "${uid}" -G root,sudo "${user}"