|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e |
| 3 | + |
| 4 | +function test-command() { |
| 5 | + command -v $1 >/dev/null 2>&1 || { echo >&2 "The command \"$1\" is required. Try \"apt-get install $2\"."; exit 1; } |
| 6 | +} |
| 7 | + |
| 8 | +test-command debootstrap debootstrap |
| 9 | +test-command arch-chroot arch-install-scripts |
| 10 | +test-command genfstab arch-install-scripts |
| 11 | +test-command parted parted |
| 12 | + |
| 13 | +# Download the debs to be used to install debian |
| 14 | +if [ ! -e "debs.tar.gz" ]; then |
| 15 | + debootstrap --verbose \ |
| 16 | + --make-tarball=debs.tar.gz \ |
| 17 | + --include=linux-image-amd64,grub2 \ |
| 18 | + stable rootfs https://deb.debian.org/debian |
| 19 | +fi |
| 20 | + |
| 21 | +# Create our hard disk |
| 22 | +rm -rf boot.img |
| 23 | +truncate -s 20G boot.img |
| 24 | +parted -s boot.img \ |
| 25 | + mklabel msdos \ |
| 26 | + mkpart primary 0% 2GiB \ |
| 27 | + mkpart primary 2GiB 2.5GiB \ |
| 28 | + mkpart primary 2.5GiB 3GiB \ |
| 29 | + mkpart primary 3GiB 100% |
| 30 | + |
| 31 | +# Partition layout: |
| 32 | +# 1. The base recovery os |
| 33 | +# 2. Darch configuration (/etc/darch) |
| 34 | +# 3. Home directory |
| 35 | +# 3. Darch stage/images |
| 36 | + |
| 37 | +# Mount the newly created drive |
| 38 | +loop_device=`losetup --partscan --show --find boot.img` |
| 39 | + |
| 40 | +# Format the partitions |
| 41 | +mkfs.ext4 ${loop_device}p1 |
| 42 | +mkfs.ext4 ${loop_device}p2 |
| 43 | +mkfs.ext4 ${loop_device}p3 |
| 44 | +mkfs.ext4 ${loop_device}p4 |
| 45 | + |
| 46 | +# Mount the new partitions |
| 47 | +rm -rf rootfs && mkdir rootfs |
| 48 | +mount ${loop_device}p1 rootfs |
| 49 | +mkdir -p rootfs/etc/darch |
| 50 | +mount ${loop_device}p2 rootfs/etc/darch |
| 51 | +mkdir rootfs/home |
| 52 | +mount ${loop_device}p3 rootfs/home |
| 53 | +mkdir -p rootfs/var/lib/darch |
| 54 | +mount ${loop_device}p4 rootfs/var/lib/darch |
| 55 | + |
| 56 | +# Generate the rootfs |
| 57 | +debootstrap --verbose \ |
| 58 | + --unpack-tarball=$(pwd)/debs.tar.gz \ |
| 59 | + --include=linux-image-amd64,grub2 \ |
| 60 | + stable rootfs https://deb.debian.org/debian |
| 61 | + |
| 62 | +# Generate fstab (removing comments and whitespace) |
| 63 | +genfstab -U -p rootfs | sed -e 's/#.*$//' -e '/^$/d' > rootfs/etc/fstab |
| 64 | + |
| 65 | +# Set the computer name |
| 66 | +echo "darch-demo" > rootfs/etc/hostname |
| 67 | + |
| 68 | +# Update all the packages |
| 69 | +arch-chroot rootfs apt-get update |
| 70 | + |
| 71 | +# Install network manager for networking and SSH |
| 72 | +arch-chroot rootfs apt-get -y install network-manager openssh-server |
| 73 | + |
| 74 | +# Install GRUB |
| 75 | +arch-chroot rootfs grub-install ${loop_device} |
| 76 | +arch-chroot rootfs grub-mkconfig -o /boot/grub/grub.cfg |
| 77 | + |
| 78 | +# Create the default users |
| 79 | +arch-chroot rootfs apt-get -y install sudo |
| 80 | +arch-chroot rootfs /usr/bin/bash -c 'echo -en "root\nroot" | passwd' |
| 81 | +arch-chroot rootfs useradd -m -G users,sudo -s /usr/bin/bash darch |
| 82 | +arch-chroot rootfs /usr/bin/bash -c 'echo -en "darch\ndarch" | passwd darch' |
| 83 | + |
| 84 | +# Install Darch |
| 85 | +arch-chroot rootfs apt-get -y install curl gnupg software-properties-common |
| 86 | +arch-chroot rootfs /bin/bash -c "curl -L https://raw.githubusercontent.com/godarch/debian-repo/master/key.pub | apt-key add -" |
| 87 | +arch-chroot rootfs add-apt-repository 'deb https://raw.githubusercontent.com/godarch/debian-repo/master/darch testing main' |
| 88 | +arch-chroot rootfs apt-get update |
| 89 | +arch-chroot rootfs apt-get -y install darch |
| 90 | +arch-chroot rootfs mkdir -p /etc/containerd |
| 91 | +echo "root = \"/var/lib/darch/containerd\"" > rootfs/etc/containerd/config.toml |
| 92 | +arch-chroot rootfs systemctl enable containerd |
| 93 | + |
| 94 | +# Setup the fstab hooks for Darch |
| 95 | +cat rootfs/etc/fstab | tail -n +2 > rootfs/etc/darch/hooks/default_fstab |
| 96 | +echo "*=default_fstab" > rootfs/etc/darch/hooks/fstab.config |
| 97 | + |
| 98 | +# Run grub-mkconfig again to ensure it loads the Darch grub config file |
| 99 | +arch-chroot rootfs grub-mkconfig -o /boot/grub/grub.cfg |
| 100 | + |
| 101 | +# Clone our examples repo |
| 102 | +arch-chroot rootfs apt-get -y install git |
| 103 | +arch-chroot rootfs git clone https://github.com/godarch/example-recipes.git /home/darch/example-recipes |
| 104 | +arch-chroot rootfs mkdir /home/darch/Desktop |
| 105 | +arch-chroot rootfs ln -s /home/darch/example-recipes /home/darch/Desktop/Recipes |
| 106 | +arch-chroot rootfs chown -R darch:darch /home/darch/ |
| 107 | + |
| 108 | +# Clean up |
| 109 | +umount rootfs/etc/darch |
| 110 | +umount rootfs/var/lib/darch |
| 111 | +umount rootfs/home |
| 112 | +umount rootfs |
| 113 | +losetup -d ${loop_device} |
| 114 | + |
| 115 | +echo "------------------------" |
| 116 | +echo "Finished creating the boot.img file." |
| 117 | +echo "This file bootable drive that could be dd'd directly to a drive, or converted to a virtual machine." |
| 118 | +echo "" |
| 119 | +echo "Commands for VMs" |
| 120 | +echo " VirtualBox: qemu-img convert -O vdi boot.img boot.vdi" |
| 121 | +echo " VMWare: qemu-img convert -O vmdk boot.img boot.vmdk" |
| 122 | +echo "" |
| 123 | +echo "NOTE: Ensure your VM has at least 4G of RAM allocated." |
| 124 | +echo "" |
| 125 | +echo "Please follow further instructions here:" |
| 126 | +echo "https://pknopf.com/post/2018-11-09-give-ubuntu-darch-a-quick-ride-in-a-virtual-machine/" |
| 127 | +echo "------------------------" |
0 commit comments