-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
189 lines (166 loc) · 4.05 KB
/
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
DISK='/dev/sda'
# System configuration variables
TIMEZONE='America/Sao_Paulo'
LOCALE='en_US.UTF-8 UTF-8\npt_BR.UTF-8 UTF-8'
USERNAME=$2
PASSWORD=$3
HOSTNAME=$4
BOOT_SIZE=256
is_efi() {
[ -d '/sys/firmware/efi/efivars' ]
}
user_configurations() {
echo "Choose your user name"
read USERNAME
echo "Set your root password"
read -s PASSWORD
echo "Please, confirm the root password"
read -s PASSWORD_CONFIRMATION
while [ $PASSWORD != $PASSWORD_CONFIRMATION ]
do
echo "Error: The password does not match!"
echo "Please: try again:"
read -s PASSWORD
echo "Please, confirm the root password:"
read -s PASSWORD_CONFIRMATION
done
echo "Set your hostname:"
read HOSTNAME
echo "Listing disks"
parted -l
echo "Choose your device to format: (Default device $DISK)"
read CHOSEN_DEVICE
if [ -z $CHOSEN_DEVICE ]
then
echo "We will use the default then"
else
$DISK = "/dev/$CHOSEN_DEVICE"
fi
}
config_partitions() {
local memory=$(vmstat -s -S M | grep 'total memory' | tr -dc '0-9')
local memory_addr=$(($memory + $BOOT_SIZE))M
echo "Formatting disk"
if is_efi
then
parted -s "$DISK" \
mklabel gpt \
mkpart primary fat32 1 "$BOOT_SIZE"M \
mkpart primary ext4 $memory_addr 100% \
mkpart primary linux-swap "$BOOT_SIZE"M $memory_addr \
set 1 esp on \
set 2 LVM on \
set 3 LVM on
else
parted -s "$DISK" \
mklabel msdos \
mkpart primary ext2 1 "$BOOT_SIZE"M \
mkpart primary ext4 $memory_addr 100% \
mkpart primary linux-swap "$BOOT_SIZE"M $memory_addr \
set 1 bios_grub on \
set 2 LVM on \
set 3 LVM on
fi
}
format_disk() {
local boot_dev="$DISK"1
local lvm_dev="$DISK"2
local swap_dev="$DISK"3
config_partitions
is_efi && mkfs.fat -F32 "$boot_dev" || mkfs.ext2 -L boot "$boot_dev"
mkfs.ext4 -L root "$lvm_dev"
mkswap $swap_dev
swapon $swap_dev
mount $lvm_dev /mnt
mkdir /mnt/boot
mount $boot_dev /mnt/boot
}
install_base() {
pacstrap /mnt base base-devel linux linux-firmware
}
config_locale() {
printf $LOCALE >> /etc/locale.gen
locale-gen
cat > /etc/locale.conf <<EOF
LANG=en_US.UTF-8
EOF
}
set_hostname() {
cat > /etc/hosts <<EOF
127.0.0.1 localhost
::1 localhost
127.0.1.1 $HOSTNAME.localdomain $HOSTNAME
EOF
hostnamectl set-hostname $HOSTNAME
}
create_user() {
echo "Creating user"
groupadd sudo
useradd -m -s /bin/zsh -G root,sudo "$USERNAME"
echo -en "$PASSWORD\n$PASSWORD" | passwd "$USERNAME"
echo "%sudo ALL=(ALL) ALL" >> /etc/sudoers
echo "# Config your zshrc file" >> /home/"$USERNAME"/.zshrc
}
install_tools() {
local tools='zsh wget htop wpa_supplicant'
yes | pacman -S $tools
}
config_system() {
echo "Start system configurations"
mv /etc/localtime /etc/localtime_original
ln -sT "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
hwclock --systohc
config_locale
set_hostname
echo -en "$PASSWORD\n$PASSWORD" | passwd
create_user
install_tools
}
install_grub() {
yes | pacman -S grub
if is_efi
then
yes | pacman -S efibootmgr
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=arch
mkdir /boot/EFI/boot
cp /boot/EFI/arch/grubx64.efi /boot/EFI/boot/bootx64.efi
else
grub-install --target=i386-pc $DISK
fi
grub-mkconfig -o /boot/grub/grub.cfg
}
install_i3() {
echo "Installing i3 and dependencies"
cd "/home/$USERNAME"
sudo -u $USERNAME wget "https://raw.githubusercontent.com/Julianobsg/arch-config/master/i3_install.sh"
chmod +x i3_install.sh
echo $PASSWORD | sudo -Su $USERNAME ./i3_install.sh
}
finish_installation() {
install_grub
rm /install.sh
exit
umount /mnt/boot
umount /mnt
echo "Config finished, please boot your system."
}
install_arch() {
if [ -z "$USERNAME" ]
then
user_configurations
fi
if [ "$1" == "config" ]
then
config_system
install_i3
finish_installation
else
format_disk
install_base
genfstab -U /mnt >> /mnt/etc/fstab
cp $0 /mnt/install.sh
arch-chroot /mnt ./install.sh config $USERNAME $PASSWORD $HOSTNAME
fi
}
install_arch $1 $2 $3 $4