Created
April 4, 2019 14:35
-
-
Save angelsl/7d169dcf0eba06816d0d3198da91556a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
apt-get -y update && apt-get -y install haveged && systemctl start haveged | |
disksize=$(lsblk -bndo SIZE /dev/vda) | |
partm=$(($disksize/1048576-1024)) | |
cat <<EOF | sfdisk /dev/vda | |
label: dos | |
size=${partm}M type=83 | |
type=82 | |
EOF | |
mkfs.ext4 /dev/vda2 | |
mount /dev/vda2 /mnt | |
curl -L https://sgp.mirror.pkgbuild.com/iso/latest/archlinux-bootstrap-2019.04.01-x86_64.tar.gz | tar -C /mnt --strip-components=1 -zx | |
cat <<EOF > /mnt/chroot.sh | |
pacman-key --init && pacman-key --populate archlinux | |
echo 'Server = https://sgp.mirror.pkgbuild.com/\$repo/os/\$arch' > /etc/pacman.d/mirrorlist | |
pacman -Sy | |
mkfs.ext4 /dev/vda1 | |
mount /dev/vda1 /mnt | |
pacstrap /mnt base haveged openssh grub | |
genfstab -U /mnt >> /mnt/etc/fstab | |
cp /inst.sh /mnt/root/inst.sh | |
arch-chroot /mnt bash /root/inst.sh | |
EOF | |
cat <<EOF > /mnt/inst.sh | |
ln -sf /usr/share/zoneinfo/Asia/Singapore /etc/localtime | |
hwclock --systohc | |
echo en_SG.UTF-8 UTF-8 > /etc/locale.gen | |
locale-gen | |
echo LANG=en_SG.UTF-8 > /etc/locale.conf | |
echo $HOSTNAME > /etc/hostname | |
grub-install /dev/vda | |
grub-mkconfig -o /boot/grub/grub.cfg | |
echo 'PermitRootLogin prohibit-password' >> /etc/ssh/sshd_config | |
echo 'DNSSEC=no' >> /etc/systemd/resolved.conf | |
echo 'DNSOverTLS=no' >> /etc/systemd/resolved.conf | |
umount /etc/resolv.conf | |
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf | |
systemctl enable sshd haveged systemd-networkd systemd-resolved | |
passwd | |
EOF | |
/mnt/usr/bin/arch-chroot /mnt bash /chroot.sh | |
mkdir -p /mnt/mnt/etc/systemd/network | |
cat <<EOF > /mnt/mnt/etc/systemd/network/ens3.network | |
[Match] | |
Name=ens3 | |
[Network] | |
$(ip addr show scope global | grep -E '^\s+inet' | sed -e 's/^[[:space:]]*inet[0-9]* /Address=/' | cut -d' ' -f1) | |
Gateway=$(ip route get 1.0.0.1 | grep -o -E 'via [0-9\.]+' | cut -d' ' -f2) | |
Gateway=$(ip route get 2606:4700:4700::1111 | grep -o -E 'via [0-9a-f:]+' | cut -d' ' -f2) | |
DNS=1.0.0.1 | |
DNS=1.1.1.1 | |
DNS=2606:4700:4700::1111 | |
DNS=2606:4700:4700::1001 | |
EOF | |
cp -R /root/.ssh /mnt/mnt/root/.ssh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment