2024-02-03 17:47:41 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -o errexit -o nounset -o pipefail
|
|
|
|
|
|
|
|
. hosts.sh
|
|
|
|
|
2024-06-17 18:29:28 -04:00
|
|
|
[[ $# -eq 1 ]] || exit 1
|
|
|
|
|
|
|
|
readonly host=$1
|
|
|
|
readonly ip=${hosts_ipv4_address[$host]}
|
|
|
|
readonly hostname=${hosts_hostname[$host]}
|
|
|
|
readonly agcount=${hosts_agcount[$host]:-4}
|
|
|
|
readonly swap=${hosts_agcount[$host]:-2048}
|
2024-02-03 17:47:41 -05:00
|
|
|
readonly remote=root@$ip
|
|
|
|
|
2024-06-17 18:29:28 -04:00
|
|
|
readonly drive=$(ssh $remote '[[ -e /dev/sda ]] && echo sda || echo vda')
|
|
|
|
|
2024-02-03 17:47:41 -05:00
|
|
|
# check for Arch ISO
|
|
|
|
ssh $remote '[[ $(grep IMAGE_ID /etc/os-release) = "IMAGE_ID=archlinux" ]]' || exit 5
|
2024-06-15 13:36:29 -04:00
|
|
|
ssh $remote '[[ $(grep IMAGE_VERSION /etc/os-release) = "IMAGE_VERSION=2024.06.01" ]]' || exit 5
|
2024-02-03 17:47:41 -05:00
|
|
|
|
|
|
|
ssh $remote "sfdisk /dev/$drive -w always <<< ';'"
|
2024-02-24 10:28:10 -05:00
|
|
|
ssh $remote "mkfs.xfs -d agcount=$agcount -f /dev/${drive}1"
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv pacman.d/mirrorlist $remote:/etc/pacman.d/mirrorlist
|
2024-02-03 17:47:41 -05:00
|
|
|
ssh $remote "mount /dev/${drive}1 /mnt"
|
2024-06-17 15:00:36 -04:00
|
|
|
ssh $remote "pacstrap -K /mnt $(tr '\n' ' ' < packages/$host)"
|
2024-02-03 17:47:41 -05:00
|
|
|
|
|
|
|
ssh $remote "echo $hostname >/mnt/etc/hostname"
|
|
|
|
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cpv --chmod=644 systemd/network/$host.link $remote:/mnt/etc/systemd/network/10-public.link
|
|
|
|
rsync -cpv --chmod=644 systemd/network/$host.network $remote:/mnt/etc/systemd/network/10-public.network
|
2024-02-03 17:47:41 -05:00
|
|
|
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cpv --chmod=644 crypttab environment fstab hosts locale.conf pacman.conf pacreport.conf resolv.conf $remote:/mnt/etc/
|
2024-02-03 17:47:41 -05:00
|
|
|
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv grub $remote:/mnt/etc/default/grub
|
2024-02-03 17:47:41 -05:00
|
|
|
ssh $remote "arch-chroot /mnt grub-install /dev/$drive"
|
|
|
|
ssh $remote "arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg"
|
|
|
|
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv unbound.conf $remote:/mnt/etc/unbound/unbound.conf
|
2024-02-03 17:47:41 -05:00
|
|
|
|
|
|
|
if [[ $host = @(0.grapheneos.network|1.grapheneos.network|2.grapheneos.network|3.grapheneos.network) ]]; then
|
|
|
|
cp chrony.conf chrony.conf.tmp
|
|
|
|
echo -e '\nallow' >> chrony.conf.tmp
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv chrony.conf.tmp $remote:/mnt/etc/chrony.conf
|
2024-02-03 17:47:41 -05:00
|
|
|
rm chrony.conf.tmp
|
|
|
|
else
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv chrony.conf $remote:/mnt/etc/chrony.conf
|
2024-02-03 17:47:41 -05:00
|
|
|
fi
|
|
|
|
ssh $remote mkdir -vp /mnt/etc/sysconfig
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cpv --chmod 644 sysconfig/chronyd $remote:/mnt/etc/sysconfig/chronyd
|
2024-02-03 17:47:41 -05:00
|
|
|
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv authorized_keys $remote:/mnt/root/.ssh/authorized_keys
|
2024-02-03 17:47:41 -05:00
|
|
|
cp ssh/sshd_config ssh/sshd_config.tmp
|
|
|
|
sed -i "s/{{ssh_users}}/${hosts_ssh_users[$host]:-root}/g" ssh/sshd_config.tmp
|
2024-03-03 09:53:39 -05:00
|
|
|
rsync -cv ssh/sshd_config.tmp $remote:/mnt/etc/ssh/sshd_config
|
2024-02-03 17:47:41 -05:00
|
|
|
rm ssh/sshd_config.tmp
|
|
|
|
|
|
|
|
ssh $remote "arch-chroot /mnt systemctl enable chronyd.service fstrim.timer logrotate.timer plocate-updatedb.timer systemd-networkd.service sshd.service unbound.service"
|
|
|
|
ssh $remote "arch-chroot /mnt systemctl disable remote-fs.target systemd-network-generator.service"
|
|
|
|
|
2024-06-17 15:03:17 -04:00
|
|
|
ssh $remote "dd if=/dev/random of=/mnt/swapfile bs=1M count=$swap status=progress"
|
2024-02-03 17:47:41 -05:00
|
|
|
|
|
|
|
password=$(head -c32 <(tr -dc A-Za-z0-9 </dev/random))
|
|
|
|
echo password: $password
|
|
|
|
ssh $remote "echo root:$password | arch-chroot /mnt chpasswd"
|
|
|
|
ssh $remote umount /mnt
|
|
|
|
ssh $remote reboot
|