From 851c5e8ba8e65aafcfd6d03bc4883149424404ce Mon Sep 17 00:00:00 2001
From: Joel Grunbaum <joel@jsrv.proxmox.com>
Date: Tue, 13 Jul 2021 14:46:41 +0000
Subject: [PATCH] unneeded inversion

---
 arch-install.sh |   58 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/arch-install.sh b/arch-install.sh
index e33e945..cb4b5f9 100644
--- a/arch-install.sh
+++ b/arch-install.sh
@@ -1,35 +1,45 @@
 #!/bin/bash
+# Basic install script for an archlinux VM
+# To use as a basic hardware install script, remove qemu-guest-agent from pacstrap's arguments and qemu-ga from systemctl
+# Can comment out my repository if you like, I tend to use it for my VMs
 
 HOSTNAME=VM
 RPASS=root
+DISK=/dev/vda
+PARTNO=1
+LOCALE=en_US.UTF-8
+TIMEZONE=UTC # location in zoneinfo, e.g. Australia/Melbourne
 
-# Partition disk
-(
-echo n # Add a new partition
-echo p # Primary partition
-echo 1 # Partition number
-echo   # First sector (Accept default: 1)
-echo   # Last sector (Accept default: varies)
-echo w # Write changes
-) | sudo fdisk /dev/sda
-mkfs.ext4 /dev/sda1
+# Partition disk will create a new partition on the rest of the empty free space
+printf "n\np\n\n\n\nw\n" | fdisk $DISK
+mkfs.btrfs "$DISK$PARTNO"
 
 # Mount and install
-mount /dev/sda1 /mnt
-pacstrap base linux linux-firmware grub dhcpcd vim qemu-guest-agent
+mount -o compress=zstd "$DISK$PARTNO" /mnt
+pacstrap /mnt base linux linux-firmware grub dhcpcd vim qemu-guest-agent btrfs-progs
 genfstab -U /mnt >> /mnt/etc/fstab
 
-# Setup system in chroot
-arch-chroot /mnt "ln -sf /usr/share/zoneinfo/UTC /etc/localtime;
-				  echo en_US.UTF-8 >> /etc/locale.gen;
-				  locale-gen;
-				  echo LANG=en_US.UTF-8 > /etc/locale.conf;
-				  echo $HOSTNAME > /etc/hostname;
-				  printf \"127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\t$HOSTNAME.localdomain $HOSTNAME\" > /etc/hostname;
-				  systemctl enable dhcpcd qemu-guest-agent;
-				  mkinitcpio -P;
-				  echo root:$RPASS | chpasswd;
-				  grub-install /dev/sda;
-				  grub-mkconfig -o /boot/grub/grub.cfg"
+# Setup locale
+arch-chroot /mnt ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
+sed -i -e "s/#$LOCALE/$LOCALE/" /mnt/etc/locale.gen
+arch-chroot /mnt locale-gen
+echo "LANG=$LOCALE" > /mnt/etc/locale.conf
+
+# Set hostname and make hosts file
+echo $HOSTNAME > /mnt/etc/hostname
+printf "127.0.0.1\tlocalhost\n::1\t\tlocalhost\n127.0.1.1\t$HOSTNAME.localdomain $HOSTNAME" > /mnt/etc/hosts
+
+# Enable networking on boot and qemu guest agent
+arch-chroot /mnt systemctl enable dhcpcd qemu-ga
+
+# Make boot files and setup grub
+arch-chroot /mnt mkinitcpio -P
+arch-chroot /mnt sh -c "echo root:$RPASS | chpasswd"
+sed -i "s/GRUB_TIMEOUT=\d*/GRUB_TIMEOUT=\"0\"/" /mnt/etc/default/grub
+arch-chroot /mnt grub-install $DISK
+arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
+
+# Add my repo to pacman.conf
+printf "[Chizi123]\nSigLevel = Optional TrustAll\nServer = https://repo.joelg.cf/x86_64\n" >> /mnt/etc/pacman.conf
 
 reboot

--
Gitblit v1.9.3