-
Notifications
You must be signed in to change notification settings - Fork 0
/
clone-gentoo-base-container.sh
30 lines (23 loc) · 1.25 KB
/
clone-gentoo-base-container.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
set -eux
CONTAINER_NAME=$1
BASE_CONTAINER_NAME=gentoo-base-container
mountpoint -q /mnt/full-root/ || mount /mnt/full-root/
btrfs sub snap /mnt/full-root/vols/${BASE_CONTAINER_NAME} /mnt/full-root/vols/${CONTAINER_NAME}
rmdir /mnt/full-root/vols/${CONTAINER_NAME}/rootfs
btrfs sub snap /mnt/full-root/vols/${BASE_CONTAINER_NAME}/rootfs /mnt/full-root/vols/${CONTAINER_NAME}/rootfs
mkdir -p /var/lib/lxc/${CONTAINER_NAME}
mount -o subvol=vols/${CONTAINER_NAME} /dev/mmcblk1p3 /var/lib/lxc/${CONTAINER_NAME}
mount -o subvol=vols/${CONTAINER_NAME}/rootfs /dev/mmcblk1p3 /var/lib/lxc/${CONTAINER_NAME}/rootfs
# copy configs from template
[[ -d template/${CONTAINER_NAME} ]] && cp -a template/${CONTAINER_NAME}/* /var/lib/lxc/${CONTAINER_NAME}
# uninstall ssh
chroot "/var/lib/lxc/${CONTAINER_NAME}/rootfs" rc-update del sshd
# install world
lxc-start -n ${CONTAINER_NAME}
lxc-attach -n ${CONTAINER_NAME} -- eselect news read
lxc-attach -n ${CONTAINER_NAME} -- emerge -uDN world --with-bdeps=y --binpkg-respect-use=y
lxc-attach -n ${CONTAINER_NAME} -- etc-update -p # do trivial merges
#lxc-attach -n ${CONTAINER_NAME} -- etc-update --automode -9 # ignore the rest
lxc-attach -n ${CONTAINER_NAME} -- bash /container-specific-setup.sh
lxc-stop -n ${CONTAINER_NAME}