-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchinstall.sh
More file actions
300 lines (236 loc) · 8.41 KB
/
archinstall.sh
File metadata and controls
300 lines (236 loc) · 8.41 KB
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
#!/bin/bash
# Function to get available drives
get_available_drives() {
lsblk -ndo NAME,SIZE,TYPE | awk '$3=="disk" {print "/dev/"$1" ("$2")"}'
}
# Function to install base Arch Linux
install_base_arch() {
print_message "$BLUE" "Installing base Arch Linux..."
# Select installation drive
mapfile -t drives < <(get_available_drives)
drives+=("Back to main menu")
display_colored_menu "Select installation drive:" "${drives[@]}"
drive_choice=$?
if [ $drive_choice -eq ${#drives[@]}-1 ]; then
return
fi
selected_drive=$(echo "${drives[$drive_choice]}" | cut -d' ' -f1)
print_message "$BLUE" "Selected drive: $selected_drive"
# Get user input for various settings
read -p "Enter desired hostname: " hostname
read -p "Enter desired username: " username
read -s -p "Enter password for $username: " user_password
echo
read -s -p "Enter root password: " root_password
echo
# Get region/timezone
read -p "Enter your timezone (e.g., America/New_York): " timezone
# Get keyboard layout
read -p "Enter your keyboard layout (e.g., us): " keyboard_layout
# Update system clock
timedatectl set-ntp true
# Partition the disk
parted $selected_drive mklabel gpt
parted $selected_drive mkpart ESP fat32 1MiB 513MiB
parted $selected_drive set 1 esp on
parted $selected_drive mkpart primary ext4 513MiB 100%
# Format the partitions
mkfs.fat -F32 "${selected_drive}1"
mkfs.ext4 "${selected_drive}2"
# Mount the file systems
mount "${selected_drive}2" /mnt
mkdir /mnt/boot
mount "${selected_drive}1" /mnt/boot
# Install base packages and additional networking tools
pacstrap /mnt base base-devel linux linux-firmware efibootmgr networkmanager network-manager-applet wireless_tools wpa_supplicant dialog os-prober mtools dosfstools git python
# Generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# Create a setup script to run inside the chroot environment
cat > /mnt/setup.sh <<EOF
#!/bin/bash
# Set time zone
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
hwclock --systohc
# Set locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
# Set keyboard layout
echo "KEYMAP=$keyboard_layout" > /etc/vconsole.conf
# Set hostname
echo "$hostname" > /etc/hostname
# Set root password
echo "root:$root_password" | chpasswd
# Create new user and add to sudo group
useradd -m -G wheel -s /bin/bash $username
echo "$username:$user_password" | chpasswd
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Install and configure bootloader (systemd-boot)
bootctl install
echo "default arch" > /boot/loader/loader.conf
echo "timeout 3" >> /boot/loader/loader.conf
echo "editor 0" >> /boot/loader/loader.conf
echo "title Arch Linux" > /boot/loader/entries/arch.conf
echo "linux /vmlinuz-linux" >> /boot/loader/entries/arch.conf
echo "initrd /initramfs-linux.img" >> /boot/loader/entries/arch.conf
echo "options root=PARTUUID=$(blkid -s PARTUUID -o value ${selected_drive}2) rw" >> /boot/loader/entries/arch.conf
# Enable NetworkManager
systemctl enable NetworkManager
EOF
# Make the setup script executable
chmod +x /mnt/setup.sh
# Run the setup script in the chroot environment
arch-chroot /mnt /setup.sh
# Remove the setup script
rm /mnt/setup.sh
print_message "$GREEN" "Base Arch Linux installation completed with EFI boot and networking setup."
print_message "$YELLOW" "Please reboot your system to complete the installation."
}
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored messages
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to display a colored menu
display_colored_menu() {
local prompt=$1
shift
local options=("$@")
local selected=0
tput civis # Hide cursor
while true; do
clear
print_message "$BLUE" "$prompt"
echo
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
print_message "$GREEN" "> ${options[$i]}"
else
echo " ${options[$i]}"
fi
done
read -rsn1 key
case "$key" in
A) ((selected > 0)) && ((selected--)) ;;
B) ((selected < ${#options[@]} - 1)) && ((selected++)) ;;
'') break ;;
esac
done
tput cnorm # Show cursor
return $selected
}
# Function to get available drives
get_available_drives() {
lsblk -ndo NAME,SIZE,TYPE | awk '$3=="disk" {print "/dev/"$1" ("$2")"}'
}
# Function to install base Arch Linux
install_base_arch() {
print_message "$BLUE" "Installing base Arch Linux..."
# Select installation drive
mapfile -t drives < <(get_available_drives)
drives+=("Back to main menu")
display_colored_menu "Select installation drive:" "${drives[@]}"
drive_choice=$?
if [ $drive_choice -eq ${#drives[@]}-1 ]; then
return
fi
selected_drive=$(echo "${drives[$drive_choice]}" | cut -d' ' -f1)
print_message "$BLUE" "Selected drive: $selected_drive"
# Get user input for various settings
read -p "Enter desired hostname: " hostname
read -p "Enter desired username: " username
read -s -p "Enter password for $username: " user_password
echo
read -s -p "Enter root password: " root_password
echo
# Get region/timezone
read -p "Enter your timezone (e.g., America/New_York): " timezone
# Get keyboard layout
read -p "Enter your keyboard layout (e.g., us): " keyboard_layout
# Update system clock
timedatectl set-ntp true
# Partition the disk
parted $selected_drive mklabel gpt
parted $selected_drive mkpart ESP fat32 1MiB 513MiB
parted $selected_drive set 1 esp on
parted $selected_drive mkpart primary ext4 513MiB 100%
# Format the partitions
mkfs.fat -F32 "${selected_drive}1"
mkfs.ext4 "${selected_drive}2"
# Mount the file systems
mount "${selected_drive}2" /mnt
mkdir /mnt/boot
mount "${selected_drive}1" /mnt/boot
# Install base packages and additional networking tools
pacstrap /mnt base base-devel linux linux-firmware efibootmgr networkmanager network-manager-applet wireless_tools wpa_supplicant dialog os-prober mtools dosfstools git python
# Generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# Create a setup script to run inside the chroot environment
cat > /mnt/setup.sh <<EOF
#!/bin/bash
# Set time zone
ln -sf /usr/share/zoneinfo/$timezone /etc/localtime
hwclock --systohc
# Set locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
# Set keyboard layout
echo "KEYMAP=$keyboard_layout" > /etc/vconsole.conf
# Set hostname
echo "$hostname" > /etc/hostname
# Set root password
echo "root:$root_password" | chpasswd
# Create new user and add to sudo group
useradd -m -G wheel -s /bin/bash $username
echo "$username:$user_password" | chpasswd
echo "%wheel ALL=(ALL) ALL" >> /etc/sudoers
# Install and configure bootloader (systemd-boot)
bootctl install
echo "default arch" > /boot/loader/loader.conf
echo "timeout 3" >> /boot/loader/loader.conf
echo "editor 0" >> /boot/loader/loader.conf
echo "title Arch Linux" > /boot/loader/entries/arch.conf
echo "linux /vmlinuz-linux" >> /boot/loader/entries/arch.conf
echo "initrd /initramfs-linux.img" >> /boot/loader/entries/arch.conf
echo "options root=PARTUUID=$(blkid -s PARTUUID -o value ${selected_drive}2) rw" >> /boot/loader/entries/arch.conf
# Enable NetworkManager
systemctl enable NetworkManager
EOF
# Make the setup script executable
chmod +x /mnt/setup.sh
# Run the setup script in the chroot environment
arch-chroot /mnt /setup.sh
# Remove the setup script
rm /mnt/setup.sh
print_message "$GREEN" "Base Arch Linux installation completed with EFI boot and networking setup."
print_message "$YELLOW" "Please reboot your system to complete the installation."
}
# Main menu options
main_options=(
"Install base Arch Linux"
"Exit"
)
# Main loop
while true; do
display_colored_menu "Arch Linux Installation Menu" "${main_options[@]}"
choice=$?
case $choice in
0)
install_base_arch
;;
1)
print_message "$YELLOW" "Exiting..."
exit 0
;;
esac
print_message "$YELLOW" "Press any key to continue..."
read -n 1 -s
done