-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalis.sh
272 lines (235 loc) · 7.97 KB
/
calis.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
#!/usr/bin/env bash
# Author: qaraluch - 08.2018 - MIT
# Part of the repo: arch-bootstrap
# Custom Arch Linux Installation Script (CALIS)
# Updates:
# - 2019-11-18 - UEFI device (NUC) and sydtemd-boot
set -e
########################## INSTALLATION PARAMS ##############################################################
# edit it before run!
readonly p_hostname='arch-nuc-dev'
readonly p_device='sda'
readonly p_part_boot_size='550'
readonly p_part_swap_size='8000'
readonly p_part_root_size='20000'
readonly p_chroot_source='https://raw.githubusercontent.com/qaraluch/arch-bootstrap/master/calis-chroot.sh'
readonly p_exec_part_mgmt='Y'
readonly p_exec_install_arch='Y'
readonly p_exec_down_chroot='Y'
readonly p_exec_chroot='Y'
#############################################################################################################
main() {
welcomeMsg
_switchYN $p_exec_part_mgmt && execPartitionMgmt
_switchYN $p_exec_part_mgmt || _echoIt "${_pDel}" "Skipped set up of partitions" "$_ic"
_switchYN $p_exec_install_arch && execInstallArch
_switchYN $p_exec_install_arch || _echoIt "${_pDel}" "Skipped installation of Arch Linux" "$_ic"
_switchYN $p_exec_down_chroot && execDownloadChroot
_switchYN $p_exec_down_chroot || _echoIt "${_pDel}" "Skipped downloading of chroot script" "$_ic"
_switchYN $p_exec_chroot && execChrootWelcomeMsg
_switchYN $p_exec_chroot && execChroot
_switchYN $p_exec_chroot || _echoIt "${_pDel}" "Skipped run of chroot script" "$_ic"
_echoIt "${_pDel}" "ALL DONE!" "$_it"
execReboot
}
# Calculated vars
readonly device_full="/dev/${p_device}"
readonly part_swap_size_relative=$(( $p_part_swap_size + $p_part_boot_size))
readonly part_root_size_relative=$(( $p_part_root_size + $part_swap_size_relative))
readonly part_boot="${device_full}1"
readonly part_swap="${device_full}2"
readonly part_root="${device_full}3"
readonly part_home="${device_full}4"
welcomeMsg() {
_echoIt "${_pDel}" "Welcome to: Custom Arch Linux Installation Script (CALIS)"
_echoIt "${_pDel}" "Used variables:"
_echoIt "${_pDel}" " - hostname: $p_hostname"
_echoIt "${_pDel}" " - device: $p_device"
_echoIt "${_pDel}" " - 1. BOOT (MB): $p_part_boot_size"
_echoIt "${_pDel}" " - 2. SWAP (MB): $p_part_swap_size"
_echoIt "${_pDel}" " - 3. ROOT (MB): $p_part_root_size"
_echoIt "${_pDel}" " - 4. HOME (MB): <the rest of the disk size>"
_echoIt "${_pDel}" " - chroot source: $p_chroot_source"
_echoIt "${_pDel}" "Execution subscript flags:"
_echoIt "${_pDel}" " - run partition management [Y]es/[N]o: $p_exec_part_mgmt"
_echoIt "${_pDel}" " - run arch installation [Y]es/[N]o: $p_exec_install_arch"
_echoIt "${_pDel}" " - download chroot script [Y]es/[N]o: $p_exec_down_chroot"
_echoIt "${_pDel}" " - run chroot script [Y]es/[N]o: $p_exec_chroot"
_echoIt "${_pDel}" "Check above installation settings." "$_iw"
_yesConfirmOrAbort "Ready to roll"
}
execPartitionMgmt() {
updateSystemClock
createPartitions
showPartitionLayout
formatPartitionsAndMount
_echoIt "${_pDel}" "Partitions are set up."
}
updateSystemClock() {
timedatectl set-ntp true
_echoIt "${_pDel}" "Updated system clock." "$_it"
}
createPartitions() {
_echoIt "${_pDel}" "About to create partitions..."
parted --script "${device_full}" -- mklabel gpt \
mkpart primary fat32 1Mib "${p_part_boot_size}MiB" \
set 1 esp on \
mkpart primary linux-swap "${p_part_boot_size}MiB" "${part_swap_size_relative}MiB" \
mkpart primary ext4 "${part_swap_size_relative}MiB" "${part_root_size_relative}MiB" \
mkpart primary ext4 "${part_root_size_relative}MiB" 100%
}
showPartitionLayout() {
parted --script "${device_full}" -- print
_echoIt "${_pDel}" "Created partitions." "$_it"
_yesConfirmOrAbort
}
formatPartitionsAndMount() {
_echoIt "${_pDel}" "About to wipe data..."
wipefs "${part_boot}"
wipefs "${part_swap}"
wipefs "${part_root}"
wipefs "${part_home}"
_echoIt "${_pDel}" "About to format partitions..."
mkfs.vfat -F32 ${part_boot}
mkfs.ext4 ${part_root}
mkfs.ext4 ${part_home}
mkswap ${part_swap}
_echoIt "${_pDel}" "Formated partitions." "$_it"
swapon ${part_swap}
mount ${part_root} /mnt
mkdir -p /mnt/boot
mount ${part_boot} /mnt/boot
mkdir -p /mnt/home
mount ${part_home} /mnt/home
_echoIt "${_pDel}" "Mounted partitions." "$_it"
}
execInstallArch() {
_echoIt "${_pDel}" "About to install Arch Linux."
_pressAnyKey
installArch
generateFstabFile
setupHostName
}
installArch() {
pacstrap /mnt base base-devel intel-ucode linux linux-firmware neovim man-pages
_echoIt "${_pDel}" "Installed Arch." "$_it"
}
generateFstabFile() {
genfstab -U /mnt >> /mnt/etc/fstab
_echoIt "${_pDel}" "Generated fstab file." "$_it"
_echoIt "${_pDel}" "See fstab file:"
more /mnt/etc/fstab
_yesConfirmOrAbort
}
setupHostName() {
echo $p_hostname > /mnt/etc/hostname
cat <<EOT >> /mnt/etc/hosts
127.0.0.1 localhost
::1 localhost
# 127.0.1.1 myhostname.localdomain myhostname
EOT
# sed -i "8i 127.0.1.1\t$p_hostname.localdomain\t$p_hostname" /etc/hosts
_echoIt "${_pDel}" "Setup hostname." "$_it"
}
execDownloadChroot() {
_echoIt "${_pDel}" "About to download calis-chroot.sh script..."
downloadChrootScript
}
downloadChrootScript() {
curl -sL "${p_chroot_source}" > /mnt/chroot.sh
_echoIt "${_pDel}" "Download completed!" "$_it"
}
execChrootWelcomeMsg() {
_echoIt "${_pDel}" "Chroot script is downloaded." "$_it"
_echoIt "${_pDel}" "If you need edit some of this settings:"
_echoIt "${_pDel}" " - locale"
_echoIt "${_pDel}" " - timezone"
_echoIt "${_pDel}" " - keyboard"
_echoIt "${_pDel}" " - bootloader"
_echoIt "${_pDel}" " - network manager"
_echoIt "${_pDel}" "Abort this script and edit file /mnt/chroot.sh"
_echoIt "${_pDel}" "Re-run only execution of chroot of CALIS script afterwords."
_yesConfirmOrAbort "Ready to roll"
}
execChroot() {
_echoIt "${_pDel}" "Run arch-chroot..."
runChroot
}
runChroot() {
arch-chroot /mnt /bin/bash chroot.sh && rm /mnt/chroot.sh
_echoIt "${_pDel}" "Chroot script ended. Clean it up too." "$_it"
}
execReboot() {
_echoIt "${_pDel}" "We are ready to reboot to brand new Arch Linux System..."
_echoIt "${_pDel}" "Fingers crossed!"
rebootNow
orGoBackToChroot
}
rebootNow() {
read -p "$D_APP$_ia Confirm reboot or skip it [y/n]?" -n 1 -r
echo >&2
if [[ $REPLY =~ ^[Yy]$ ]]
then
umount -R /mnt
swapoff ${part_swap}
reboot
# shutdown -h now
fi
}
orGoBackToChroot() {
read -p "$D_APP$_ia Maybe go to chroot again or skip it [y/n]?" -n 1 -r
echo >&2
if [[ $REPLY =~ ^[Yy]$ ]]
then
arch-chroot /mnt
fi
clear
_echoIt "${_pDel}" "Nothing more to do... :("
}
# Utils
readonly _pDel='[ CALIS ]'
export _cr=$'\033[0;31m' # color red
export _cg=$'\033[1;32m' # color green
export _cy=$'\033[1;33m' # color yellow
export _cb=$'\033[1;34m' # color blue
export _cm=$'\033[1;35m' # color magenta
export _cc=$'\033[1;36m' # color cyan
export _ce=$'\033[0m' # color end
export _it="[ ${_cg}✔${_ce} ]" # icon tick
export _iw="[ ${_cy}!${_ce} ]" # icon warn
export _ic="[ ${_cr}✖${_ce} ]" # icon cross
export _ia="[ ${_cy}?${_ce} ]" # icon ask
_echoIt() {
local delimiter=$1 ; local msg=$2 ; local icon=${3:-''} ; echo "${delimiter}${icon} $msg" >&2
}
_errorExit() {
local delimiter=$1 ; local msg=$2 ; local icon=${3:-"$_ic"} ; echo "${delimiter}${icon} ${msg}" 1>&2 ; exit 1
}
_yesConfirmOrAbort() {
local msg=${1:-'Continue'}
local msgDefaultAbort=${2:-'Abort script!'}
read -n 1 -s -r -p "${_pDel}${_ia} ${msg} [Y/n]?"
echo >&2
REPLY=${REPLY:-'Y'}
if [[ ! $REPLY =~ ^[Yy]$ ]] ; then
_errorExit "${_pDel}" "${msgDefaultAbort}"
fi
}
_pressAnyKey() {
read -n 1 -s -r -p "${_pDel}${_ia} Press [any] key to continue. "
echo >&2
}
_isStringEqualY() {
local string=$1
[[ "$string" == "Y" ]]
}
_switchYN() {
local switch=$1
if _isStringEqualY $switch; then
return 0
else
return 1
fi
}
# Main run!
main