github.com/moby/docker@v26.1.3+incompatible/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  # reset umask to default
     8  umask 022
     9  
    10  hash pacstrap &> /dev/null || {
    11  	echo "Could not find pacstrap. Run pacman -S arch-install-scripts"
    12  	exit 1
    13  }
    14  
    15  hash expect &> /dev/null || {
    16  	echo "Could not find expect. Run pacman -S expect"
    17  	exit 1
    18  }
    19  
    20  export LANG="C.UTF-8"
    21  
    22  ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX)
    23  chmod 755 $ROOTFS
    24  
    25  # required packages
    26  PKGREQUIRED=(
    27  	bash
    28  	haveged
    29  	pacman
    30  	pacman-mirrorlist
    31  )
    32  
    33  # packages to ignore for space savings
    34  PKGIGNORE=(
    35  	dhcpcd
    36  	diffutils
    37  	file
    38  	inetutils
    39  	iproute2
    40  	iputils
    41  	jfsutils
    42  	licenses
    43  	linux
    44  	linux-firmware
    45  	lvm2
    46  	man-db
    47  	man-pages
    48  	mdadm
    49  	nano
    50  	netctl
    51  	openresolv
    52  	pciutils
    53  	pcmciautils
    54  	psmisc
    55  	reiserfsprogs
    56  	s-nail
    57  	sysfsutils
    58  	systemd-sysvcompat
    59  	usbutils
    60  	vi
    61  	which
    62  	xfsprogs
    63  )
    64  
    65  PKGREMOVE=(
    66  	gawk
    67  	haveged
    68  	less
    69  	linux-libre
    70  	linux-libre-firmware
    71  )
    72  
    73  PKGREQUIRED="${PKGREQUIRED[*]}"
    74  IFS=','
    75  PKGIGNORE="${PKGIGNORE[*]}"
    76  unset IFS
    77  PKGREMOVE="${PKGREMOVE[*]}"
    78  
    79  arch="$(uname -m)"
    80  case "$arch" in
    81  	armv*)
    82  		if pacman -Q archlinuxarm-keyring > /dev/null 2>&1; then
    83  			pacman-key --init
    84  			pacman-key --populate archlinuxarm
    85  		else
    86  			echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm"
    87  			exit 1
    88  		fi
    89  		PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX)
    90  		version="$(echo $arch | cut -c 5)"
    91  		sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}"
    92  		PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo'
    93  		PACMAN_EXTRA_PKGS='archlinuxarm-keyring'
    94  		EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1)
    95  		ARCH_KEYRING=archlinuxarm
    96  		DOCKER_IMAGE_NAME="armv${version}h/archlinux"
    97  		;;
    98  	*)
    99  		PACMAN_CONF='./mkimage-arch-pacman.conf'
   100  		PACMAN_MIRRORLIST='Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch'
   101  		PACMAN_EXTRA_PKGS=''
   102  		EXPECT_TIMEOUT=60
   103  		ARCH_KEYRING=archlinux
   104  		DOCKER_IMAGE_NAME=archlinux
   105  		;;
   106  esac
   107  
   108  export PACMAN_MIRRORLIST
   109  
   110  expect << EOF
   111  	set send_slow {1 .1}
   112  	proc send {ignore arg} {
   113  		sleep .1
   114  		exp_send -s -- \$arg
   115  	}
   116  	set timeout $EXPECT_TIMEOUT
   117  
   118  	spawn pacstrap -C $PACMAN_CONF -c -d -G -i $ROOTFS base $PKGREQUIRED $PACMAN_EXTRA_PKGS --ignore $PKGIGNORE
   119  	expect {
   120  		-exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue }
   121  		-exact "(default=all): " { send -- "\r"; exp_continue }
   122  		-exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue }
   123  		-exact "delete it? \[Y/n\]" { send -- "y\r"; exp_continue }
   124  	}
   125  EOF
   126  
   127  arch-chroot $ROOTFS /bin/sh -c 'rm -r /usr/share/man/*'
   128  arch-chroot $ROOTFS /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman-key --populate $ARCH_KEYRING"
   129  arch-chroot $ROOTFS /bin/sh -c "ln -sf /usr/share/zoneinfo/UTC /etc/localtime"
   130  arch-chroot $ROOTFS /bin/sh -c "for pkg in $PKGREMOVE; do if pacman -Qi \$pkg > /dev/null 2>&1; then pacman -Rs --noconfirm \$pkg; fi; done"
   131  echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen
   132  arch-chroot $ROOTFS locale-gen
   133  
   134  # udev doesn't work in containers, rebuild /dev
   135  DEV=$ROOTFS/dev
   136  rm -rf $DEV
   137  mkdir -p $DEV
   138  mknod -m 666 $DEV/null c 1 3
   139  mknod -m 666 $DEV/zero c 1 5
   140  mknod -m 666 $DEV/random c 1 8
   141  mknod -m 666 $DEV/urandom c 1 9
   142  mkdir -m 755 $DEV/pts
   143  mkdir -m 1777 $DEV/shm
   144  mknod -m 666 $DEV/tty c 5 0
   145  mknod -m 600 $DEV/console c 5 1
   146  mknod -m 666 $DEV/tty0 c 4 0
   147  mknod -m 666 $DEV/full c 1 7
   148  mknod -m 600 $DEV/initctl p
   149  mknod -m 666 $DEV/ptmx c 5 2
   150  ln -sf /proc/self/fd $DEV/fd
   151  
   152  tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME
   153  docker run --rm -t $DOCKER_IMAGE_NAME echo Success.
   154  rm -rf $ROOTFS