forked from pi3rrot/blackarch-install-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchroot-install
executable file
·497 lines (379 loc) · 10.6 KB
/
chroot-install
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
#!/bin/bash
################################################################################
# #
# blackarchinstall - Blackarch Install #
# #
# FILE #
# chroot-install #
# #
# DATE #
# 2013-12-16 #
# #
# DESCRIPTION #
# Script for easy install #
# #
# AUTHOR #
# #
# CONTRIBUTORS #
# #
################################################################################
# true / false
FALSE="0"
TRUE="1"
# return codes
SUCCESS=1337
FAILURE=31337
# verbose mode - default: quiet
VERBOSE="/dev/null"
# blackarch-install version
VERSION="v0.7.8"
# colors
WHITE="$(tput bold ; tput setaf 7)"
GREEN="$(tput setaf 2)"
RED="$(tput bold; tput setaf 1)"
YELLOW="$(tput bold ; tput setaf 3)"
NC="$(tput sgr0)" # No Color
# BA REPO DEFAULT
BLACKARCH_REPO_URL='http://www.blackarch.org/blackarch/$repo/os/$arch'
# luks global variable
LUKS="false"
# printf white
wprintf()
{
fmt="${1}"
shift
printf "%s${fmt}%s\n" "${WHITE}" "$@" "${NC}"
return $SUCCESS
}
# print warning
warn()
{
fmt="${1}"
shift
printf "%s[!] WARNING: ${fmt}%s\n" "${RED}" "${@}" "${NC}"
return $SUCCESS
}
# print error and exit
err()
{
fmt="${1}"
shift
printf "%s[-] ERROR: ${fmt}%s\n" "${RED}" "${@}" "${NC}"
return $FAILURE
}
# print error and exit
cri()
{
fmt=${1}
shift
printf "%s[-] CRITICAL: ${fmt}%s\n" "${RED}" "${@}" "${NC}"
exit $FAILURE
}
# leet banner, very important
banner()
{
printf "%s--==[ blackarch-install %s ]==--%s\n" \
"${YELLOW}" "${VERSION}" "${NC}"
return $SUCCESS
}
# print banner + head
header()
{
head="${@}"
clear
printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
banner
printf '%*s\n\n\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
wprintf ">> %s\n\n" "${head}"
return $SUCCESS
}
# usage and help
usage()
{
cat << EOF
usage: $0 <arg> | <misc>
options:
-l: live-iso install
-r: repository install
-b: blackman install
-d: device target [/dev/sda]
misc:
-V: print version and exit
-H: print help and exit
EOF
exit $SUCCESS
}
# check environment
check_env()
{
if [ -f /var/lib/pacman/db.lck ]
then
cri "pacman locked - rm /var/lib/pacman/db.lck"
fi
}
# select blackarch repository
select_ba_repo()
{
mirror_file="/tmp/mirror.lst"
github_url="https://github.com/BlackArch/blackarch/raw/master/mirror/mirror.lst"
wprintf "[*] fetching mirror list"
# check if wget installed
command -v wget >/dev/null 2>&1 || pacman -S wget --noconfirm
wget -q "${github_url}" -O "${mirror_file}"
if [ "${?}" != "0" ]
then
err "wget failed - setting BlackArch repository"
return $FAILURE
fi
count="1"
local IFS='|'
( while read -r country url mirror_name; do
wprintf " %s. %s - %s" "${count}" "${country}" "${mirror_name}"
wprintf " * %s" "${url}"
((count++))
done < "${mirror_file}" )
printf "%s[?] select mirror number: " "${WHITE}"; read a
if [ "${a}" -gt "$(wc -l < ${mirror_file})" ]
then
# BLACKARCH_REPO_URL gets the default one - choose better next time ;)
wprintf "[*] you fucked up man - we select BlackArch for you..."
else
BLACKARCH_REPO_URL=$(sed -n "${a}p" "${mirror_file}"|cut -d"|" -f2)
wprintf " -> mirror from '%s' selected" \
"$(sed -n "${a}p" "${mirror_file}"|cut -d"|" -f3)"
fi
# cleaning up
rm -rf "${mirror_file}"
return $SUCCESS
}
# update the system
update_system()
{
wprintf "[*] adding BlackArch repository"
select_ba_repo
if [ "${?}" = "$FAILURE" ]
then
warn "mirror selection failed - we go with default one"
fi
curl -s http://blackarch.org/strap.sh | sh
if ! grep -q "blackarch" /etc/pacman.conf
then
printf '[blackarch]\nServer = %s\n' "${BLACKARCH_REPO_URL}" \
>> /etc/pacman.conf
else
sed -i "/\[blackarch\]/{ n;s?Server.*?Server = ${BLACKARCH_REPO_URL}?; }" /etc/pacman.conf
fi
pacman -Syyu --noconfirm
return $SUCCESS
}
# testing
install_packages_blackman()
{
command -v git >/dev/null 2>&1 || pacman -S git --noconfirm
cd /usr/share/
git clone https://github.com/nrzizrn/blackman
ln -s /usr/share/blackman/blackman /usr/bin
blackman -a
return $SUCCESS
}
# install blackarch packages
install_packages_repo()
{
# repo
pacman -S blackarch
# X11 related, wms, configs
pacman -S blackarch-config-awesome blackarch-config-fluxbox \
blackarch-config-lxdm blackarch-config-openbox fluxbox openbox awesome \
spectrwm blackarch-dwm i3-wm wmii
return $SUCCESS
}
# install grub bootloader
install_grub()
{
pacman -S grub --noconfirm --needed
mv /boot/splash.png /boot/grub/
sed -i 's/Arch Linux/BlackArch Linux/' /boot/grub/grub.cfg
printf 'GRUB_BACKGROUND="/boot/grub/splash.png"\n' >> /etc/default/grub
if [ "${LUKS}" == "true" ]
then
sed -i "s|quiet|cryptdevice=${ROOT_PART}:cryptroot root=/dev/mapper/cryptroot|" /etc/default/grub
sed -i 's|"Arch"|"BlackArch"|' /etc/default/grub
#sed -i "s|rw quiet|rw cryptdevice=${ROOT_PART}:cryptroot|" \
# /boot/grub/grub.cfg
fi
grub-install --target=i386-pc "${HD}"
grub-mkconfig -o /boot/grub/grub.cfg
return $SUCCESS
}
# set passwd check
set_passwd()
{
user="${1}"
if [ -n "${user}" ]
then
passwd "${user}"
else
passwd
fi
if [ "${?}" != "0" ]
then
wprintf "wrong passwd - please try again"
set_passwd "${user}"
else
return $SUCCESS
fi
return $SUCCESS
}
# add and configure users
configure_users()
{
printf "%s" "${WHITE}"
printf "[*] setting up root password\n"
set_passwd
mv /mnt/shell/root/.bashrc /root/
cp /root/.bashrc /root/.bash_profile
printf "[?] setup a normal user account [y/N]: "; read a
if [ "${a}" == "y" ] || [ "${a}" == "Y" ]
then
printf "[?] user name: "; read user
useradd -m -p "" -g users \
-G "adm,audio,floppy,log,network,rfkill,scanner,storage,optical,power,wheel" \
-s /bin/bash "${user}" && printf "[*] user '%s' created\n" "${user}"
set_passwd "${user}"
mv /mnt/shell/user/.bashrc "/home/${user}/"
cp "/home/${user}/.bashrc" "/home/${user}/.bash_profile"
chown -R "${user}:users" "/home/${user}"
fi
# cleaning up
rm -rf /tmp/shell
printf "%s" "${NC}"
return $SUCCESS
}
# not used atm
generate_initramfs()
{
sed -i 's/block filesystems/block encrypt filesystems/' /etc/mkinitcpio.conf
mkinitcpio -p linux
return $SUCCESS
}
# set system hostname
set_hostname()
{
printf "%s" "${WHITE}"
printf "[?] set hostname [blackarch]: "
read hostname
if [ "${hostname}" == "" ]
then
hostname="blackarch"
fi
printf "%s\n" "${hostname}" > /etc/hostname
printf "%s" "${NC}"
return $SUCCESS
}
# configure X related things
#configure_X()
#{
# enable display manager
#systemctl enable lxdm
# WMs
#cp -r /usr/share/fluxbox-blackarch/* /usr/share/fluxbox
#cp /etc/xdg/awesome/rc.lua.blackarch /etc/xdg/awesome/rc.lua
#cp -r /etc/xdg/openbox-blackarch/* /etc/xdg/openbox
#cp /usr/share/themes/blackarch/openbox-3-blackarch/* \
# /usr/share/themes/blackarch/openbox-3
#return $SUCCESS
#}
# install the system
install()
{
menu_opt=${1}
header "package installation"
case "${menu_opt}" in
"live")
header "system update"
update_system
;;
"repository")
header "system update"
update_system
install_packages_repo
;;
"blackman")
install_packages_blackman
;;
esac
header "user configuration"
configure_users
header "initramfs"
"${LUKS}" && generate_initramfs
header "hostname setup"
set_hostname
# set keymaps choosed before silently
printf "KEYMAP=%s\n" "${KEYMAPS}" > /etc/vconsole.conf
#header "X configuration"
#configure_X
header "grub installation"
install_grub
# sync hd
sync
printf "%s[*] BlackArch Linux ready! Enjoy!%s\n" "${RED}" "${NC}"
return $SUCCESS
}
# parse command line options
get_opts()
{
while getopts lrbD:R:Lk:vVH flags
do
case "${flags}" in
l)
opt_arg="live"
;;
r)
opt_arg="repository"
;;
b)
opt_arg="blackman"
;;
D)
HD=${OPTARG}
;;
R)
ROOT_PART=${OPTARG}
;;
L)
LUKS="true"
;;
k)
KEYMAPS=${OPTARG}
;;
v)
VERBOSE="/dev/stdout"
;;
V)
printf "%s\n" "${VERSION}"
exit $SUCCESS
;;
H)
usage
;;
*)
err "WTF?! mount /dev/brain"
;;
esac
done
return $SUCCESS
}
# controller and program flow
main()
{
get_opts "${@}"
check_env
install "${opt_arg}"
return $SUCCESS
}
# program start
main "${@}"
# EOF