-
Notifications
You must be signed in to change notification settings - Fork 15
/
blackarch-install
executable file
·600 lines (484 loc) · 15.7 KB
/
blackarch-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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
#!/bin/bash
################################################################################
# #
# blackarchinstall - Blackarch Install #
# #
# FILE #
# blackarchinstall.sh #
# #
# DATE #
# 2013-12-16 #
# #
# DESCRIPTION #
# Script for easy install #
# #
# AUTHOR #
# #
################################################################################
# SECURITY VAR - this version can rm -rf /* your hard drive
SEC_ENABLE="false"
# root variable
ROOT="/mnt/blackarch"
# Defaults Partitioning
HD="/dev/sda"
boot_part="${HD}"
boot_type="ext2"
boot_size="100MB"
root_part="${HD}"
root_type="ext4"
root_size="10GB"
swap_part="${HD}"
swap_size="1024MB"
# Partition CONST
PART_AUTO="1"
PART_MANUAL="2"
# Menu CONST
MENU_LIVE="1"
MENU_REPO="2"
MENU_BLACKMAN="3"
# blackarchinstall version
VERSION="v0.6.3beta1"
# true / false
FALSE="0"
TRUE="1"
# return codes
SUCCESS="1337"
FAILURE="31337"
# verbose mode - default: quiet
VERBOSE="/dev/null"
# 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
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}"
}
# usage and help
usage()
{
cat <<EOF
Usage: $0 <arg> | <misc>
MISC:
-V: print version and exit
-H: print help and exit
EOF
return "${SUCCESS}"
}
# leet banner, very important
banner()
{
printf "%s--==[ BlackArch Install %s ]==--%s\n" "${YELLOW}" "${VERSION}" "${NC}"
return "${SUCCESS}"
}
check_env()
{
if [ -f /var/lib/pacman/db.lck ]; then
cri "Pacman locked - rm /var/lib/pacman/db.lck"
fi
}
# check argument count
check_argc()
{
return "${SUCCESS}"
}
# check if required arguments were selected
check_args()
{
return "${SUCCESS}"
}
update_system()
{
if [ "$(uname -m)" == "x86_64" ]; then
if grep -q "#\[multilib\]" /etc/pacman.conf; then
# it exist but commented
wprintf "[+] Uncommenting multilib in /etc/pacman.conf..."
sed -i '/\[multilib\]/{ s/^#//; n; s/^#//; }' /etc/pacman.conf
elif ! grep -q "\[multilib\]" /etc/pacman.conf; then
# it does not exist at all
wprintf "[+] Enabling multilib in /etc/pacman.conf..."
printf "[multilib]\nInclude = /etc/pacman.d/mirrorlist\n" >> /etc/pacman.conf
fi
fi
if [ -n "${LIVE}" ]; then
wget http://blackarch.org/blackarch/blackarch/os/x86_64/blackarch-keyring-20140118-3-any.pkg.tar.xz{,.sig}
gpg --keyserver hkp://pgp.mit.edu --recv-keys '4345771566D76038C7FEB43863EC0ADBEA87E4E3'
gpg --with-fingerprint --verify blackarch-keyring-20140118-3-any.pkg.tar.xz.sig
rm blackarch-keyring-20140118-3-any.pkg.tar.xz.sig
pacman-key --init
pacman -U blackarch-keyring-20140118-3-any.pkg.tar.xz --noconfirm
fi
pacman -Syy --noconfirm "${LIVE+-u}"
return "${SUCCESS}"
}
# auto mode
setup_partition_values()
{
part_opt=${1}
# * BOOT
printf "[+] Select partition size for /boot [%s]: " "${boot_size}"
read a; [ "${a}" != "" ] && boot_size=${a}
# * ROOT
# Manual && Automatic
printf "[+] Select partition size for / [%s]: " "${root_size}"
read a; [ "${a}" != "" ] && root_size=${a}
# * Swap
printf "[+] Select partition size for swap [%s] : " "${swap_size}"
read a; [ "${a}" != "" ] && swap_size=${a}
return "${SUCCESS}"
}
check_parted_status()
{
[ ${?} != "0" ] && cri "Something wrong with parted - If you plan to run install script again, delete first all partitions created before error"
return "${SUCCESS}"
}
check_mkfs_status()
{
[ ${?} != "0" ] && cri "Something wrong with mkfs"
return "${SUCCESS}"
}
# auto mode
format_filesystem()
{
# about to format
printf "%s" "${RED}"
printf "\n[!!] About to create and format partitions:\n"
printf " -> /boot %s - Size: %s\n" "${boot_part}" "${boot_size}"
printf " -> Swap %s - Size: %s\n" "${swap_part}" "${swap_size}"
printf " -> / %s - Size: %s\n" "${root_part}" "${root_size}"
printf "Are you sure? [y/N]: "; read a
[ "${a}" == "y" ] || [ "${a}" == "Y" ] && printf " - R3ally? ;) \n[y/N]: "; read a
printf "%s" "${WHITE}"
if [ "${a}" == "y" ] || [ "${a}" == "Y" ]; then
# check if Partition Table already set
# parted "/dev/${HD}" print | grep -q "Partition Table"
parted -s "${HD}" mklabel msdos
check_parted_status
(echo n; echo p; echo 1; echo ; echo +${boot_size}; echo w; echo q) | fdisk ${HD}
check_parted_status
# partition bootable
parted "${boot_part}" set 1 boot on
check_parted_status
(echo n; echo p; echo 2; echo ; echo +${swap_size}; echo w; echo q) | fdisk ${HD}
check_parted_status
(echo n; echo p; echo 3; echo ; echo +${root_size}; echo w; echo q) | fdisk ${HD}
check_parted_status
boot_part="${boot_part}1"
swap_part="${swap_part}2"
root_part="${root_part}3"
"mkfs.${boot_type}" -L boot "${boot_part}"; check_mkfs_status
printf "[+] Created boot partition: %s - ext2\n" "${boot_part}"
if [ $LUKS == "YES" ]; then
#Format and encrypt ROOT partition
printf "[+] Formatting ROOT partiton, please type your passphrase for encryption : \n"
cryptsetup -y -v luksFormat "${root_part}"
printf "[+] Openning encrypted partition, re-enter your passphrase : \n"
cryptsetup open "${root_part}" cryptroot
"mkfs.${root_type}" -L root "/dev/mapper/cryptroot"; check_mkfs_status
printf "[+] Created root encrypted partition: /dev/mapper/cryptroot - ext4\n"
else
"mkfs.${root_type}" -L root "${root_part}"; check_mkfs_status
printf "[+] Created root partition: %s - ext4\n" "${root_part}"
fi
/usr/bin/mkswap ${swap_part}; check_mkfs_status
printf "[+] Created Swap partition: %s - SWAP\n" "${swap_part}"
else
# go back to setup up filesystem
setup_filesystem
return "${SUCCESS}"
fi
return "${SUCCESS}"
}
# manual mode
manual_partition()
{
# manual defaults
boot_part="${HD}1"
swap_part="${HD}2"
root_part="${HD}3"
printf "[+] Create new partitions with cfdisk [only boot and root]\n"
sleep 2
cfdisk "${HD}"
printf " -> Number of the Boot partition created [1]: "
read a; [ "${a}" != "" ] && boot_part="${HD}${a}"
printf " -> Type of Boot partition [ext2]: "
read a; [ "${a}" != "" ] && boot_type="${a}"
printf " -> Number of the Swap partition created [2]:"
read a; [ "${a}" != "" ] && swap_part="${a}"
printf " -> Number of the Root partition created [3]: "
read a; [ "${a}" != "" ] && root_part="${HD}${a}"
printf " -> Type of Root partition [ext4]: "
read a; [ "${a}" != "" ] && boot_type="${a}"
# about to format
printf "%s" "${RED}"
printf "\n[!!] About to create and format partitions:\n"
printf " -> /boot %s with type %s\n" "${boot_part}" "${boot_type}"i
printf " -> Swap %s with type Swap\n" "${swap_part}"
printf " -> / %s with type %s\n" "${root_part}" "${root_type}"
printf "Are you sure? [y/N]: "; read a
[ "${a}" == "y" ] || [ "${a}" == "Y" ] && printf " - R3ally? ;) \n[y/N]: "; read a
printf "%s" "${WHITE}"
if [ "${a}" == "y" ] || [ "${a}" == "Y" ]; then
"mkfs.${boot_type}" -L boot "${boot_part}"; check_mkfs_status
if [ $LUKS == "YES" ]; then
#Format and encrypt ROOT partition
printf "[*] Formatting ROOT partition, please type your passphrase encryption : \n"
cryptsetup -y -v luksFormat "${root_part}"
printf "[*] Openning encrypted partition, re-enter your passphrase : \n"
cryptsetup open "${root_part}" cryptroot
"mkfs.${root_type}" -L root "/dev/mapper/cryptroot"; check_mkfs_status
printf "[*] Created root encrypted partition: /dev/mapper/cryptroot - "${root_type}
else
"mkfs.${root_type}" -L root "${root_part}"; check_mkfs_status
/usr/bin/mkswap ${swap_part}; check_mkfs_status
fi
else
# go back to setup up filesystem
setup_filesystem
return "${SUCCESS}"
fi
return "${SUCCESS}"
}
ask_for_luks()
{
printf "%s" "${WHITE}"
# user input for luks
printf "[+] Do you want full encrypted root? (YES in upper case) :\n"
read LUKS;
if [ $LUKS == "YES" ]; then
printf "[!] Root will be encrypted\n"
else
printf "[!] Root will NOT be encrypted\n"
fi
}
setup_filesystem()
{
printf "%s" "${WHITE}"
# user input settings
printf "[+] Type the device for install [%s]: " "${HD}"
read a; [ "${a}" != "" ] && HD=${a} # sanitize input
printf " -> Hard Drive Selected: %s\n" "${HD}"
while ! [ "${part_opt}" == "${PART_AUTO}" -o "${part_opt}" == "${PART_MANUAL}" ]; do
printf "[+] Partition mode:\n"
printf "%s[WARNING] If this is a real env (not a Virtual Machine):\n" "${RED}"
printf " * We recomend you to make partitioning by hand with option 2.\n"
printf " * This comes with no guarantees after option 1. You had been warned. ;)\n%s" "${WHITE}"
printf " 1. Automatic - only empty HD! new partitions will be created in %s1, %s2 ans %s3\n" "${HD}" "${HD}" "${HD}"
printf " 2. Manual - set manual partitions with cfdisk and format them\n"
printf "Make your choice: "; read part_opt
done
if [ "${part_opt}" == "${PART_AUTO}" ]; then
setup_partition_values "${part_opt}"
format_filesystem
else
manual_partition
fi
printf "%s" "${NC}"
return "${SUCCESS}"
}
mount_filesystem()
{
mkdir -p "${ROOT}"
if [ $LUKS == "YES" ]; then
mount -t "${root_type}" /dev/mapper/cryptroot "${ROOT}"
else
mount -t "${root_type}" "${root_part}" "${ROOT}"
fi
mkdir -p "${ROOT}/boot"
mount -t "${boot_type}" "${boot_part}" "${ROOT}/boot"
swapon ${swap_part}
return "${SUCCESS}"
}
install_base_packages()
{
wprintf " --> ArchLinux Base"
pacstrap -c "${ROOT}" base
[ ${?} != "0" ] && cri "Failed to install ArchLinux base packages"
return "${SUCCESS}"
}
install_chroot()
{
mode=${1}
# setup chroot-install path
if [ -f chroot-install ]; then
chroot_file="chroot-install"
else
# we are a blackarch package installed
chroot_file="/usr/share/blackarch-install-scripts/chroot-install"
fi
cp "${chroot_file}" "${ROOT}/bin/"
mkdir -p ${ROOT}/{proc,sys,dev}
mount -t proc proc "${ROOT}/proc"
mount --rbind /dev "${ROOT}/dev"
mount --rbind /sys "${ROOT}/sys"
chroot "${ROOT}" "/bin/chroot-install" "${mode}" -d "${HD}"
# cleaning up
rm -rf "${ROOT}/bin/${chroot_file}"
return "${SUCCESS}"
}
# only LIVE mode
dump_live()
{
t=7 remaining=7;
SECONDS=0;
while sleep .2; do
printf '\r[+] Down the rabbit hole we go '"${RED}$remaining"${NC}' ';
if (( (remaining=t-SECONDS) <=0 )); then
printf '\rseconds remaining to proceed' 0;
break;
fi;
done
cp -Rpv /bin /etc /home /lib /lib64 /opt /root /srv /usr /var /tmp "${ROOT}"
# cleaning files - it will be create later
rm -rf "${ROOT}/etc/{group, passwd, shadow*, gshadow*}"
wprintf "[+] Dump done!"
return "${SUCCESS}"
}
install()
{
menu_opt=${1}
# live flag for update system
[ "${menu_opt}" == "${MENU_LIVE}" ] && LIVE="true"
wprintf "[+] Updating system..."
update_system
wprintf "[+] Hard drive configuration..."
ask_for_luks
setup_filesystem
wprintf "[+] Mounting filesystem..."
mount_filesystem
# if live dump everything
[ "${menu_opt}" == "${MENU_LIVE}" ] && dump_live
wprintf "[+] Installing packages..."
install_base_packages
wprintf "[+] Generating fstab..."
genfstab -p "${ROOT}" >> "${ROOT}/etc/fstab"
# if live not need to do this
if [ "${menu_opt}" != "${MENU_LIVE}" ]; then
wprintf "[+] Generating pacman.conf"
cp -Rf /etc/pacman* "${ROOT}/etc/"
wprintf "[+] Generating resolv.conf"
cp /etc/resolv.conf "${ROOT}/etc/"
fi
wprintf "[+] Setting up grub config..."
if [ -d grub ]; then
cp grub/splash.png "${ROOT}/boot/"
else
# we are a blackarch package installed
cp /usr/share/blackarch-install-scripts/grub/splash.png "${ROOT}/boot/"
fi
wprintf "[+] Installing chroot system..."
if [ -d shell ]; then
cp -f shell/etc/issue "${ROOT}/etc/"
cp -R shell/ "${ROOT}/mnt/"
else
cp -f /usr/share/blackarch-install-scripts/shell/etc/issue "${ROOT}/etc/"
cp -R /usr/share/blackarch-install-scripts/shell "${ROOT}/mnt/"
fi
# setup hostname
sed -i 's/localhost/blackarch/g' "${ROOT}/etc/hosts"
case "${menu_opt}" in
"${MENU_LIVE}")
install_chroot "-l"
;;
"${MENU_REPO}")
install_chroot "-r"
;;
"${MENU_BLACKMAN}")
install_chroot "-b"
;;
esac
return "${SUCCESS}"
}
install_menu()
{
printf "%s" "${WHITE}"
while ! [ "${menu_opt}" == "${MENU_LIVE}" \
-o "${menu_opt}" == "${MENU_REPO}" \
-o "${menu_opt}" == "${MENU_BLACKMAN}" ]; do
printf "[+] Select Install Mode:\n"
printf " 1. Install from Live-ISO.\n"
printf " 2. Install from BlackArch Official Repository.\n"
printf " 3. Install from Blackman.\n"
printf "Make a choice: "; read menu_opt
done
printf "%s" "${NC}"
return "${SUCCESS}"
}
# parse command line options
get_opts()
{
while getopts vVH flags
do
case "${flags}" in
#i)
# #optarg=${OPTARG}
# opt="install"
# ;;
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()
{
banner
check_argc ${*}
get_opts ${*}
check_args ${*}
check_env
# commented arg opt
#if [ "${opt}" == "install" ]; then
if [[ "${SEC_ENABLE}" == "false" ]]; then
install_menu
install "${menu_opt}"
else
cri "SEC_ENABLE var active - vim blackarch-install"
fi
#fi
return "${SUCCESS}"
}
# program start
main ${*}
# EOF