docker images for Archlinux32

mkimage-arch.sh 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env bash
  2. # Generate a minimal filesystem for archlinux and load it into the local
  3. # docker as "archlinux"
  4. # requires root
  5. set -e
  6. hash pacstrap &>/dev/null || {
  7. echo "Could not find pacstrap. Run pacman -S arch-install-scripts"
  8. exit 1
  9. }
  10. hash expect &>/dev/null || {
  11. echo "Could not find expect. Run pacman -S expect"
  12. exit 1
  13. }
  14. export LANG="C.UTF-8"
  15. MOUNTPOINT=$(mktemp -d ${TMPDIR:-/var/tmp}/mountpoint-archlinux-XXXXXXXXXX)
  16. ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX)
  17. chmod 755 $ROOTFS
  18. # packages to ignore for space savings
  19. PKGIGNORE=(
  20. dhcpcd
  21. iproute2
  22. jfsutils
  23. linux
  24. lvm2
  25. man-db
  26. man-pages
  27. mdadm
  28. nano
  29. netctl
  30. openresolv
  31. pciutils
  32. pcmciautils
  33. reiserfsprogs
  34. s-nail
  35. systemd-sysvcompat
  36. usbutils
  37. vi
  38. xfsprogs
  39. )
  40. IFS=','
  41. PKGIGNORE="${PKGIGNORE[*]}"
  42. unset IFS
  43. arch="$(uname -m)"
  44. case "$arch" in
  45. armv*)
  46. if pacman -Q archlinuxarm-keyring >/dev/null 2>&1; then
  47. pacman-key --init
  48. pacman-key --populate archlinuxarm
  49. else
  50. echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm"
  51. exit 1
  52. fi
  53. PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX)
  54. version="$(echo $arch | cut -c 5)"
  55. sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}"
  56. PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo'
  57. PACMAN_EXTRA_PKGS='archlinuxarm-keyring'
  58. EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1)
  59. ARCH_KEYRING=archlinuxarm
  60. DOCKER_IMAGE_NAME="armv${version}h/archlinux"
  61. ;;
  62. *)
  63. if pacman -Q archlinux32-keyring >/dev/null 2>&1; then
  64. pacman-key --init
  65. pacman-key --populate archlinux32
  66. else
  67. echo "Could not find archlinux32-keyring. Please, install it and run pacman-key --populate archlinux32"
  68. exit 1
  69. fi
  70. PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX)
  71. sed "s/Architecture.*/Architecture = i686/" './mkimage-arch-pacman.conf' > "${PACMAN_CONF}"
  72. echo 'Server = http://archlinux32.andreasbaumann.cc/$arch/$repo' > mirrorlist32
  73. sed -i "s|/etc/pacman.d/mirrorlist|mirrorlist32|g" "${PACMAN_CONF}"
  74. PACMAN_MIRRORLIST='Server = http://archlinux32.andreasbaumann.cc/$arch/$repo'
  75. PACMAN_EXTRA_PKGS='archlinux32-keyring'
  76. EXPECT_TIMEOUT=1800
  77. ARCH_KEYRING=archlinux32
  78. DOCKER_IMAGE_NAME=archlinux32
  79. ;;
  80. esac
  81. export PACMAN_MIRRORLIST
  82. expect <<EOF
  83. set send_slow {1 .1}
  84. proc send {ignore arg} {
  85. sleep .1
  86. exp_send -s -- \$arg
  87. }
  88. set timeout $EXPECT_TIMEOUT
  89. spawn pacstrap -C $PACMAN_CONF -c -d -G -i $ROOTFS base haveged $PACMAN_EXTRA_PKGS --ignore $PKGIGNORE
  90. expect {
  91. -exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue }
  92. -exact "(default=all): " { send -- "\r"; exp_continue }
  93. -exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue }
  94. -exact "delete it? \[Y/n\]" { send -- "y\r"; exp_continue }
  95. }
  96. EOF
  97. mount --bind $ROOTFS $MOUNTPOINT
  98. arch-chroot $MOUNTPOINT /bin/sh -c 'rm -r /usr/share/man/*'
  99. #arch-chroot $MOUNTPOINT /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman -Rs --noconfirm haveged; pacman-key --populate $ARCH_KEYRING; pkill gpg-agent"
  100. arch-chroot $MOUNTPOINT /bin/sh -c "pacman-key --init; pacman-key --populate $ARCH_KEYRING"
  101. arch-chroot $MOUNTPOINT /bin/sh -c "ln -fs /usr/share/zoneinfo/UTC /etc/localtime"
  102. echo 'en_US.UTF-8 UTF-8' > $MOUNTPOINT/etc/locale.gen
  103. arch-chroot $MOUNTPOINT locale-gen
  104. sed -i "s/Architecture.*/Architecture = i686/" "$MOUNTPOINT/etc/pacman.conf"
  105. arch-chroot $MOUNTPOINT /bin/sh -c 'echo $PACMAN_MIRRORLIST > /etc/pacman.d/mirrorlist'
  106. # udev doesn't work in containers, rebuild /dev
  107. DEV=$MOUNTPOINT/dev
  108. rm -rf $DEV
  109. mkdir -p $DEV
  110. mknod -m 666 $DEV/null c 1 3
  111. mknod -m 666 $DEV/zero c 1 5
  112. mknod -m 666 $DEV/random c 1 8
  113. mknod -m 666 $DEV/urandom c 1 9
  114. mkdir -m 755 $DEV/pts
  115. mkdir -m 1777 $DEV/shm
  116. mknod -m 666 $DEV/tty c 5 0
  117. mknod -m 600 $DEV/console c 5 1
  118. mknod -m 666 $DEV/tty0 c 4 0
  119. mknod -m 666 $DEV/full c 1 7
  120. mknod -m 600 $DEV/initctl p
  121. mknod -m 666 $DEV/ptmx c 5 2
  122. ln -sf /proc/self/fd $DEV/fd
  123. umount $MOUNTPOINT
  124. tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME
  125. docker run --rm -t $DOCKER_IMAGE_NAME echo Success.
  126. rmdir $MOUNTPOINT
  127. rm -rf $ROOTFS