2014-01-22 01:21:56 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-10-15 23:09:02 +00:00
|
|
|
# Generate a minimal filesystem for archlinux and load it into the local
|
|
|
|
# docker as "archlinux"
|
|
|
|
# requires root
|
|
|
|
set -e
|
|
|
|
|
2019-05-01 10:17:04 +00:00
|
|
|
# reset umask to default
|
|
|
|
umask 022
|
|
|
|
|
2020-03-03 03:27:49 +00:00
|
|
|
hash pacstrap &> /dev/null || {
|
2014-07-09 15:38:13 +00:00
|
|
|
echo "Could not find pacstrap. Run pacman -S arch-install-scripts"
|
|
|
|
exit 1
|
2013-10-15 23:09:02 +00:00
|
|
|
}
|
2014-01-06 12:08:55 +00:00
|
|
|
|
2020-03-03 03:27:49 +00:00
|
|
|
hash expect &> /dev/null || {
|
2014-07-09 15:38:13 +00:00
|
|
|
echo "Could not find expect. Run pacman -S expect"
|
|
|
|
exit 1
|
2014-07-09 15:08:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-28 04:33:24 +00:00
|
|
|
export LANG="C.UTF-8"
|
|
|
|
|
2014-06-27 12:43:12 +00:00
|
|
|
ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/rootfs-archlinux-XXXXXXXXXX)
|
2014-02-02 13:50:54 +00:00
|
|
|
chmod 755 $ROOTFS
|
2013-10-15 23:09:02 +00:00
|
|
|
|
2019-05-01 10:17:04 +00:00
|
|
|
# required packages
|
|
|
|
PKGREQUIRED=(
|
2019-07-17 17:48:13 +00:00
|
|
|
bash
|
|
|
|
haveged
|
|
|
|
pacman
|
|
|
|
pacman-mirrorlist
|
2019-05-01 10:17:04 +00:00
|
|
|
)
|
|
|
|
|
2014-01-06 12:11:16 +00:00
|
|
|
# packages to ignore for space savings
|
2014-12-21 00:16:19 +00:00
|
|
|
PKGIGNORE=(
|
2019-07-17 17:48:13 +00:00
|
|
|
dhcpcd
|
|
|
|
diffutils
|
|
|
|
file
|
|
|
|
inetutils
|
|
|
|
iproute2
|
|
|
|
iputils
|
|
|
|
jfsutils
|
|
|
|
licenses
|
|
|
|
linux
|
|
|
|
linux-firmware
|
|
|
|
lvm2
|
|
|
|
man-db
|
|
|
|
man-pages
|
|
|
|
mdadm
|
|
|
|
nano
|
|
|
|
netctl
|
|
|
|
openresolv
|
|
|
|
pciutils
|
|
|
|
pcmciautils
|
|
|
|
psmisc
|
|
|
|
reiserfsprogs
|
|
|
|
s-nail
|
|
|
|
sysfsutils
|
|
|
|
systemd-sysvcompat
|
|
|
|
usbutils
|
|
|
|
vi
|
|
|
|
which
|
|
|
|
xfsprogs
|
2014-12-21 00:16:19 +00:00
|
|
|
)
|
2019-05-01 10:17:04 +00:00
|
|
|
|
|
|
|
PKGREMOVE=(
|
2019-07-17 17:48:13 +00:00
|
|
|
gawk
|
2020-03-03 03:27:49 +00:00
|
|
|
haveged
|
2019-07-17 17:48:13 +00:00
|
|
|
less
|
|
|
|
linux-libre
|
|
|
|
linux-libre-firmware
|
2019-05-01 10:17:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
PKGREQUIRED="${PKGREQUIRED[*]}"
|
2014-12-21 00:16:19 +00:00
|
|
|
IFS=','
|
|
|
|
PKGIGNORE="${PKGIGNORE[*]}"
|
|
|
|
unset IFS
|
2019-05-01 10:17:04 +00:00
|
|
|
PKGREMOVE="${PKGREMOVE[*]}"
|
2014-01-06 12:13:19 +00:00
|
|
|
|
2016-07-03 20:14:24 +00:00
|
|
|
arch="$(uname -m)"
|
|
|
|
case "$arch" in
|
2015-09-29 12:06:19 +00:00
|
|
|
armv*)
|
2020-03-03 03:27:49 +00:00
|
|
|
if pacman -Q archlinuxarm-keyring > /dev/null 2>&1; then
|
2015-09-29 12:06:19 +00:00
|
|
|
pacman-key --init
|
|
|
|
pacman-key --populate archlinuxarm
|
|
|
|
else
|
|
|
|
echo "Could not find archlinuxarm-keyring. Please, install it and run pacman-key --populate archlinuxarm"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-07-03 20:14:24 +00:00
|
|
|
PACMAN_CONF=$(mktemp ${TMPDIR:-/var/tmp}/pacman-conf-archlinux-XXXXXXXXX)
|
|
|
|
version="$(echo $arch | cut -c 5)"
|
|
|
|
sed "s/Architecture = armv/Architecture = armv${version}h/g" './mkimage-archarm-pacman.conf' > "${PACMAN_CONF}"
|
2015-09-29 12:06:19 +00:00
|
|
|
PACMAN_MIRRORLIST='Server = http://mirror.archlinuxarm.org/$arch/$repo'
|
|
|
|
PACMAN_EXTRA_PKGS='archlinuxarm-keyring'
|
2016-07-11 01:39:52 +00:00
|
|
|
EXPECT_TIMEOUT=1800 # Most armv* based devices can be very slow (e.g. RPiv1)
|
2015-09-29 12:06:19 +00:00
|
|
|
ARCH_KEYRING=archlinuxarm
|
2016-07-03 20:14:24 +00:00
|
|
|
DOCKER_IMAGE_NAME="armv${version}h/archlinux"
|
2015-09-29 12:06:19 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
PACMAN_CONF='./mkimage-arch-pacman.conf'
|
|
|
|
PACMAN_MIRRORLIST='Server = https://mirrors.kernel.org/archlinux/$repo/os/$arch'
|
|
|
|
PACMAN_EXTRA_PKGS=''
|
|
|
|
EXPECT_TIMEOUT=60
|
|
|
|
ARCH_KEYRING=archlinux
|
|
|
|
DOCKER_IMAGE_NAME=archlinux
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
export PACMAN_MIRRORLIST
|
|
|
|
|
2020-03-03 03:27:49 +00:00
|
|
|
expect << EOF
|
2014-07-09 15:38:13 +00:00
|
|
|
set send_slow {1 .1}
|
|
|
|
proc send {ignore arg} {
|
|
|
|
sleep .1
|
|
|
|
exp_send -s -- \$arg
|
|
|
|
}
|
2015-09-29 12:06:19 +00:00
|
|
|
set timeout $EXPECT_TIMEOUT
|
2014-07-09 15:38:13 +00:00
|
|
|
|
2019-07-17 17:48:13 +00:00
|
|
|
spawn pacstrap -C $PACMAN_CONF -c -d -G -i $ROOTFS base $PKGREQUIRED $PACMAN_EXTRA_PKGS --ignore $PKGIGNORE
|
2014-07-09 15:38:13 +00:00
|
|
|
expect {
|
|
|
|
-exact "anyway? \[Y/n\] " { send -- "n\r"; exp_continue }
|
|
|
|
-exact "(default=all): " { send -- "\r"; exp_continue }
|
|
|
|
-exact "installation? \[Y/n\]" { send -- "y\r"; exp_continue }
|
2016-07-03 20:14:24 +00:00
|
|
|
-exact "delete it? \[Y/n\]" { send -- "y\r"; exp_continue }
|
2014-07-09 15:38:13 +00:00
|
|
|
}
|
2014-07-09 15:08:17 +00:00
|
|
|
EOF
|
2013-10-15 23:09:02 +00:00
|
|
|
|
2014-12-21 00:25:15 +00:00
|
|
|
arch-chroot $ROOTFS /bin/sh -c 'rm -r /usr/share/man/*'
|
2019-05-01 10:17:04 +00:00
|
|
|
arch-chroot $ROOTFS /bin/sh -c "haveged -w 1024; pacman-key --init; pkill haveged; pacman-key --populate $ARCH_KEYRING"
|
|
|
|
arch-chroot $ROOTFS /bin/sh -c "ln -sf /usr/share/zoneinfo/UTC /etc/localtime"
|
|
|
|
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"
|
2014-01-06 12:13:19 +00:00
|
|
|
echo 'en_US.UTF-8 UTF-8' > $ROOTFS/etc/locale.gen
|
2013-10-15 23:09:02 +00:00
|
|
|
arch-chroot $ROOTFS locale-gen
|
|
|
|
|
|
|
|
# udev doesn't work in containers, rebuild /dev
|
2014-01-06 12:11:16 +00:00
|
|
|
DEV=$ROOTFS/dev
|
|
|
|
rm -rf $DEV
|
|
|
|
mkdir -p $DEV
|
|
|
|
mknod -m 666 $DEV/null c 1 3
|
|
|
|
mknod -m 666 $DEV/zero c 1 5
|
|
|
|
mknod -m 666 $DEV/random c 1 8
|
|
|
|
mknod -m 666 $DEV/urandom c 1 9
|
|
|
|
mkdir -m 755 $DEV/pts
|
|
|
|
mkdir -m 1777 $DEV/shm
|
|
|
|
mknod -m 666 $DEV/tty c 5 0
|
|
|
|
mknod -m 600 $DEV/console c 5 1
|
|
|
|
mknod -m 666 $DEV/tty0 c 4 0
|
|
|
|
mknod -m 666 $DEV/full c 1 7
|
|
|
|
mknod -m 600 $DEV/initctl p
|
|
|
|
mknod -m 666 $DEV/ptmx c 5 2
|
2014-04-19 07:57:17 +00:00
|
|
|
ln -sf /proc/self/fd $DEV/fd
|
2013-10-15 23:09:02 +00:00
|
|
|
|
2015-09-29 12:06:19 +00:00
|
|
|
tar --numeric-owner --xattrs --acls -C $ROOTFS -c . | docker import - $DOCKER_IMAGE_NAME
|
|
|
|
docker run --rm -t $DOCKER_IMAGE_NAME echo Success.
|
2013-10-15 23:09:02 +00:00
|
|
|
rm -rf $ROOTFS
|