github.com/reds/docker@v1.11.2-rc1/contrib/mkimage-arch.sh (about)

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