-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patharch.sh
More file actions
268 lines (195 loc) · 5.21 KB
/
arch.sh
File metadata and controls
268 lines (195 loc) · 5.21 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
T_COLS=$(tput cols)
T_ROWS=$(tput lines)
LANG=en_US.UTF-8
FONT=ter-122n
HOSTNAME=blusamurai
DOMAIN_NAME=densetsu
ZONEINFO="Asia/Kolkata"
PACMAN_CONF=/etc/pacman.conf
PART_CRYPT=/dev/sda1
PART_EFI=/dev/sda2
VG_ROOT=/dev/vg/root
VG_HOME=/dev/vg/home
VG_SWAP=/dev/vg/swap
CRYPTLVM=cryptlvm
DEV_CRYPT=/dev/mapper/cryptlvm
error() {
echo ${RED}"Error: $@"${RESET} >&2
}
# Source: https://github.com/robbyrussell/oh-my-zsh/blob/master/tools/install.sh
setup_color() {
# Only use colors if connected to a terminal
if [ -t 1 ]; then
RED=$(printf '\033[31m')
GREEN=$(printf '\033[32m')
YELLOW=$(printf '\033[33m')
BLUE=$(printf '\033[34m')
BOLD=$(printf '\033[1m')
RESET=$(printf '\033[m')
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
}
function cmd_nostdout() {
for i in "$@"
do
printf "${i} ... "
if $i >/dev/null; then
echo "${GREEN}OK${RESET}"
else
echo "${RED}FAILED${RESET}"
fi
done
}
function cmd_abort_nostd(){
for i in "$@"
do
printf "${i} ... "
if $i >/dev/null; then
echo "${GREEN}OK${RESET}"
else
echo "${RED}FAILED${RESET}"
echo "${RED} Aborting Script"
return 1
fi
done
return 0
}
function cmd()
{
for i in "$@"
do
if $i; then
echo "${GREEN}OK${RESET}"
else
echo "${RED}FAILED${RESET}"
return 1
fi
done
}
function cmd_abort(){
for i in "$@"
do
if $i; then
echo "${GREEN}OK${RESET}"
else
echo "${RED}FAILED${RESET}"
echo "${RED} Aborting Script"
return 1
fi
done
return 0
}
function exit_s(){
echo "${RED} Exiting Script ${RESET}"
cmd_nostdout "umount -R /mnt"
cmd_nostdout "vgchange -a n vg"
cmd_nostdout "cryptsetup close ${CRYPTLVM}"
exit 1
}
function setup_arch() {
# Set Time Synchronisation
echo "Setting NetworkTime Syncronization .......... "
cmd_nostdout "timedatectl set-ntp true"
echo
# FIx the timeou error when connected to college internet.
fix_dwd_limit="sed /\[options\]/aDisableDownloadTimeout ${PACMAN_CONF} -i.backup"
echo "Disabling Download Limit from pacman.(Fix for college wifi) ...... "
cmd_nostdout "$fix_dwd_limit"
echo
# Update Pacman Databse and FONT change
echo "${BLUE}Updating pacman databases ....... ${RESET}"
if cmd "pacman -Sy terminus-font" ; then
setfont $FONT
else
echo "${YELLOW}Check Internet and Mirrors.${RESET}"
exit_s
fi
echo
echo "${BOLD}[ Preparing FileSystem ] ${RESET}"
echo "Opening CryptLVM Container :-"
if ! cmd "cryptsetup open ${PART_CRYPT} ${CRYPTLVM}"; then
echo "${RED}Could'nt open Crypt container.${RESET}"
exit_s
fi
echo "Activating LVM Containers"
cmd_nostdout "vgchange -ay"
#HOTFIX for a random bug where volume group does'nt show even though it is activated
lsblk &>/dev/null
echo
echo "Formating Partitions :-"
format_exec=(
"mkfs.ext4 ${VG_ROOT}"
"mkfs.ext4 ${VG_HOME}"
"mkswap ${VG_SWAP}"
"mkfs.fat -F32 ${PART_EFI}"
)
cmd_nostdout "${format_exec[@]}"
echo
echo "Mounting Partitions :-"
mount_exec=(
"mount ${VG_ROOT} /mnt"
"mkdir -p /mnt/home"
"mkdir -p /mnt/efi"
"mount ${VG_HOME} /mnt/home"
"mount ${PART_EFI} /mnt/efi"
)
if ! cmd_abort_nostd "${mount_exec[@]}"; then
echo "${RED}Failed to mount partitions. Exiting Script ${RESET}"
exit_s
fi
echo
echo "${BOLD}[ Pacstrap /mnt ] ${RESET}"
pacstrap_exec="pacstrap /mnt \
base base-devel \
grub efibootmgr intel-ucode \
zsh git go vim wget \
terminus-font \
networkmanager \
python python-requests \
"
if ! cmd "$pacstrap_exec"; then
echo "${RED}FAILED to install arch in /mnt.${RESET}"
exit_s
fi
echo
echo
# echo "${BOLD} [CHROOTING INTO /mnt] ${RESET}"
# if ! cmd_abort "arch-chroot /mnt"; then
# exit_s
# fi
# echo "Setting console font ....."
# cmd_abort_nostd "echo 'FONT=ter-122n' > /etc/vconsole.conf"
# echo
# echo "Setting Time :-"
# time_exec=(
# "ln -sf /usr/share/zoneinfo/${ZONEINFO} /etc/localtime"
# "mkdir /mnt/home"
# )
# cmd_nostdout "${time_exec[@]}"
# echo
# echo "Setting Locale :-"
# locale_exec=(
# "echo "en_US.UTF-8 UTF-8" > /etc/locale.gen"
# "locale-gen"
# "echo "LANG=${LANG}" > /etc/locale.conf"
# "export $LANG"
# )
# cmd_abort_nostd "${locale_exec[@]}"
# echo
# echo "Setting Hostname:-"
# cmd_abort_nostd "echo '${hostname}' > /etc/hostname"
# cmd_abort_nostd "echo '127.0.0.1 localhost \\n::1 localhost \\n127.0.1.1 blusamurai.densetsu blusamurai' >> /etc/hosts"
# cmd_abort_nostd "dbus-uuidgen --ensure"
}
setup_color
setup_arch
LANG=en_US.UTF-8
FONT=ter-122n
LANG=en_US.UTF-8
FONT=ter-122n