aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReid 'arrdem' McKenzie <me@arrdem.com>2018-06-03 23:47:50 -0700
committerReid 'arrdem' McKenzie <me@arrdem.com>2018-06-03 23:47:50 -0700
commit844e28cd8b767aa60b74e8f194eca067b863aefa (patch)
tree500f5047f86cc5ace359ff1e6c09a67785981e12
downloadarch-auto-install-844e28cd8b767aa60b74e8f194eca067b863aefa.tar.gz
arch-auto-install-844e28cd8b767aa60b74e8f194eca067b863aefa.tar.xz
arch-auto-install-844e28cd8b767aa60b74e8f194eca067b863aefa.zip
Initial state for installing Mk. 1 nodes
-rwxr-xr-xroot/chroot.sh67
-rwxr-xr-xroot/install.sh61
-rwxr-xr-xrun.sh27
3 files changed, 155 insertions, 0 deletions
diff --git a/root/chroot.sh b/root/chroot.sh
new file mode 100755
index 0000000..087d928
--- /dev/null
+++ b/root/chroot.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+set -x
+
+# $1 to this script is the boot device's name
+# $2 is the hostname to deploy
+
+HOST="$2"
+USERNAME=arrdem
+HOME_DIR="/home/${USERNAME}"
+
+# grub as a bootloader
+grub-install --target=x86_64-efi --efi-directory=/boot/efi/ --bootloader-id=GRUB --recheck "$1"
+
+# This makes the grub timeout 0, it's faster than 5 :)
+#
+# Skipping this so that it's still possible to physically get on the
+# node without using custom boot media.
+# sudo sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/g' /etc/default/grub
+
+grub-mkconfig -o /boot/grub/grub.cfg
+
+# run these following essential service by default
+systemctl enable sshd.service
+systemctl enable dhcpcd.service
+systemctl enable ntpd.service
+
+# Network configuration
+echo "$HOST.apartment.arrdem.com" > /etc/hostname
+cat <<EOF >> /etc/hosts
+127.0.0.1 localhost
+::1 localhost
+127.0.1.1 $HOSTNAME $HOSTNAME.apartment.arrdem.com
+EOF
+
+# adding your normal user with additional wheel group so can sudo
+useradd -m -G wheel -s /bin/bash "$USERNAME"
+
+# adding public key both to root and user for ssh key access
+mkdir -m 700 -p "$HOME_DIR/.ssh"
+mkdir -m 700 -p /root/.ssh
+cp /authorized_keys "/$HOME_DIR/.ssh"
+cp /authorized_keys /root/.ssh
+chown -R "$USERNAME:$USERNAME" "$HOME_DIR/.ssh"
+
+# adjust your timezone here
+ln -f -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
+hwclock --systohc
+
+# adjust your name servers here if you don't want to use google
+# echo 'name_servers="8.8.8.8 8.8.4.4"' >> /etc/resolvconf.conf
+
+# Set up the locale
+echo en_US.UTF-8 UTF-8 > /etc/locale.gen
+echo LANG=en_US.UTF-8 > /etc/locale.conf
+locale-gen
+
+# because we are using ssh keys, make sudo not ask for passwords
+echo 'root ALL=(ALL) ALL' > /etc/sudoers
+echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
+
+# I like to use vim :)
+echo -e 'EDITOR=emacs' > /etc/environment
+
+# auto-complete these essential commands
+echo complete -cf sudo >> /etc/bash.bashrc
+echo complete -cf man >> /etc/bash.bashrc
diff --git a/root/install.sh b/root/install.sh
new file mode 100755
index 0000000..c53ad67
--- /dev/null
+++ b/root/install.sh
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+set -x
+
+# $1 is the hostname to install
+
+HOSTNAME="$1"
+
+# Partition the NVME device as the boot device
+BOOT_DISK="/dev/nvme0n1"
+parted -s "$BOOT_DISK" mklabel gpt
+
+BOOT_PARTITION="${BOOT_DISK}p1"
+parted -s -a optimal "$BOOT_DISK" mkpart primary 0 512
+parted -s "$BOOT_DISK" set 1 boot on
+parted -s "$BOOT_DISK" set 1 esp on
+# Make fat32
+mkfs.fat -F32 "$BOOT_PARTITION"
+
+ROOT_PARTITION="${BOOT_DISK}p2"
+parted -s -a optimal "$BOOT_DISK" mkpart primary ext4 512 100%
+# Force creation
+mkfs.ext4 -F "$ROOT_PARTITION"
+
+# Partition the data/scratch disk
+DATA_DISK="/dev/sda"
+DATA_PARTITION="${DATA_DISK}1" # NVME and SATA have different naming schemes >.>
+parted -s "$DATA_DISK" mklabel gpt
+parted -s -a optimal "$DATA_DISK" mkpart primary ext4 0% 100%
+# Force creation
+mkfs.ext4 -F "$DATA_PARTITION" # I may regret this later
+
+# Mount the boot partition - we'll chroot into it in a second
+mount "$ROOT_PARTITION" /mnt
+
+mkdir -p /mnt/boot/efi
+mount "$BOOT_PARTITION" /mnt/boot/efi
+
+mkdir /mnt/data
+mount "$DATA_PARTITION" /mnt/data
+
+mkdir -p /mnt/root/.ssh
+
+# Bootstrap into the new disk & install a bunch of stuff
+pacman -Syy
+pacstrap /mnt base base-devel grub efibootmgr openssh sudo ntp wget vim emacs-nox
+genfstab -p /mnt >> /mnt/etc/fstab
+
+cp ./chroot.sh /mnt/
+cp ~/.ssh/authorized_keys /mnt/
+cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist
+
+# Chroot into the new disk and run the chroot part of this setup dance
+arch-chroot /mnt /chroot.sh "$BOOT_DISK" "$HOSTNAME"
+
+# Remove the chroot bits
+rm /mnt/chroot.sh
+rm /mnt/authorized_keys
+
+umount -R /mnt
+systemctl reboot
diff --git a/run.sh b/run.sh
new file mode 100755
index 0000000..09b4a6f
--- /dev/null
+++ b/run.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+read HOSTNAME
+read HOST
+PORT=22
+
+echo PORT="$PORT", HOST="$HOST"
+HOST_ROOT="root@$HOST"
+PUBKEY=$(cat ~/.ssh/id_rsa.pub)
+
+if [ ! -f mirrorlist.ranked ]; then
+ awk '/^## United States$/{f=1}f==0{next}/^$/{exit}{print substr($0, 2)}' /etc/pacman.d/mirrorlist.pacnew > mirrorlist.unranked
+ rankmirrors -n 6 mirrorlist > mirrorlist.ranked
+fi
+
+# copy your public key, so can ssh without a password later on
+ssh -tt -p "$PORT" "$HOST_ROOT" "mkdir -p -m 700 ~/.ssh; echo $PUBKEY > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys"
+
+# copy install scripts from ./root folder
+scp -P "$PORT" ./root/* "$HOST_ROOT:/root"
+scp -P "$PORT" mirrorlist.ranked "$HOST_ROOT:/etc/pacman.d/mirrorlist"
+
+# set the executable bits
+ssh -tt -p "$PORT" "$HOST_ROOT" "chmod +x ./install.sh ./chroot.sh"
+
+# run the install script remotely
+ssh -tt -p "$PORT" "$HOST_ROOT" "./install.sh" "$HOSTNAME"