-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.sh
executable file
·314 lines (267 loc) · 7.82 KB
/
base.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/usr/bin/env bash
# set -eu
declare VOLUMEN;
declare VOLUMEN_ID;
declare HOSTNAME;
declare PASSWORD;
function main() {
VOLUMEN="/dev/nvme0n1"
HOSTNAME="strappazzon"
ntp
mirror
keyboard
user_password
partitioning
base
configure_input
configure_locale
configure_environment
configure_profile
configure_network
configure_user
configure_grub
packages
services
drivers
finish
}
function ntp() {
echo "--> Configure time zone and NTP."
timedatectl set-timezone Europe/Madrid
timedatectl set-ntp true
hwclock --systohc
}
function mirror() {
echo "--> Configure mirrorlist."
cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
reflector -a 48 -c ES -f 5 -l 20 --sort rate --save /etc/pacman.d/mirrorlist
echo "--> Synchronize database..."
pacman -Sy &> /dev/null
}
function keyboard() {
echo "--> Configure keyboard layaout."
loadkeys us
}
function user_password() {
echo "--> Define password for root and user."
while true; do
IFS="" read -r -s -p " Enter your password: " PASSWORD </dev/tty
echo
IFS="" read -r -s -p " Confirm your password: " password_confirm </dev/tty
echo
[ "${PASSWORD}" = "${password_confirm}" ] && break
echo "--> Passwords do not match. Please try again."
done
PASSWORD=$(openssl passwd -6 "$password_confirm")
}
function partitioning() {
readarray -t VOLUMES_LIST < <(lsblk --list --nvme --nodeps --ascii --noheadings --output=NAME | sort)
VOLUMENS_COUNT=$(( ${#VOLUMES_LIST[@]} - 1 ))
echo "--> Available volumes:"
for VOLUMEN_INDEX in "${!VOLUMES_LIST[@]}"; do
echo " ${VOLUMEN_INDEX}. ${VOLUMES_LIST[$VOLUMEN_INDEX]}"
done
until [[ $VOLUMEN_ID =~ ^[0-${VOLUMENS_COUNT}]$ ]]; do
IFS="" read -r -p " > Choice volume number: " VOLUMEN_ID </dev/tty
done
VOLUMEN="/dev/${VOLUMES_LIST[$VOLUMEN_ID]}"
echo " > Has chosen this volume: $VOLUMEN"
echo "--> Umount partitions."
(umount --all-targets --quiet --recursive /mnt/) || true
(swapoff --all) || true
echo "--> Delete old partitions."
(parted --script "${VOLUMEN}" rm 1 &> /dev/null) || true
(parted --script "${VOLUMEN}" rm 2 &> /dev/null) || true
(parted --script "${VOLUMEN}" rm 3 &> /dev/null) || true
echo "--> Create new partitions."
parted --script "${VOLUMEN}" mklabel gpt
parted --script "${VOLUMEN}" mkpart efi fat32 1MiB 1024MiB
parted --script "${VOLUMEN}" set 1 esp on
parted --script "${VOLUMEN}" mkpart swap linux-swap 1GiB 32GiB
parted --script "${VOLUMEN}" mkpart root ext4 32GiB 100%
echo "--> Format partitions."
mkfs.fat -F32 -n UEFI "${VOLUMEN}p1" &> /dev/null
mkswap -L SWAP "${VOLUMEN}p2" &> /dev/null
mkfs.ext4 -L ROOT "${VOLUMEN}p3" &> /dev/null
echo "--> Verify partitions."
partprobe "${VOLUMEN}"
echo "--> Mount: swap, root and boot"
swapon "${VOLUMEN}p2"
mount "${VOLUMEN}p3" /mnt
mkdir -p /mnt/boot/efi/
mount "${VOLUMEN}p1" /mnt/boot/efi/
echo "--> Remove default directories lost+found."
rm -rf /mnt/boot/efi/lost+found
rm -rf /mnt/lost+found
echo "--> Generate fstab."
mkdir /mnt/etc/
genfstab -pU /mnt >> /mnt/etc/fstab
}
function base() {
echo "--> Installing essential packages."
pacstrap /mnt \
base \
base-devel \
dhcpcd \
efibootmgr \
grub \
iwd \
linux \
linux-firmware \
linux-headers \
man-db \
mkinitcpio \
networkmanager \
openssh \
vim \
&> /dev/null
}
function configure_input() {
sed -i 's/#set bell-style none/set bell-style none/g' /mnt/etc/inputrc
}
function configure_locale() {
echo "en_US.UTF-8 UTF-8" > /mnt/etc/locale.gen
echo "LANG=en_US.UTF-8" > /mnt/etc/locale.conf
echo "LANGUAGE=en_US" >> /mnt/etc/locale.conf
echo "LC_ALL=C" >> /mnt/etc/locale.conf
arch-chroot /mnt locale-gen &> /dev/null
}
function configure_environment() {
cat > /mnt/etc/environment << 'EOF'
EDITOR=vim
TERM=xterm
TERMINAL=xterm
EOF
}
function configure_profile() {
cat > /mnt/etc/skel/.bashrc << 'EOF'
[[ $- != *i* ]] && return
if [ -x /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -f "$i" ]; then
. "$i"
fi
done
fi
EOF
cat > /mnt/etc/profile.d/custom.sh << 'EOF'
#!/bin/sh
if [ -x ~/.bashrc.d ]; then
for i in ~/.bashrc.d/*.sh; do
if [ -f "$i" ]; then
. "$i"
fi
done
fi
EOF
cat > /mnt/etc/profile.d/ps.sh << 'EOF'
#!/bin/sh
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\][\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '
else
PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] '
fi
EOF
rm -f /mnt/etc/profile.d/perlbin.*
}
function configure_network() {
echo "--> Network configuration."
echo $HOSTNAME > /mnt/etc/hostname
cat << EOF > /mnt/etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 ${HOSTNAME}.localdomain $HOSTNAME
EOF
}
function configure_user() {
echo "--> Create user."
arch-chroot /mnt useradd --create-home --shell=/bin/bash --gid=users --groups=wheel,uucp,video --password="$PASSWORD" --comment="Nicola Strappazzon C." nicola
arch-chroot /mnt sed -i 's/^# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers
cp /mnt/etc/skel/.bashrc /mnt/root/.bashrc
chmod 0600 /mnt/root/.bashrc
arch-chroot /mnt usermod --shell /bin/bash root
printf "root:%s" "$PASSWORD" | arch-chroot /mnt chpasswd --encrypted
}
function configure_grub() {
echo "--> Install & configure bootloader."
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB &> /dev/null
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg &> /dev/null
echo "GRUB_DEFAULT=0" > /mnt/etc/default/grub.silent
echo "GRUB_TIMEOUT=0" >> /mnt/etc/default/grub.silent
echo "GRUB_RECORDFAIL_TIMEOUT=\$GRUB_TIMEOUT" >> /mnt/etc/default/grub.silent
chmod 0644 /mnt/etc/default/grub.silent
sed -i "s/timeout=5/timeout=0/" /mnt/boot/grub/grub.cfg
sed -i "s/echo 'Loading Linux linux ...'//" /mnt/boot/grub/grub.cfg
sed -i "s/echo 'Loading initial ramdisk ...'//" /mnt/boot/grub/grub.cfg
sed -i "s/loglevel=3 quiet/quiet loglevel=0 rd.systemd.show_status=auto rd.udev.log_level=3/" /mnt/boot/grub/grub.cfg
}
function packages() {
echo "--> Install aditional packages."
PACKAGES=(
base
base-devel
bash-completion
bind-tools
btop
ca-certificates
curl
dosfstools
fzf
git
go
htop
less
libusb
links
neofetch
net-tools
networkmanager-openvpn
nmap
openvpn
pass
pass-otp
rsync
testdisk
tmux
traceroute
ufw
unrar
unzip
usbutils
vim
wget
wl-clipboard
xclip
)
for PACKAGE in "${PACKAGES[@]}"; do
arch-chroot /mnt pacman -S "${PACKAGE}" --noconfirm --needed &> /dev/null
done
}
function services() {
echo "--> Enable services."
arch-chroot /mnt systemctl enable sshd
arch-chroot /mnt systemctl start sshd
arch-chroot /mnt systemctl enable NetworkManager
arch-chroot /mnt systemctl start NetworkManager
}
function drivers() {
echo "--> Install drivers."
sudo pacman -S --noconfirm --needed \
alsa-firmware \
alsa-utils \
amd-ucode \
pulseaudio \
pulseaudio-alsa \
ddcutil \
&> /dev/null
}
function finish() {
echo "--> Unmount all partitions and reboot."
echo
read -n 1 -s -r -p "Press any key to continue" </dev/tty
(umount --all-targets --quiet --recursive /mnt/) || true
(swapoff --all) || true
clear
reboot
}
main "$@"