-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharch-install.sh
executable file
·203 lines (157 loc) · 5.43 KB
/
arch-install.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
# Variables
DISK="/dev/sda" # lsblk -a
LAPTOP=false # special instalation for laptops
SWAP=false # Enable swap
LANG="en_US.UTF-8" # /etc/locale.gen
KEYMAP="dvorak" # list keymaps with "localectl list-keymaps"
NAME="arch" # Hostname
TIMEZONE="America/Lima" # list zones with "timedatectl list-zones"
CIFRATE_DISK=false # cifrate grub and disk.
# Function for confirm a password for a user
ask_password() {
while true; do
read -p "Set password for $1: " pass
read -p "Confirm password: " confirm
if [[ "$pass" = "$confirm" ]]; then
break
fi
done
echo "$pass"
}
# Comprobar si el sistema usa UEFI
EFI=""
TYPE="msdos"
if [[ -d /sys/firmware/efi ]]; then
EFI="/efi"
TYPE="gpt"
fi
# cifrate disk and grub
GRUB_PASS=""
if [[ "$CIFRATE_DISK" = true ]]; then
echo -e "\n################################################\n"
echo -e "[!] Encrypting grub, please provide a password...\n"
GRUB_PASS=$(ask_password "GRUB")
fi
# --------------- Particiones ---------------
# Eliminar todas las particiones previas
parted -s "$DISK" mklabel "$TYPE"
# Crear particiones
if [[ "$EFI" = "" ]]; then
echo "creando BIOS"
parted -s "$DISK" mkpart primary fat32 1MiB 513MiB
else
echo "creando UEFI"
parted -s "$DISK" mkpart esp fat32 1MiB 513MiB
parted -s "$DISK" set 1 esp on
fi
if [[ "$SWAP" = false ]];then
ROOT_PART="2"
ROOT_START="513MiB"
ROOT_END="100%"
else
parted -s "$DISK" mkpart primary linux-swap 513MiB 8075MiB
ROOT_PART="3"
ROOT_START="8075MiB"
ROOT_END="100%"
fi
parted -s "$DISK" mkpart primary ext4 "$ROOT_START" "$ROOT_END"
if [[ "$CIFRATE_DISK" = true ]]; then
echo -e "\n################################################\n"
echo -e "[!] Encrypting disk, please provide a password...\n"
cryptsetup luksFormat "${DISK}${ROOT_PART}"
cryptsetup open "${DISK}${ROOT_PART}" cryptroot
fi
# --------------- Formateo ---------------
if [[ "$EFI" = "" ]]; then
mkfs.vfat -F32 "${DISK}1" # Formatear EFI
fi
if [[ "$CIFRATE_DISK" = true ]]; then
echo -e "\n################################################\n"
cryptsetup luksFormat "${DISK}${ROOT_PART}"
cryptsetup open "${DISK}${ROOT_PART}" cryptroot
mkfs.ext4 /dev/mapper/cryptroot
fi
if [[ "$SWAP" = true ]]; then
mkswap "${DISK}2"
else
if [[ "$CIFRATE_DISK" = false ]]; then
mkfs.ext4 "${DISK}${ROOT_PART}"
fi
fi
# --------------- Montaje ---------------
if [[ "$SWAP" = true ]]; then
swapon "${DISK}2"
fi
if [[ "$CIFRATE_DISK" = true ]]; then
mount /dev/mapper/cryptroot /mnt
else
mount "${DISK}${ROOT_PART}"
fi
mkdir -p "/mnt/boot${EFI}"
mount "${DISK}1" "/mnt/boot${EFI}"
# --------------- Instalación del sistema ---------------
pacstrap /mnt base base-devel networkmanager grub gvfs linux linux-firmware nano vim cryptsetup ${EFI:+efibootmgr}
# Para laptops
if [[ "$LAPTOP" = true ]]; then
# Controladores de wifi, el track pad, etc.
pacstrap /mnt netctl wpa_supplicant dialog xf86-input-synaptics
fi
echo -e "Before starting the installation, create a password for the root user and your own user.\n"
# Configurar contraseña para root
ROOTPASS=$(ask_password "root")
echo
# Crear usuario personal con privilegios de sudo
read -p "Enter your username: " USERNAME
# Configurar contraseña para el usuario
USERPASS=$(ask_password "$USERNAME")
# --------------- Generar fstab ---------------
genfstab -U /mnt > /mnt/etc/fstab
# --------------- Chroot y configuración ---------------
arch-chroot /mnt << EOF
if [[ "$CIFRATE_DISK" = true ]]; then
uuid=$(blkid -s UUID -o value "${DISK}${ROOT_PART}")
grub_default="/etc/default/grub"
mkinit_file="/etc/mkinitcpio.conf"
if [[ grep -q 'GRUB_CMDLINE_LINUX=' "$grub_default" ]]; then
sed -i "s|^GRUB_CMDLINE_LINUX=.*|GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=$uuid:cryptroot root=/dev/mapper/cryptroot\"|" "$grub_default"
else
echo "GRUB_CMDLINE_LINUX=\"cryptdevice=UUID=$uuid:cryptroot root=/dev/mapper/cryptroot\"" >> "$grub_default"
fi
sed -i 's/^HOOKS=.*/HOOKS=(base udev autodetect keyboard keymap modconf block encrypt filesystems)/' "$mkinit_file"
fi
timedatectl set-timezone "$TIMEZONE"
timedatectl set-ntp true
echo "$NAME" > /etc/hostname
sed -i 's/^#\(en_US.UTF-8 UTF-8\)/\1/' /etc/locale.gen
#echo "LANG=$LANG" > /etc/locale.conf
locale-gen
cat <<HOSTS > /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${NAME}.local ${NAME}
HOSTS
systemctl enable NetworkManager
echo "KEYMAP=$KEYMAP" > /etc/vconsole.conf
echo "root:$ROOTPASS" | chpasswd
useradd -m -G wheel -s /bin/bash "$USERNAME"
echo "$USERNAME:$USERPASS" | chpasswd
sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
if [[ "$CIFRATE_DISK" = true ]]; then
mkinitcpio -P
fi
if [[ "$EFI" = "/efi" ]]; then
grub-install --efi-directory=/boot/efi --bootloader-id=GRUB --removable
else
grub-install "$DISK"
fi
if [[ "$CIFRATE_DISK" = true ]]; then
PASS_HASH=$(echo -e "$GRUB_PASS\n$GRUB_PASS" | grub-mkpasswd-pbkdf2 | grep 'grub.pbkdf2' | awk '{print $NF}')
echo "set superusers=\"root\"" | sudo tee -a /etc/grub.d/40_custom
echo "password_pbkdf2 root $PASS_HASH" | sudo tee -a /etc/grub.d/40_custom
fi
grub-mkconfig -o /boot/grub/grub.cfg
EOF
# --------------- Salida y reinicio ---------------
umount -R /mnt
echo "Manually reboot when you're ready and remove boot device.";