-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path00-arch-install.sh
executable file
·190 lines (157 loc) · 5.31 KB
/
00-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
#!/bin/bash
# This script should be run after internet configuration from archlinux iso
set -euo pipefail
# confirm you can access the internet
echo -n "Testing Internet connection ... "
ping -q -w 1 -c 1 google.fr > /dev/null && echo "OK" || (echo "Your Internet seems broken. Press Ctrl-C to abort or enter to continue." && read)
# Get total memory to define swap file sizing
memSize=$(free|awk '/^Mem:/{print $2}')
memSwap=$(echo $memSize | sed -e "s/M//")
if [[ $memSwap -ge 4096 ]]
then
memSwap=4096
fi
# microcode management
manufacturer=""
if lscpu | grep -qi intel; then
manufacturer="intel"
elif lscpu | grep -qi amd; then
manufacturer="amd"
fi
device=
fdisk -l | grep '^Disk[[:space:]]*/' | grep -v loop
while [[ ! -b $device ]]; do
read -p "Type your device path (e.g. /dev/sda): " -e device
done
echo -e "\033[0;31m/!\ Warning : $device will be totally erased !\033[0m"
go=""
while ! ([[ "$go" == "y" ]] || [[ "$go" == "n" ]]); do
read -p "Are you sure to continue ? (y/n): " -e go
done
if [[ $go == "n" ]]; then
exit 1
fi
suffix=""
if [[ "${device}" == *"nvme"* ]] || [[ "${device}" == *"mmc"* ]];
then suffix="p"
fi
# erase disk
echo -n "Erase disk ... "
sgdisk --zap-all ${device}
echo "OK"
# make partitions on the disk.
echo -n "Partitioning ... "
sgdisk --new=0:0:+512MiB ${device}
sgdisk --change-name=1:ESP ${device}
sgdisk --typecode=1:EF00 ${device}
sgdisk --new=0:0:0 ${device}
sgdisk --change-name=2:SYSTEM ${device}
sgdisk --typecode=2:8300 ${device}
partprobe ${device}
echo "OK"
# make filesystems
echo -n "Creating file system ... "
# /boot
mkfs.fat -F32 ${device}${suffix}1
# /
mkfs.ext4 -Fv ${device}${suffix}2
echo "OK"
uuid=$(blkid -o value -s UUID ${device}${suffix}2)
# set up /mnt
echo -n "Mounting partitions ... "
mount ${device}${suffix}2 /mnt
mkdir /mnt/boot
mount ${device}${suffix}1 /mnt/boot
echo "OK"
# Update database
echo "Updating repository database ... "
pacman -Syy
pacman -S wget unzip pacman-contrib --noconfirm
# rankmirrors to make this faster (though it takes a while)
echo -n "Ranking repository mirrors ... "
pacman -S --noconfirm pacman-mirrorlist
cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.orig
curl -s "https://www.archlinux.org/mirrorlist/?country=FR&country=DE&country=IT&country=GB&protocol=https&use_mirror_status=on" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 6 - > /etc/pacman.d/mirrorlist
echo "OK"
# Install keys for archlinux packages
pacman -S --noconfirm archlinux-keyring
echo "Installing ArchLinux ... "
# install base packages (take a coffee break if you have slow internet)
pacstrap /mnt base linux linux-firmware
# copy ranked mirrorlist over
cp /etc/pacman.d/mirrorlist* /mnt/etc/pacman.d
# generate fstab
genfstab -p -U /mnt >> /mnt/etc/fstab
# chroot
arch-chroot /mnt /bin/bash <<EOF
# set up swap
fallocate -l ${memSwap}M /swapfile
chmod 600 /swapfile
mkswap /swapfile
echo -e "# Swap\n/swapfile\t\tnone\t\tswap\t\tdefaults\t0 0" >> /etc/fstab
# set initial hostname
echo "archlinux-$(date -I)" >/etc/hostname
# set initial timezone to America/Los_Angeles
ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
# set hw clock on utc
hwclock --systohc --utc
# set initial locale
echo "fr_FR.UTF-8 UTF-8" >>/etc/locale.gen
echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen
echo "fr_FR ISO-8859-1" >>/etc/locale.gen
locale-gen
#locale >/etc/locale.conf
#sed -i -e 's/LANG="en_US/LANG="fr_FR/' /etc/locale.conf
echo 'LANG="fr_FR.UTF-8"' > /etc/locale.conf
# set keymap
echo "KEYMAP=fr-pc" > /etc/vconsole.conf
# install systemd-boot
bootctl --path=/boot install
cp /usr/share/systemd/bootctl/loader.conf /boot/loader/loader.conf
echo "timeout 1" >> /boot/loader/loader.conf
cat <<EOC > /boot/loader/entries/arch.conf
title Arch Linux
linux /vmlinuz-linux
initrd /initramfs-linux.img
options root=UUID=${uuid} rw
EOC
if ! [ -z ${manufacturer} ]; then
pacman -S ${manufacturer}-ucode --noconfirm
sed -i "/^linux.*\/vm/a initrd /${manufacturer}-ucode.img" /boot/loader/entries/arch.conf
fi
# no modifications to mkinitcpio.conf should be needed
mkinitcpio -P
# set root password to "root"
echo root:azer | chpasswd
# Set initial configuration
echo -n "Quick basic configuration ... "
echo -e '\n[archlinuxfr]\nSigLevel = Never\nServer = http://repo.archlinux.fr/\$arch\n' >> /etc/pacman.conf
pacman -Syu
pacman -S pacman --noconfirm
pacman -S vim bash-completion colordiff lsb-release pacman-contrib --noconfirm
pacman -S openssh ntp --noconfirm
systemctl enable sshd
systemctl enable ntpd
sed -i 's/^#[[:space:]]*Color/Color/g' /etc/pacman.conf
sed -i 's/^#[[:space:]]*VerbosePkgLists/VerbosePkgLists/g' /etc/pacman.conf
# end section sent to chroot
EOF
# Add default bashrc and profile files
if ! grep -q '### Tweaks bashrc' /mnt/etc/bash.bashrc; then
cat $(dirname $0)/files/bash/bash.bashrc >> /mnt/etc/bash.bashrc
fi
if ! grep -q '" vim custom config' /mnt/etc/vimrc; then
cat $(dirname $0)/files/vim/vimrc >> /mnt/etc/vimrc
fi
cp -f $(dirname $0)/files/bash/profile/* /mnt/etc/profile.d/
wifi=""
while ! ([[ "$wifi" == "y" ]] || [[ "$wifi" == "n" ]]); do
read -p "Do you want install wifi support ? (y/n): " -e wifi
done
if [[ $wifi == "y" ]]; then
pacstrap /mnt dialog wpa_supplicant
fi
# unmount
umount /mnt/{boot,}
echo "Done! Unmount the CD image from the VM, then type 'reboot'."
echo -e "\033[0;31m/!\ Password for root authentification is 'azer'\033[0m"