~alexdavid/dotfiles

ref: ec258e597464b4340b1781e7d30cd6c33fd9c363 dotfiles/archlinux/setup/init -rw-r--r-- 1.9 KiB
ec258e59 — Alex David Update i3block order 1 year, 9 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash

set -e

function section {
  echo
  echo
  echo
  echo "################################################################"
  echo "==> $1"
  echo
}

function ask {
  printf "%s: " "$2"
  read $1
}

function confirm {
  QUESTION="$1"
  CONTINUE="nil"
  while [ "$CONTINUE" != "yes" ]; do
    ask CONTINUE "$1 (yes/no)"
    if [ "$CONTINUE" == "no" ]; then
      exit 1
    fi
  done
}

section "GENERATING AND UPDATING MIRROR LIST"
curl "https://www.archlinux.org/mirrorlist/?country=US&protocol=https&ip_version=4" | sed -E 's/^#//' > /etc/pacman.d/mirrorlist
cat /etc/pacman.d/mirrorlist
confirm "Does this mirror list look good"


section "PARTITIONING DRIVES"
fdisk -l
ask DRIVE "Select a drive"
{
  echo g       # make gpt partition table

  echo n       # Add new partition (/boot)
  echo         # (default 1)
  echo         # (default 2048)
  echo "+512M"

  echo n       # Add new partition (swap)
  echo         # (default 2)
  echo         # (default)
  echo "+2G"

  echo n       # Add new partition (linux)
  echo         # (default 3)
  echo         # (default)
  echo         # (default)

  echo t       # Change partition type
  echo 1       # Partition number 1 (/boot)
  echo 1       # EFI System

  echo t       # Change partition type
  echo 2       # Partition number 2 (swap)
  echo 19      # Linux swap

  echo w       # write
} | fdisk "$DRIVE"
fdisk -l
confirm "Does drive partition look good"


PARTITIONS=($(lsblk -pln -o name "$DRIVE"))


section "FORMATTING & MOUNTING DRIVES"
cryptsetup luksFormat --type luks "${PARTITIONS[3]}"
cryptsetup luksOpen "${PARTITIONS[3]}" main
mkfs.vfat -F32 "${PARTITIONS[1]}"
mkfs.ext4 -F /dev/mapper/main
mount /dev/mapper/main /mnt
mkdir /mnt/boot
mount "${PARTITIONS[1]}" /mnt/boot

# Install base
pacstrap /mnt base
genfstab -U /mnt >> /mnt/etc/fstab

# Setup grub cryptmapper
echo "GRUB_CMDLINE_LINUX=\"cryptdevice=${PARTITIONS[3]}:cryptroot\"" >> /mnt/etc/default/grub