· 6 years ago · Apr 15, 2019, 03:02 AM
1#https://drive.google.com/open?id=1wQNdicjj3GqXcxp6zGeUmBv0sIKFkEgT
2
3#!/bin/sh
4################################################################################
5# #
6# blackarch-installer - Official Installer for BlackArch Linux #
7# #
8# AUTHOR #
9# noptrix@nullsecurity.net #
10# #
11################################################################################
12
13
14# blackarch-installer version
15VERSION="v1.0.15"
16
17# path to blackarch-installer
18BI_PATH="/usr/share/blackarch-installer"
19
20# true / false
21TRUE=0
22FALSE=1
23
24# return codes
25SUCCESS=0
26FAILURE=1
27
28# verbose mode - default: quiet
29VERBOSE="/dev/null"
30
31# colors
32WHITE="$(tput setaf 7)"
33WHITEB="$(tput bold ; tput setaf 7)"
34GREEN="$(tput setaf 2)"
35GREENB="$(tput bold ; tput setaf 2)"
36RED="$(tput setaf 1)"
37REDB="$(tput bold; tput setaf 1)"
38YELLOW="$(tput setaf 3)"
39YELLOWB="$(tput bold ; tput setaf 3)"
40BLINK="$(tput blink)"
41NC="$(tput sgr0)"
42
43# installation mode
44INSTALL_MODE=''
45
46# install modes
47INSTALL_REPO='1'
48INSTALL_LIVE_ISO='2'
49INSTALL_BLACKMAN='3'
50
51# chosen locale
52LOCALE=''
53
54# set locale
55SET_LOCALE='1'
56
57# list locales
58LIST_LOCALE='2'
59
60# chosen keymap
61KEYMAP=''
62
63# set keymap
64SET_KEYMAP='1'
65
66# list keymaps
67LIST_KEYMAP='2'
68
69# network interfaces
70NET_IFS=''
71
72# chosen network interface
73NET_IF=''
74
75# network configuration mode
76NET_CONF_MODE=''
77
78# network configuration modes
79NET_CONF_AUTO='1'
80NET_CONF_WLAN='2'
81NET_CONF_MANUAL='3'
82NET_CONF_SKIP='4'
83
84# hostname
85HOST_NAME=''
86
87# host ipv4 address
88HOST_IPV4=''
89
90# gateway ipv4 address
91GATEWAY=''
92
93# subnet mask
94SUBNETMASK=''
95
96# broadcast address
97BROADCAST=''
98
99# nameserver address
100NAMESERVER=''
101
102# LUKS flag
103LUKS=''
104
105# avalable hard drive
106HD_DEVS=''
107
108# chosen hard drive device
109HD_DEV=''
110
111# partition label: gpt or msdos
112PART_LABEL=''
113
114# boot partition
115BOOT_PART=''
116
117# root partition
118ROOT_PART=''
119
120# crypted root
121CRYPT_ROOT='r00t'
122
123# swap partition
124SWAP_PART=''
125
126# boot fs type - default: ext4
127BOOT_FS_TYPE=''
128
129# root fs type - default: ext4
130ROOT_FS_TYPE=''
131
132# chroot directory / blackarch linux installation
133CHROOT='/mnt'
134
135# normal system user
136NORMAL_USER=''
137
138# default BlackArch Linux repository URL
139BA_REPO_URL='https://www.blackarch.org/blackarch/$repo/os/$arch'
140
141# default ArchLinux repository URL
142AR_REPO_URL='https://archlinux.surlyjake.com/archlinux/$repo/os/$arch'
143AR_REPO_URL="$AR_REPO_URL http://mirrors.evowise.com/archlinux/\$repo/os/\$arch"
144AR_REPO_URL="$AR_REPO_URL http://mirror.rackspace.com/archlinux/\$repo/os/\$arch"
145
146# X (display + window managers ) setup - default: false
147X_SETUP=$FALSE
148
149# VirtualBox setup - default: false
150VBOX_SETUP=$FALSE
151
152# VMware setup - default: false
153VMWARE_SETUP=$FALSE
154
155# BlackArch Linux tools setup - default: false
156BA_TOOLS_SETUP=$FALSE
157
158# wlan ssid
159WLAN_SSID=""
160
161# wlan passphrase
162WLAN_PASSPHRASE=""
163
164# check boot mode
165BOOT_MODE=""
166
167# check type of ISO (live? netinst?)
168ISO_TYPE=""
169
170
171# check exit status
172check()
173{
174 es=$1
175 func="$2"
176 info="$3"
177
178 if [ $es -ne 0 ]
179 then
180 echo
181 warn "Something went wrong with $func. $info."
182 sleep 5
183 fi
184}
185
186
187# print formatted output
188wprintf()
189{
190 fmt="${1}"
191
192 shift
193 printf "%s$fmt%s" "$WHITE" "$@" "$NC"
194
195 return $SUCCESS
196}
197
198
199# print warning
200warn()
201{
202 printf "%s[!] WARNING: %s%s\n" "$YELLOW" "$@" "$NC"
203
204 return $SUCCESS
205}
206
207
208# print error and exit
209err()
210{
211 printf "%s[-] ERROR: %s%s\n" "$RED" "$@" "$NC"
212
213 exit $FAILURE
214
215 return $SUCCESS
216}
217
218
219# leet banner (very important)
220banner()
221{
222 columns="$(tput cols)"
223 str="--==[ blackarch-installer $VERSION ]==--"
224
225 printf "${REDB}%*s${NC}\n" "${COLUMNS:-$(tput cols)}" | tr ' ' '-'
226
227 echo "$str" |
228 while IFS= read -r line
229 do
230 printf "%s%*s\n%s" "$WHITEB" $(( (${#line} + columns) / 2)) \
231 "$line" "$NC"
232 done
233
234 printf "${REDB}%*s${NC}\n\n\n" "${COLUMNS:-$(tput cols)}" | tr ' ' '-'
235
236 return $SUCCESS
237}
238
239
240# check boot mode
241check_boot_mode()
242{
243 if [ "$(efivar --list 2> /dev/null)" ]
244 then
245 BOOT_MODE="uefi"
246 else
247 BOOT_MODE="bios"
248 fi
249
250 return $SUCCESS
251}
252
253
254# check type of iso
255check_iso_type()
256{
257 if [ "$(which dnsspider 2> /dev/null)" ]
258 then
259 ISO_TYPE="live"
260 else
261 ISO_TYPE="net"
262 fi
263
264 return $SUCCESS
265}
266
267
268# sleep and clear
269sleep_clear()
270{
271 sleep $1
272 clear
273
274 return $SUCCESS
275}
276
277
278# confirm user inputted yYnN
279confirm()
280{
281 header="$1"
282 ask="$2"
283
284 while true
285 do
286 title "$header"
287 wprintf "$ask"
288 read input
289 case $input in
290 y|Y|yes|YES|Yes) return $TRUE ;;
291 n|N|no|NO|No) return $FALSE ;;
292 *) clear ; continue ;;
293 esac
294 done
295
296 return $SUCCESS
297}
298
299
300# print menu title
301title()
302{
303 banner
304 printf "${GREEN}>> %s${NC}\n\n\n" "${@}"
305
306 return "${SUCCESS}"
307}
308
309
310# check for environment issues
311check_env()
312{
313 if [ -f "/var/lib/pacman/db.lck" ]
314 then
315 err "pacman locked - Please remove /var/lib/pacman/db.lck"
316 fi
317}
318
319
320# check user id
321check_uid()
322{
323 if [ "$(id -u)" != "0" ]
324 then
325 err "You must be root to run the BlackArch installer!"
326 fi
327
328 return $SUCCESS
329}
330
331
332# welcome and ask for installation mode
333ask_install_mode()
334{
335 while [ \
336 "$INSTALL_MODE" != "$INSTALL_REPO" -a \
337 "$INSTALL_MODE" != "$INSTALL_BLACKMAN" -a \
338 "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
339 do
340 title "Welcome to the BlackArch Linux installer!"
341 wprintf "[+] Available installation modes:"
342 printf "\n
343 1. Install from BlackArch repository (online)
344 2. Install from BlackArch Live-ISO (offline)
345 3. Install from sources using blackman (online)\n\n"
346 wprintf "[?] Choose an installation mode: "
347 read INSTALL_MODE
348 if [ "$INSTALL_MODE" = "$INSTALL_LIVE_ISO" ]
349 then
350 if [ "$ISO_TYPE" = "net" ]
351 then
352 err "WTF, Live-ISO mode with Netinstall? Nope, sorry!"
353 fi
354 fi
355 clear
356 done
357
358 return $SUCCESS
359}
360
361
362# ask for output mode
363ask_output_mode()
364{
365 title "Environment > Output Mode"
366 wprintf "[+] Available output modes:"
367 printf "\n
368 1. Quiet (default)
369 2. Verbose (output of system commands: mkfs, pacman, etc.)\n\n"
370 wprintf "[?] Make a choice: "
371 read output_opt
372 if [ "$output_opt" = 2 ]
373 then
374 VERBOSE="/dev/stdout"
375 fi
376
377 return $SUCCESS
378}
379
380
381# ask for locale to use
382ask_locale()
383{
384 while [ \
385 "$locale_opt" != "$SET_LOCALE" -a \
386 "$locale_opt" != "$LIST_LOCALE" ]
387 do
388 title "Environment > Locale Setup"
389 wprintf "[+] Available locale options:"
390 printf "\n
391 1. Set a locale
392 2. List available locales\n\n"
393 wprintf "[?] Make a choice: "
394 read locale_opt
395 if [ "$locale_opt" = "$SET_LOCALE" ]
396 then
397 break
398 elif [ "$locale_opt" = "$LIST_LOCALE" ]
399 then
400 less /etc/locale.gen
401 echo
402 else
403 clear
404 continue
405 fi
406 clear
407 done
408
409 clear
410
411 return $SUCCESS
412}
413
414
415# set locale to use
416set_locale()
417{
418 title "Environment > Locale Setup"
419 wprintf "[?] Set locale [en_US.UTF-8]: "
420 read LOCALE
421
422 # default locale
423 if [ -z "$LOCALE" ]
424 then
425 echo
426 warn "Setting default locale: en_US.UTF-8"
427 sleep 1
428 LOCALE="en_US.UTF-8"
429 fi
430 localectl set-locale "LANG=$LOCALE"
431 check $? "setting locale"
432
433 return $SUCCESS
434}
435
436
437# ask for keymap to use
438ask_keymap()
439{
440 while [ \
441 "$keymap_opt" != "$SET_KEYMAP" -a \
442 "$keymap_opt" != "$LIST_KEYMAP" ]
443 do
444 title "Environment > Keymap Setup"
445 wprintf "[+] Available keymap options:"
446 printf "\n
447 1. Set a keymap
448 2. List available keymaps\n\n"
449 wprintf "[?] Make a choice: "
450 read keymap_opt
451
452 if [ "$keymap_opt" = "$SET_KEYMAP" ]
453 then
454 break
455 elif [ "$keymap_opt" = "$LIST_KEYMAP" ]
456 then
457 localectl list-x11-keymap-layouts
458 echo
459 else
460 clear
461 continue
462 fi
463 clear
464 done
465
466 clear
467
468 return $SUCCESS
469}
470
471
472# set keymap to use
473set_keymap()
474{
475 title "Environment > Keymap Setup"
476 wprintf "[?] Set keymap [us]: "
477 read KEYMAP
478
479 # default keymap
480 if [ -z "$KEYMAP" ]
481 then
482 echo
483 warn "Setting default keymap: us"
484 sleep 1
485 KEYMAP="us"
486 fi
487 localectl set-keymap --no-convert "$KEYMAP"
488 loadkeys "$KEYMAP" > $VERBOSE 2>&1
489 check $? "setting keymap"
490
491 return $SUCCESS
492}
493
494
495# enable multilib in pacman.conf if x86_64 present
496enable_pacman_multilib()
497{
498 path="$1"
499
500 if [ "$path" = "chroot" ]
501 then
502 path="$CHROOT"
503 else
504 path=""
505 fi
506
507 title "Pacman Setup > Multilib"
508
509 if [ "$(uname -m)" = "x86_64" ]
510 then
511 wprintf "[+] Enabling multilib support"
512 printf "\n\n"
513 if grep -q "#\[multilib\]" "$path/etc/pacman.conf"
514 then
515 # it exists but commented
516 sed -i '/\[multilib\]/{ s/^#//; n; s/^#//; }' "$path/etc/pacman.conf"
517 elif ! grep -q "\[multilib\]" "$path/etc/pacman.conf"
518 then
519 # it does not exist at all
520 printf "[multilib]\nInclude = /etc/pacman.d/mirrorlist\n" \
521 >> "$path/etc/pacman.conf"
522 fi
523 fi
524
525 return $SUCCESS
526}
527
528
529# enable color mode in pacman.conf
530enable_pacman_color()
531{
532 path="$1"
533
534 if [ "$path" = "chroot" ]
535 then
536 path="$CHROOT"
537 else
538 path=""
539 fi
540
541 title "Pacman Setup > Color"
542
543 wprintf "[+] Enabling color mode"
544 printf "\n\n"
545
546 sed -i 's/^#Color/Color/' "$path/etc/pacman.conf"
547
548 return $SUCCESS
549}
550
551
552# update pacman package database
553update_pkg_database()
554{
555 title "Pacman Setup > Package Database"
556
557 wprintf "[+] Updating pacman database"
558 printf "\n\n"
559
560 pacman -Syy --noconfirm > $VERBOSE 2>&1
561
562 return $SUCCESS
563}
564
565
566# update pacman.conf and database
567update_pacman()
568{
569 enable_pacman_multilib
570 sleep_clear 1
571
572 enable_pacman_color
573 sleep_clear 1
574
575 update_pkg_database
576 sleep_clear 1
577
578 return $SUCCESS
579}
580
581
582# ask user for hostname
583ask_hostname()
584{
585 while [ -z "$HOST_NAME" ]
586 do
587 title "Network Setup > Hostname"
588 wprintf "[?] Set your hostname: "
589 read HOST_NAME
590 done
591
592 return $SUCCESS
593}
594
595# get available network interfaces
596get_net_ifs()
597{
598 NET_IFS="$(ls /sys/class/net)"
599
600 return $SUCCESS
601}
602
603
604# ask user for network interface
605ask_net_if()
606{
607 while true
608 do
609 title "Network Setup > Network Interface"
610 wprintf "[+] Available network interfaces:"
611 printf "\n\n"
612 for i in $NET_IFS
613 do
614 echo " > $i"
615 done
616 echo
617 wprintf "[?] Please choose a network interface: "
618 read NET_IF
619 if echo $NET_IFS | grep "\<$NET_IF\>" > /dev/null
620 then
621 clear
622 break
623 fi
624 clear
625 done
626
627 return $SUCCESS
628}
629
630
631# ask for networking configuration mode
632ask_net_conf_mode()
633{
634 while [ \
635 "$NET_CONF_MODE" != "$NET_CONF_AUTO" -a \
636 "$NET_CONF_MODE" != "$NET_CONF_WLAN" -a \
637 "$NET_CONF_MODE" != "$NET_CONF_MANUAL" -a \
638 "$NET_CONF_MODE" != "$NET_CONF_SKIP" ]
639 do
640 title "Network Setup > Network Interface"
641 wprintf "[+] Network interface configuration:"
642 printf "\n
643 1. Auto DHCP (use this for auto connect via dhcp on selected interface)
644 2. WiFi WPA Setup (use if you need to connect to a wlan before)
645 3. Manual (use this if you are 1337)
646 4. Skip (use this if you are already connected)\n\n"
647 wprintf "[?] Please choose a mode: "
648 read NET_CONF_MODE
649 clear
650 done
651
652 return $SUCCESS
653}
654
655
656# ask for network addresses
657ask_net_addr()
658{
659 while [ \
660 "$HOST_IPV4" = "" -o "$GATEWAY" = "" -o "$SUBNETMASK" = "" \
661 -o "$BROADCAST" = "" -o "$NAMESERVER" = "" ]
662 do
663 title "Network Setup > Network Configuration (manual)"
664 wprintf "[+] Configuring network interface '$NET_IF' via USER: "
665 printf "\n
666 > Host ipv4
667 > Gateway ipv4
668 > Subnetmask
669 > Broadcast
670 > Nameserver
671 \n"
672 wprintf "[?] Host IPv4: "
673 read HOST_IPV4
674 wprintf "[?] Gateway IPv4: "
675 read GATEWAY
676 wprintf "[?] Subnetmask: "
677 read SUBNETMASK
678 wprintf "[?] Broadcast: "
679 read BROADCAST
680 wprintf "[?] Nameserver: "
681 read NAMESERVER
682 clear
683 done
684
685 return $SUCCESS
686}
687
688
689# manual network interface configuration
690net_conf_manual()
691{
692 title "Network Setup > Network Configuration (manual)"
693 wprintf "[+] Configuring network interface '$NET_IF' manually: "
694 printf "\n\n"
695
696 ip addr flush dev $NET_IF
697 ip link set $NET_IF up
698 ip addr add "$HOST_IPV4/$SUBNETMASK" broadcast $BROADCAST dev $NET_IF
699 ip route add default via $GATEWAY
700 echo "nameserver $NAMESERVER" > /etc/resolv.conf
701
702 return $SUCCESS
703}
704
705
706# auto (dhcp) network interface configuration
707net_conf_auto()
708{
709 opts="-h noleak -i noleak -v ,noleak -I noleak -t 10"
710
711 title "Network Setup > Network Configuration (auto)"
712 wprintf "[+] Configuring network interface '$NET_IF' via DHCP: "
713 printf "\n\n"
714
715 dhcpcd $opts -i $NET_IF > $VERBOSE 2>&1
716
717 return $SUCCESS
718}
719
720
721# ask for wlan data (ssid, wpa passphrase, etc.)
722ask_wlan_data()
723{
724 while [ "$WLAN_SSID" = "" -o "$WLAN_PASSPHRASE" = "" ]
725 do
726 title "Network Setup > Network Configuration (WiFi)"
727 wprintf "[+] Configuring network interface '$NET_IF' via W-LAN + DHCP: "
728 printf "\n
729 > W-LAN SSID
730 > WPA Passphrase (will not echo)
731 \n"
732 wprintf "[?] W-LAN SSID: "
733 read WLAN_SSID
734 wprintf "[?] WPA Passphrase: "
735 read -s WLAN_PASSPHRASE
736 clear
737 done
738
739 return $SUCCESS
740}
741
742
743# wifi and auto dhcp network interface configuration
744net_conf_wlan()
745{
746 wpasup="$(mktemp)"
747 dhcp_opts="-h noleak -i noleak -v ,noleak -I noleak -t 10"
748
749 title "Network Setup > Network Configuration (WiFi)"
750 wprintf "[+] Configuring network interface '$NET_IF' via W-LAN + DHCP: "
751 printf "\n\n"
752
753 wpa_passphrase "$WLAN_SSID" "$WLAN_PASSPHRASE" > $wpasup
754 wpa_supplicant -B -c $wpasup -i $NET_IF > $VERBOSE 2>&1
755
756 warn "We need to wait a bit for wpa_supplicant and dhcpcd"
757
758 sleep 10
759
760 dhcpcd $dhcp_opts -i $NET_IF > $VERBOSE 2>&1
761
762 sleep 10
763
764 return $SUCCESS
765}
766
767
768# check for internet connection
769check_inet_conn()
770{
771 title "Network Setup > Connection Check"
772 wprintf "[+] Checking for Internet connection..."
773
774 if ! curl -s http://www.yahoo.com/ > $VERBOSE 2>&1
775 then
776 err "No Internet connection! Check your network (settings)."
777 fi
778
779 return $SUCCESS
780}
781
782
783# ask user for luks encrypted partition
784ask_luks()
785{
786 while [ "$LUKS" = "" ]
787 do
788 if confirm "Hard Drive Setup > Crypto" "[?] Full encrypted root [y/n]: "
789 then
790 LUKS=$TRUE
791 echo
792 warn "The root partition will be encrypted"
793 else
794 LUKS=$FALSE
795 echo
796 warn "The root partition will NOT be encrypted"
797 fi
798 sleep_clear 2
799 done
800 return $SUCCESS
801}
802
803
804# get available hard disks
805get_hd_devs()
806{
807 HD_DEVS="$(lsblk | grep disk | awk '{print $1}')"
808
809 return $SUCCESS
810}
811
812
813# ask user for device to format and setup
814ask_hd_dev()
815{
816 while true
817 do
818 title "Hard Drive Setup"
819
820 wprintf "[+] Available hard drives for installation:"
821 printf "\n\n"
822
823 for i in $HD_DEVS
824 do
825 echo " > ${i}"
826 done
827 echo
828 wprintf "[?] Please choose a device: "
829 read HD_DEV
830 if echo $HD_DEVS | grep "\<$HD_DEV\>" > /dev/null
831 then
832 HD_DEV="/dev/$HD_DEV"
833 clear
834 break
835 fi
836 clear
837 done
838
839
840 return $SUCCESS
841}
842
843
844# ask user to create partitions using cfdisk
845ask_cfdisk()
846{
847 if confirm "Hard Drive Setup > Partitions" "[?] Create partitions with \
848cfdisk (root and boot, optional swap) [y/n]: "
849 then
850 clear
851 zero_part
852 else
853 echo
854 warn "No partitions chosed? Make sure you have them already configured."
855 fi
856
857 return $SUCCESS
858}
859
860
861# zero out partition if needed/chosen
862zero_part()
863{
864 if confirm "Hard Drive Setup" "[?] Start with an in-memory zeroed \
865partition table [y/n]: "
866 then
867 cfdisk -z "$HD_DEV"
868 sync
869 else
870 cfdisk "$HD_DEV"
871 sync
872 fi
873
874 return $SUCCESS
875}
876
877
878# get partition label
879get_partition_label()
880{
881 PART_LABEL="$(parted -m $HD_DEV print | grep $HD_DEV | cut -d ':' -f 6)"
882
883 return $SUCCESS
884}
885
886
887# get partitions
888ask_partitions()
889{
890 partitions=$(ls ${HD_DEV}* | grep -v "${HD_DEV}\>")
891
892 while [ \
893 "$BOOT_PART" = "" -o \
894 "$ROOT_PART" = "" -o \
895 "$BOOT_FS_TYPE" = "" -o \
896 "$ROOT_FS_TYPE" = "" ]
897 do
898 title "Hard Drive Setup > Partitions"
899 wprintf "[+] Created partitions:"
900 printf "\n\n"
901
902 for i in $partitions
903 do
904 echo " > $i"
905 done
906 echo
907
908 wprintf "[?] Boot partition (/dev/sdXY): "
909 read BOOT_PART
910 wprintf "[?] Boot FS type (ext2, ext3, ext4, fat32): "
911 read BOOT_FS_TYPE
912 wprintf "[?] Root partition (/dev/sdXY): "
913 read ROOT_PART
914 wprintf "[?] Root FS type (ext2, ext3, ext4, btrfs): "
915 read ROOT_FS_TYPE
916 wprintf "[?] Swap parition (/dev/sdXY - empty for none): "
917 read SWAP_PART
918
919 if [ "$SWAP_PART" = "" ]
920 then
921 SWAP_PART="none"
922 fi
923 clear
924 done
925
926 return $SUCCESS
927}
928
929
930# print partitions and ask for confirmation
931print_partitions()
932{
933 i=""
934
935 while true
936 do
937 title "Hard Drive Setup > Partitions"
938 wprintf "[+] Current Partition table"
939 printf "\n
940 > /boot : $BOOT_PART ($BOOT_FS_TYPE)
941 > / : $ROOT_PART ($ROOT_FS_TYPE)
942 > swap : $SWAP_PART (swap)
943 \n"
944 wprintf "[?] Partition table correct [y/n]: "
945 read i
946 if [ "$i" = "y" -o "$i" = "Y" ]
947 then
948 clear
949 break
950 elif [ "$i" = "n" -o "$i" = "N" ]
951 then
952 echo
953 err "Hard Drive Setup aborted."
954 else
955 clear
956 continue
957 fi
958 clear
959 done
960
961 return $SUCCESS
962}
963
964
965# ask user and get confirmation for formatting
966ask_formatting()
967{
968 if confirm "Hard Drive Setup > Partition Formatting" "[?] Formatting \
969partitions. Are you sure? No crying afterwards? [y/n]: "
970 then
971 return $SUCCESS
972 else
973 echo
974 err "Seriously? No formatting no fun!"
975 fi
976
977 return $SUCCESS
978}
979
980
981# create LUKS encrypted partition
982make_luks_partition()
983{
984 part="$1"
985
986 title "Hard Drive Setup > Partition Creation (crypto)"
987
988 wprintf "[+] Creating LUKS partition"
989 printf "\n\n"
990
991 cryptsetup -q -y -v -c aes-xts-plain64 -s 512 -h sha512 luksFormat "$part" \
992 > $VERBOSE 2>&1 || err "Could not LUKS format"
993
994 return $SUCCESS
995}
996
997
998# open LUKS partition
999open_luks_partition()
1000{
1001 part="$1"
1002 name="$2"
1003
1004 title "Hard Drive Setup > Partition Creation (crypto)"
1005
1006 wprintf "[+] Opening LUKS partition"
1007 printf "\n\n"
1008 cryptsetup open $part $name > $VERBOSE 2>&1 ||
1009 err "Could not open LUKS device"
1010
1011 return $SUCCESS
1012}
1013
1014
1015# create swap partition
1016make_swap_partition()
1017{
1018 title "Hard Drive Setup > Partition Creation (swap)"
1019
1020 wprintf "[+] Creating SWAP partition"
1021 printf "\n\n"
1022 mkswap $SWAP_PART > $VERBOSE 2>&1 || err "Could not create filesystem"
1023
1024 return $SUCCESS
1025}
1026
1027
1028# make and format root partition
1029make_root_partition()
1030{
1031 if [ $LUKS = $TRUE ]
1032 then
1033 make_luks_partition "$ROOT_PART"
1034 sleep_clear 1
1035 open_luks_partition "$ROOT_PART" "$CRYPT_ROOT"
1036 sleep_clear 1
1037 title "Hard Drive Setup > Partition Creation (root crypto)"
1038 wprintf "[+] Creating encrypted ROOT partition"
1039 printf "\n\n"
1040 if [ "$ROOT_FS_TYPE" = "btrfs" ]
1041 then
1042 mkfs.$ROOT_FS_TYPE -f "/dev/mapper/$CRYPT_ROOT" > $VERBOSE 2>&1 ||
1043 err "Could not create filesystem"
1044 else
1045 mkfs.$ROOT_FS_TYPE -F "/dev/mapper/$CRYPT_ROOT" > $VERBOSE 2>&1 ||
1046 err "Could not create filesystem"
1047 fi
1048 sleep_clear 1
1049 else
1050 title "Hard Drive Setup > Partition Creation (root)"
1051 wprintf "[+] Creating ROOT partition"
1052 printf "\n\n"
1053 if [ "$ROOT_FS_TYPE" = "btrfs" ]
1054 then
1055 mkfs.$ROOT_FS_TYPE -f $ROOT_PART > $VERBOSE 2>&1 ||
1056 err "Could not create filesystem"
1057 else
1058 mkfs.$ROOT_FS_TYPE -F $ROOT_PART > $VERBOSE 2>&1 ||
1059 err "Could not create filesystem"
1060 fi
1061 sleep_clear 1
1062 fi
1063
1064 return $SUCCESS
1065}
1066
1067
1068# make and format boot partition
1069make_boot_partition()
1070{
1071 title "Hard Drive Setup > Partition Creation (boot)"
1072
1073 wprintf "[+] Creating BOOT partition"
1074 printf "\n\n"
1075 if [ "$PART_LABEL" = "gpt" ]
1076 then
1077 mkfs.fat -F32 $BOOT_PART > $VERBOSE 2>&1 ||
1078 err "Could not create filesystem"
1079 else
1080 mkfs.$BOOT_FS_TYPE -F $BOOT_PART > $VERBOSE 2>&1 ||
1081 err "Could not create filesystem"
1082 fi
1083
1084 return $SUCCESS
1085}
1086
1087
1088# make and format partitions
1089make_partitions()
1090{
1091 make_boot_partition
1092 sleep_clear 1
1093
1094 make_root_partition
1095 sleep_clear 1
1096
1097 if [ "$SWAP_PART" != "none" ]
1098 then
1099 make_swap_partition
1100 sleep_clear 1
1101 fi
1102
1103 return $SUCCESS
1104}
1105
1106
1107# mount filesystems
1108mount_filesystems()
1109{
1110 title "Hard Drive Setup > Mount"
1111
1112 wprintf "[+] Mounting filesystems"
1113 printf "\n\n"
1114
1115 # ROOT
1116 if [ $LUKS = $TRUE ]
1117 then
1118 mount "/dev/mapper/$CRYPT_ROOT" $CHROOT > $VERBOSE 2>&1
1119 else
1120 mount $ROOT_PART $CHROOT > $VERBOSE 2>&1
1121 fi
1122
1123 # BOOT
1124 mkdir "$CHROOT/boot" > $VERBOSE 2>&1
1125 mount $BOOT_PART "$CHROOT/boot" > $VERBOSE 2>&1
1126
1127 # SWAP
1128 if [ "$SWAP_PART" != "none" ]
1129 then
1130 swapon $SWAP_PART > $VERBOSE 2>&1
1131 fi
1132
1133 return $SUCCESS
1134}
1135
1136
1137# unmount filesystems
1138umount_filesystems()
1139{
1140 routine="$1"
1141
1142 if [ "$routine" = "harddrive" ]
1143 then
1144 title "Hard Drive Setup > Unmount"
1145
1146 wprintf "[+] Unmounting filesystems"
1147 printf "\n\n"
1148
1149 umount -Rf "$HD_DEV"{1..128} > /dev/null 2>&1 # gpt max - 128
1150 else
1151 title "Game Over"
1152
1153 wprintf "[+] Unmounting filesystems"
1154 printf "\n\n"
1155
1156 umount -Rf $CHROOT > /dev/null 2>&1
1157 cryptsetup luksClose "$CRYPT_ROOT" > /dev/null 2>&1
1158 swapoff $SWAP_PART > /dev/null 2>&1
1159 fi
1160
1161 return $SUCCESS
1162}
1163
1164
1165# check for necessary space
1166check_space()
1167{
1168 if [ $LUKS -eq $TRUE ]
1169 then
1170 avail_space=$(df -m | grep "/dev/mapper/$CRYPT_ROOT" | awk '{print $4}')
1171 else
1172 avail_space=$(df -m | grep "$ROOT_PART" | awk '{print $4}')
1173 fi
1174
1175 if [ $avail_space -le 40960 ]
1176 then
1177 warn "BlackArch Linux requires at least 40 GB of free space to install!"
1178 fi
1179
1180 return $SUCCESS
1181}
1182
1183
1184# install ArchLinux base and base-devel packages
1185install_base_packages()
1186{
1187 title "Base System Setup > ArchLinux Packages"
1188
1189 wprintf "[+] Installing ArchLinux base packages"
1190 printf "\n\n"
1191 warn "This can take a while, please wait..."
1192 printf "\n"
1193
1194 pacstrap $CHROOT base base-devel terminus-font > $VERBOSE 2>&1
1195 chroot $CHROOT pacman -Syy --noconfirm --overwrite='*' > $VERBOSE 2>&1
1196
1197 return $SUCCESS
1198}
1199
1200
1201# setup /etc/resolv.conf
1202setup_resolvconf()
1203{
1204 title "Base System Setup > Etc"
1205
1206 wprintf "[+] Setting up /etc/resolv.conf"
1207 printf "\n\n"
1208
1209 mkdir -p "$CHROOT/etc/" > $VERBOSE 2>&1
1210 cp -L /etc/resolv.conf "$CHROOT/etc/resolv.conf" > $VERBOSE 2>&1
1211
1212 return $SUCCESS
1213}
1214
1215
1216# setup fstab
1217setup_fstab()
1218{
1219 title "Base System Setup > Etc"
1220
1221 wprintf "[+] Setting up /etc/fstab"
1222 printf "\n\n"
1223
1224 if [ "$PART_LABEL" = "gpt" ]
1225 then
1226 genfstab -U $CHROOT >> "$CHROOT/etc/fstab"
1227 else
1228 genfstab -L $CHROOT >> "$CHROOT/etc/fstab"
1229 fi
1230
1231 sed 's/relatime/noatime/g' -i "$CHROOT/etc/fstab"
1232
1233 return $SUCCESS
1234}
1235
1236
1237# setup locale and keymap
1238setup_locale()
1239{
1240 title "Base System Setup > Locale"
1241
1242 wprintf "[+] Setting up $LOCALE locale"
1243 printf "\n\n"
1244 sed -i "s/^#en_US.UTF-8/en_US.UTF-8/" "$CHROOT/etc/locale.gen"
1245 sed -i "s/^#$LOCALE/$LOCALE/" "$CHROOT/etc/locale.gen"
1246 chroot $CHROOT locale-gen > $VERBOSE 2>&1
1247 echo "LANG=$LOCALE" > "$CHROOT/etc/locale.conf"
1248 echo "KEYMAP=$KEYMAP" > "$CHROOT/etc/vconsole.conf"
1249
1250 return $SUCCESS
1251}
1252
1253
1254# setup timezone
1255setup_time()
1256{
1257 if confirm "Base System Setup > Timezone" "[?] Default: UTC. Choose other timezone [y/n]: "
1258 then
1259 for t in $(timedatectl list-timezones)
1260 do
1261 echo " > $(echo $t)"
1262 done
1263
1264 wprintf "\n[?] What is your (Zone/SubZone): "
1265 read timezone
1266 chroot $CHROOT ln -sf "/usr/share/zoneinfo/$timezone" /etc/localtime \
1267 > $VERBOSE 2>&1
1268
1269 if [ $? -eq 1 ]
1270 then
1271 warn "Do you live on Mars? Setting default time zone..."
1272 sleep 1
1273 default_time
1274 else
1275 wprintf "\n[+] Time zone setup correctly\n"
1276 fi
1277 else
1278 wprintf "\n[+] Setting up default time and timezone\n"
1279 sleep 2
1280 default_time
1281 fi
1282
1283 printf "\n"
1284
1285 return $SUCCESS
1286}
1287
1288
1289# default time and timezone
1290default_time()
1291{
1292 echo
1293 warn "Setting up default time and timezone: UTC"
1294 printf "\n\n"
1295 chroot $CHROOT ln -sf /usr/share/zoneinfo/UTC /etc/localtime > $VERBOSE 2>&1
1296
1297 return $SUCCESS
1298}
1299
1300
1301# setup initramfs
1302setup_initramfs()
1303{
1304 title "Base System Setup > InitramFS"
1305
1306 wprintf "[+] Setting up InitramFS"
1307 printf "\n\n"
1308
1309 if [ "$INSTALL_MODE" = "$INSTALL_LIVE_ISO" ]
1310 then
1311 cp /run/archiso/bootmnt/blackarch/boot/x86_64/vmlinuz \
1312 "$CHROOT/boot/vmlinuz-linux"
1313 fi
1314
1315 # terminus font
1316 sed -i 's/keyboard fsck/keyboard fsck consolefont/g' \
1317 "$CHROOT/etc/mkinitcpio.conf"
1318 echo 'FONT=ter-114n' >> "$CHROOT/etc/vconsole.conf"
1319
1320 if [ $LUKS = $TRUE ]
1321 then
1322 sed -i 's/block filesystems/block keymap encrypt filesystems/g' \
1323 "$CHROOT/etc/mkinitcpio.conf"
1324 fi
1325
1326 warn "This can take a while, please wait..."
1327 printf "\n"
1328 chroot $CHROOT mkinitcpio -p linux > $VERBOSE 2>&1
1329
1330 return $SUCCESS
1331}
1332
1333
1334# mount /proc, /sys and /dev
1335setup_proc_sys_dev()
1336{
1337 title "Base System Setup > Proc Sys Dev"
1338
1339 wprintf "[+] Setting up /proc, /sys and /dev"
1340 printf "\n\n"
1341
1342 mkdir -p "${CHROOT}/"{proc,sys,dev} > $VERBOSE 2>&1
1343
1344 mount -t proc proc "$CHROOT/proc" > $VERBOSE 2>&1
1345 mount --rbind /sys "$CHROOT/sys" > $VERBOSE 2>&1
1346 mount --make-rslave "$CHROOT/sys" > $VERBOSE 2>&1
1347 mount --rbind /dev "$CHROOT/dev" > $VERBOSE 2>&1
1348 mount --make-rslave "$CHROOT/dev" > $VERBOSE 2>&1
1349
1350 return $SUCCESS
1351}
1352
1353
1354# setup hostname
1355setup_hostname()
1356{
1357 title "Base System Setup > Hostname"
1358
1359 wprintf "[+] Setting up hostname"
1360 printf "\n\n"
1361
1362 echo $HOST_NAME > "$CHROOT/etc/hostname"
1363
1364 return $SUCCESS
1365}
1366
1367
1368# setup boot loader for UEFI/GPT or BIOS/MBR
1369setup_bootloader()
1370{
1371 title "Base System Setup > Boot Loader"
1372
1373 if [ "$PART_LABEL" = "gpt" ]
1374 then
1375 wprintf "[+] Setting up EFI boot loader"
1376 printf "\n\n"
1377
1378 chroot $CHROOT bootctl install > $VERBOSE 2>&1
1379 uuid="$(blkid $ROOT_PART | cut -d ' ' -f 2 | cut -d '"' -f 2)"
1380
1381 if [ $LUKS = $TRUE ]
1382 then
1383 cat >> "$CHROOT/boot/loader/entries/arch.conf" << EOF
1384title BlackArch Linux
1385linux /vmlinuz-linux
1386initrd /initramfs-linux.img
1387options cryptdevice=UUID=$uuid:$CRYPT_ROOT root=/dev/mapper/$CRYPT_ROOT rw
1388EOF
1389
1390 else
1391 cat >> "$CHROOT/boot/loader/entries/arch.conf" << EOF
1392title BlackArch Linux
1393linux /vmlinuz-linux
1394initrd /initramfs-linux.img
1395options root=UUID=$uuid rw
1396EOF
1397 fi
1398 else
1399 wprintf "[+] Setting up GRUB boot loader"
1400 printf "\n\n"
1401
1402 uuid="$(lsblk -o UUID $ROOT_PART | sed -n 2p)"
1403
1404 if [ "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
1405 then
1406 chroot $CHROOT pacman -S grub --noconfirm --overwrite='*' --needed \
1407 > $VERBOSE 2>&1
1408 else
1409 mkdir -p "$CHROOT/boot/grub"
1410 fi
1411
1412 if [ $LUKS = $TRUE ]
1413 then
1414 sed -i "s|quiet|cryptdevice=UUID=$uuid:$CRYPT_ROOT root=/dev/mapper/$CRYPT_ROOT quiet|" \
1415 "$CHROOT/etc/default/grub"
1416 fi
1417 sed -i 's/Arch/BlackArch/g' "$CHROOT/etc/default/grub"
1418 echo "GRUB_BACKGROUND=\"/boot/grub/splash.png\"" >> \
1419 "$CHROOT/etc/default/grub"
1420
1421 chroot $CHROOT grub-install --target=i386-pc $HD_DEV > $VERBOSE 2>&1
1422
1423 cp -f "$BI_PATH/data/boot/grub/splash.png" "$CHROOT/boot/grub/splash.png"
1424
1425 chroot $CHROOT grub-mkconfig -o /boot/grub/grub.cfg > $VERBOSE 2>&1
1426
1427 fi
1428
1429 return $SUCCESS
1430}
1431
1432
1433# ask for normal user account to setup
1434ask_user_account()
1435{
1436 if confirm "Base System Setup > User" "[?] Setup a normal user account [y/n]: "
1437 then
1438 wprintf "[?] User name: "
1439 read NORMAL_USER
1440 fi
1441
1442 return $SUCCESS
1443}
1444
1445
1446# setup blackarch test user (not active + lxdm issue)
1447setup_testuser()
1448{
1449 title "Base System Setup > Test User"
1450
1451 wprintf "[+] Setting up test user blackarchtest account"
1452 printf "\n\n"
1453 warn "Remove this user after you added a normal system user account"
1454 printf "\n"
1455
1456 chroot $CHROOT groupadd blackarchtest > $VERBOSE 2>&1
1457 chroot $CHROOT useradd -g blackarchtest -d /home/blackarchtest/ \
1458 -s /sbin/nologin -m blackarchtest > $VERBOSE 2>&1
1459}
1460
1461
1462# setup user account, password and environment
1463setup_user()
1464{
1465 user="$(echo $1 | tr -dc '[:alnum:]_' | tr '[:upper:]' '[:lower:]' |
1466 cut -c 1-32)"
1467
1468 title "Base System Setup > User"
1469
1470 wprintf "[+] Setting up $user account"
1471 printf "\n\n"
1472
1473 # normal user
1474 if [ ! -z $NORMAL_USER ]
1475 then
1476 chroot $CHROOT groupadd $user > $VERBOSE 2>&1
1477 chroot $CHROOT useradd -g $user -d "/home/$user" -s "/bin/bash" \
1478 -G "$user,wheel,users,video,audio" -m $user > $VERBOSE 2>&1
1479 chroot $CHROOT chown -R $user:$user "/home/$user" > $VERBOSE 2>&1
1480 wprintf "[+] Added user: $user"
1481 printf "\n\n"
1482 fi
1483
1484 # environment
1485 if [ -z $NORMAL_USER ]
1486 then
1487 cp -r "$BI_PATH/data/root/." "$CHROOT/root/." > $VERBOSE 2>&1
1488 else
1489 cp -r "$BI_PATH/data/user/." "$CHROOT/home/$user/." > $VERBOSE 2>&1
1490 chroot $CHROOT chown -R $user:$user "/home/$user" > $VERBOSE 2>&1
1491 fi
1492
1493 # password
1494 res=1337
1495 wprintf "[?] Set password for $user: "
1496 printf "\n\n"
1497 while [ $res -ne 0 ]
1498 do
1499 if [ "$user" = "root" ]
1500 then
1501 chroot $CHROOT passwd
1502 else
1503 chroot $CHROOT passwd $user
1504 fi
1505 res=$?
1506 done
1507
1508 return $SUCCESS
1509}
1510
1511reinitialize_keyring()
1512{
1513
1514 title "Base System Setup > Keyring Reinitialization"
1515
1516 wprintf "[+] Reinitializing keyrings"
1517 printf "\n"
1518 sleep 2
1519
1520 chroot $CHROOT pacman -S --overwrite='*' --noconfirm archlinux-keyring \
1521 > $VERBOSE 2>&1
1522
1523 return $SUCCESS
1524
1525}
1526
1527# install extra (missing) packages
1528setup_extra_packages()
1529{
1530 arch="arch-install-scripts pkgfile"
1531
1532 bluetooth="bluez bluez-hid2hci bluez-tools bluez-utils"
1533
1534 browser="chromium elinks firefox"
1535
1536 editor="hexedit vim"
1537
1538 filesystem="btrfs-progs cifs-utils dmraid dosfstools exfat-utils f2fs-tools
1539 gpart gptfdisk mtools nilfs-utils ntfs-3g partclone parted partimage"
1540
1541 fonts="ttf-dejavu ttf-freefont ttf-indic-otf ttf-liberation xorg-fonts-alias
1542 xorg-fonts-misc"
1543
1544 kernel="linux-headers"
1545
1546 misc="acpi alsa-utils b43-fwcutter bash-completion bc cmake ctags expac
1547 feh git gpm haveged hdparm htop inotify-tools ipython irssi intel-ucode
1548 linux-atm lsof mercurial mesa mlocate moreutils mpv p7zip rsync
1549 rtorrent screen scrot smartmontools strace tmux udisks2 unace unrar
1550 unzip upower usb_modeswitch zip zsh"
1551
1552 network="atftp bind-tools bridge-utils curl darkhttpd dhclient dialog dnscrypt-proxy
1553 dnsmasq dnsutils fwbuilder gnu-netcat ipw2100-fw ipw2200-fw iw lftp nfs-utils
1554 ntp openconnect openssh openvpn ppp pptpclient rfkill rp-pppoe
1555 socat vpnc wget wicd wicd-gtk wireless_tools wpa_supplicant wvdial xl2tpd"
1556
1557 xorg="xf86-video-amdgpu xf86-video-ati xf86-video-dummy xf86-video-fbdev
1558 xf86-video-intel xf86-video-nouveau xf86-video-openchrome xf86-video-sisusb
1559 xf86-video-vesa xf86-video-voodoo xorg-server xorg-xinit xterm"
1560
1561 all="$arch $bluetooth $browser $editor $filesystem"
1562 all="$all $fonts $kernel $misc $network $xorg"
1563
1564 title "Base System Setup > Extra Packages"
1565
1566 wprintf "[+] Installing extra packages"
1567 printf "\n"
1568
1569 printf "
1570 > ArchLinux : `echo $arch | wc -w` packages
1571 > Browser : `echo $browser | wc -w` packages
1572 > Bluetooth : `echo $bluetooth | wc -w` packages
1573 > Editor : `echo $editor | wc -w` packages
1574 > Filesystem : `echo $filesystem | wc -w` packages
1575 > Fonts : `echo $fonts | wc -w` packages
1576 > Misc : `echo $misc | wc -w` packages
1577 > Network : `echo $network | wc -w` packages
1578 > Xorg : `echo $xorg | wc -w` packages
1579 \n"
1580
1581 warn "This can take a while, please wait..."
1582 printf "\n"
1583 sleep 2
1584
1585 chroot $CHROOT pacman -S --needed --overwrite='*' --noconfirm $(echo $all) \
1586 > $VERBOSE 2>&1
1587
1588 return $SUCCESS
1589}
1590
1591
1592# perform system base setup/configurations
1593setup_base_system()
1594{
1595 if [ "$INSTALL_MODE" = "$INSTALL_LIVE_ISO" ]
1596 then
1597 dump_live_iso
1598 sleep_clear 1
1599 fi
1600
1601 if [ "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
1602 then
1603 pass_mirror_conf # copy mirror list to chroot env
1604
1605 setup_resolvconf
1606 sleep_clear 1
1607
1608 install_base_packages
1609 sleep_clear 1
1610
1611 setup_resolvconf
1612 sleep_clear 1
1613 fi
1614
1615 setup_fstab
1616 sleep_clear 1
1617
1618 setup_proc_sys_dev
1619 sleep_clear 1
1620
1621 setup_locale
1622 sleep_clear 1
1623
1624 setup_initramfs
1625 sleep_clear 1
1626
1627 setup_hostname
1628 sleep_clear 1
1629
1630 setup_user "root"
1631 sleep_clear 1
1632
1633 ask_user_account
1634 sleep_clear 1
1635
1636 if [ ! -z "$NORMAL_USER" ]
1637 then
1638 setup_user "$NORMAL_USER"
1639 sleep_clear 1
1640 else
1641 setup_testuser
1642 sleep_clear 2
1643 fi
1644
1645 if [ "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
1646 then
1647 reinitialize_keyring
1648 sleep_clear 1
1649 setup_extra_packages
1650 sleep_clear 1
1651 fi
1652
1653 setup_bootloader
1654 sleep_clear 1
1655
1656 return $SUCCESS
1657}
1658
1659
1660# enable iptables services
1661enable_iptables()
1662{
1663 title "BlackArch Linux Setup > Iptables"
1664
1665 wprintf "[+] Enabling iptables and ip6tables"
1666 printf "\n\n"
1667
1668 chroot $CHROOT systemctl enable iptables > $VERBOSE 2>&1
1669 chroot $CHROOT systemctl enable ip6tables > $VERBOSE 2>&1
1670
1671 return $SUCCESS
1672}
1673
1674
1675# update /etc files and set up iptables
1676update_etc()
1677{
1678 title "BlackArch Linux Setup > Etc files"
1679
1680 wprintf "[+] Updating /etc files"
1681 printf "\n\n"
1682
1683 # /etc/*
1684 cp -r "$BI_PATH/data/etc/"{arch-release,iptables,issue,motd,\
1685os-release,sysctl.d,X11,xprofile} "$CHROOT/etc/." > $VERBOSE 2>&1
1686
1687 return $SUCCESS
1688}
1689
1690
1691# ask for blackarch linux mirror
1692ask_mirror()
1693{
1694 title "BlackArch Linux Setup > BlackArch Mirror"
1695
1696 local IFS='|'
1697 count=1
1698 mirror_url="https://raw.githubusercontent.com/BlackArch/blackarch/master/mirror/mirror.lst"
1699 mirror_file="/tmp/mirror.lst"
1700
1701 wprintf "[+] Fetching mirror list"
1702 printf "\n\n"
1703 curl -s -o $mirror_file $mirror_url > $VERBOSE 2>&1
1704
1705 while read -r country url mirror_name
1706 do
1707 wprintf " %s. %s - %s" "$count" "$country" "$mirror_name"
1708 printf "\n"
1709 wprintf " * %s" "$url"
1710 printf "\n"
1711 count=`expr $count + 1`
1712 done < "$mirror_file"
1713
1714 printf "\n"
1715 wprintf "[?] Select a mirror number (enter for default): "
1716 read a
1717 printf "\n"
1718
1719 # bugfix: detected chars added sometimes - clear chars
1720 _a=`printf "%s" $a | sed 's/[a-z]//Ig' 2> /dev/null`
1721
1722 if [ -z "$_a" ]
1723 then
1724 wprintf "[+] Choosing default mirror: %s " $BA_REPO_URL
1725 else
1726 BA_REPO_URL=`sed -n "${_a}p" $mirror_file | cut -d "|" -f 2`
1727 wprintf "[+] Mirror from '%s' selected" \
1728 `sed -n "${_a}p" $mirror_file | cut -d "|" -f 3`
1729 printf "\n\n"
1730 fi
1731
1732 rm -f $mirror_file
1733
1734 return $SUCCESS
1735}
1736
1737# ask for archlinux server
1738ask_mirror_arch()
1739{
1740 declare mirrold="cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup"
1741
1742 if confirm "Pacman Setup > ArchLinux Mirrorlist" \
1743 "[+] Worldwide mirror will be used\n\n[?] Look for the best server [y/n]: "
1744 then
1745 printf "\n"
1746 warn "This may take time depending on your connection"
1747 printf "\n"
1748 $mirrold
1749 pacman -Sy --noconfirm > $VERBOSE 2>&1
1750 pacman -S --needed --noconfirm reflector > $VERBOSE 2>&1
1751 yes | pacman -Scc > $VERBOSE 2>&1
1752 reflector --verbose --latest 10 --protocol https --sort rate \
1753 --save /etc/pacman.d/mirrorlist > $VERBOSE 2>&1
1754 else
1755 printf "\n"
1756 warn "Using Worldwide mirror server"
1757 $mirrold
1758 echo -e "## Arch Linux repository Worldwide mirrorlist\n\n" \
1759 > /etc/pacman.d/mirrorlist
1760
1761 for wore in $AR_REPO_URL
1762 do
1763 echo "Server = $wore" >> /etc/pacman.d/mirrorlist
1764 done
1765 fi
1766
1767}
1768
1769# pass correct config
1770pass_mirror_conf()
1771{
1772 mkdir -p "$CHROOT/etc/pacman.d/" > $VERBOSE 2>&1
1773 cp -f /etc/pacman.d/mirrorlist "$CHROOT/etc/pacman.d/mirrorlist" \
1774 > $VERBOSE 2>&1
1775}
1776
1777
1778# run strap.sh
1779run_strap_sh()
1780{
1781 strap_sh="/tmp/strap.sh"
1782 orig_sha1="$(curl -s https://blackarch.org/checksums/strap | awk '{print $1}')"
1783
1784 title "BlackArch Linux Setup > Strap"
1785
1786 wprintf "[+] Downloading and executing strap.sh"
1787 printf "\n\n"
1788 warn "This can take a while, please wait..."
1789 printf "\n"
1790
1791 curl -s -o $strap_sh "https://www.blackarch.org/strap.sh" > $VERBOSE 2>&1
1792 sha1="$(sha1sum $strap_sh | awk '{print $1}')"
1793
1794 if [ "$sha1" = "$orig_sha1" ]
1795 then
1796 mv $strap_sh "${CHROOT}${strap_sh}"
1797 chmod a+x "${CHROOT}${strap_sh}"
1798 chroot $CHROOT echo $BA_REPO_URL | sh ${CHROOT}${strap_sh} > $VERBOSE 2>&1
1799 else
1800 err "Wrong SHA1 sum for strap.sh: $sha1 (orig: $orig_sha1). Aborting!"
1801 fi
1802
1803 # add blackarch linux mirror if we are in chroot
1804 if ! grep -q "blackarch" "$CHROOT/etc/pacman.conf"
1805 then
1806 printf '[blackarch]\nServer = %s\n' $BA_REPO_URL \
1807 >> "$CHROOT/etc/pacman.conf"
1808 else
1809 sed -i "/\[blackarch\]/{ n;s?Server.*?Server = $BA_REPO_URL?; }" \
1810 "$CHROOT/etc/pacman.conf"
1811 fi
1812
1813 return $SUCCESS
1814}
1815
1816
1817# ask user for X (display + window manager) setup
1818ask_x_setup()
1819{
1820 if confirm "BlackArch Linux Setup > X11" "[?] Setup X11 + window managers [y/n]: "
1821 then
1822 X_SETUP=$TRUE
1823 printf "\n"
1824 printf "${BLINK}NOOB! NOOB! NOOB! NOOB! NOOB! NOOB! NOOB!${NC}\n\n"
1825 fi
1826
1827 return $SUCCESS
1828}
1829
1830
1831# setup display manager
1832setup_display_manager()
1833{
1834 title "BlackArch Linux Setup > Display Manager"
1835
1836 wprintf "[+] Setting up LXDM"
1837 printf "\n"
1838
1839 # install lxdm packages
1840 chroot $CHROOT pacman -S lxdm --needed --overwrite='*' --noconfirm \
1841 > $VERBOSE 2>&1
1842
1843 # config files
1844 cp -r "$BI_PATH/data/etc/lxdm/." "$CHROOT/etc/lxdm/."
1845 cp -r "$BI_PATH/data/usr/share/lxdm/." "$CHROOT/usr/share/lxdm/."
1846 cp -r "$BI_PATH/data/usr/share/xsessions" "$CHROOT/usr/share/xsessions"
1847 cp -r "$BI_PATH/data/usr/share/gtk-2.0/." "$CHROOT/usr/share/gtk-2.0/."
1848
1849 # enable in systemd
1850 chroot $CHROOT systemctl enable lxdm > $VERBOSE 2>&1
1851
1852 return $SUCCESS
1853}
1854
1855
1856# setup window managers
1857setup_window_managers()
1858{
1859 title "BlackArch Linux Setup > Window Managers"
1860
1861 wprintf "[+] Setting up window managers"
1862 printf "\n"
1863
1864 while true
1865 do
1866 printf "
1867 1. Awesome
1868 2. Dwm
1869 3. Fluxbox
1870 4. I3-wm
1871 5. Openbox
1872 6. Spectrwm
1873 7. All of the above
1874 \n"
1875 wprintf "[?] Choose an option [7]: "
1876 read choice
1877 echo
1878 case $choice in
1879 1)
1880 chroot $CHROOT pacman -S awesome --needed --overwrite='*' --noconfirm \
1881 > $VERBOSE 2>&1
1882 cp -r "$BI_PATH/data/etc/xdg/awesome/." "$CHROOT/etc/xdg/awesome/."
1883 cp -r "$BI_PATH/data/usr/share/awesome/." "$CHROOT/usr/share/awesome/."
1884 # fix bullshit exit() issue
1885 sed -i 's|local visible, action = cmd(item, self)|local visible, action = cmd(0, 0)|' \
1886 "$CHROOT/usr/share/awesome/lib/awful/menu.lua"
1887 break
1888 ;;
1889 2)
1890 chroot $CHROOT pacman -S dwm --needed --overwrite='*' --noconfirm \
1891 > $VERBOSE 2>&1
1892 break
1893 ;;
1894 3)
1895 chroot $CHROOT pacman -S fluxbox --needed --overwrite='*' --noconfirm \
1896 > $VERBOSE 2>&1
1897 cp -r "$BI_PATH/data/usr/share/fluxbox/." "$CHROOT/usr/share/fluxbox/."
1898 break
1899 ;;
1900 4)
1901 chroot $CHROOT pacman -S i3-wm i3status i3lock dmenu --needed \
1902 --overwrite='*' --noconfirm > $VERBOSE 2>&1
1903 cp -r "$BI_PATH/data/root/"{.config,.i3status.conf} "$CHROOT/root/."
1904 break
1905 ;;
1906 5)
1907 chroot $CHROOT pacman -S openbox --needed --overwrite='*' --noconfirm \
1908 > $VERBOSE 2>&1
1909 cp -r "$BI_PATH/data/etc/xdg/openbox/." "$CHROOT/etc/xdg/openbox/."
1910 cp -r "$BI_PATH/data/usr/share/themes/blackarch" \
1911 "$CHROOT/usr/share/themes/i3lock/."
1912 break
1913 ;;
1914 6)
1915 chroot $CHROOT pacman -S spectrwm --needed --overwrite='*' --noconfirm \
1916 > $VERBOSE 2>&1
1917 cp -r "$BI_PATH/data/etc/spectrwm.conf" "$CHROOT/etc/spectrwm.conf"
1918 break
1919 ;;
1920 *)
1921 chroot $CHROOT pacman -S fluxbox openbox awesome i3-wm i3status \
1922 i3lock dwm spectrwm --needed --overwrite='*' --noconfirm \
1923 > $VERBOSE 2>&1
1924
1925 # awesome
1926 cp -r "$BI_PATH/data/etc/xdg/awesome/." "$CHROOT/etc/xdg/awesome/."
1927 cp -r "$BI_PATH/data/usr/share/awesome/." "$CHROOT/usr/share/awesome/."
1928 sed -i 's|local visible, action = cmd(item, self)|local visible, action = cmd(0, 0)|' \
1929 "$CHROOT/usr/share/awesome/lib/awful/menu.lua"
1930
1931 # fluxbox
1932 cp -r "$BI_PATH/data/usr/share/fluxbox/." "$CHROOT/usr/share/fluxbox/."
1933
1934 # i3
1935 cp -r "$BI_PATH/data/root/"{.config,.i3status.conf} "$CHROOT/root/."
1936
1937 # openbox
1938 cp -r "$BI_PATH/data/etc/xdg/openbox/." "$CHROOT/etc/xdg/openbox/."
1939 cp -r "$BI_PATH/data/usr/share/themes/blackarch" \
1940 "$CHROOT/usr/share/themes/."
1941
1942 # spectrwm
1943 cp -r "$BI_PATH/data/etc/spectrwm.conf" "$CHROOT/etc/spectrwm.conf"
1944
1945 break
1946 ;;
1947 esac
1948 done
1949
1950 # wallpaper
1951 cp -r "$BI_PATH/data/usr/share/blackarch" "$CHROOT/usr/share/blackarch"
1952
1953 # remove wrong xsession entries
1954 chroot $CHROOT rm /usr/share/xsessions/openbox-kde.desktop > $VERBOSE 2>&1
1955 chroot $CHROOT rm /usr/share/xsessions/i3-with-shmlog.desktop > $VERBOSE 2>&1
1956
1957 return $SUCCESS
1958}
1959
1960
1961# ask user for VirtualBox modules+utils setup
1962ask_vbox_setup()
1963{
1964 if confirm "BlackArch Linux Setup > VirtualBox" "[?] Setup VirtualBox modules [y/n]: "
1965 then
1966 VBOX_SETUP=$TRUE
1967 fi
1968
1969 return $SUCCESS
1970}
1971
1972
1973# setup virtualbox utils
1974setup_vbox_utils()
1975{
1976 title "BlackArch Linux Setup > VirtualBox"
1977
1978 wprintf "[+] Setting up VirtualBox utils"
1979 printf "\n\n"
1980
1981 chroot $CHROOT pacman -S virtualbox-guest-utils \
1982 virtualbox-guest-modules-arch --overwrite='*' --needed --noconfirm \
1983 > $VERBOSE 2>&1
1984
1985 chroot $CHROOT systemctl enable vboxservice > $VERBOSE 2>&1
1986
1987 printf "vboxguest\nvboxsf\nvboxvideo\n" \
1988 > "$CHROOT/etc/modules-load.d/vbox.conf"
1989
1990 cp -r "$BI_PATH/data/etc/xdg/autostart/vboxclient.desktop" "$CHROOT/etc/xdg/autostart/." > $VERBOSE 2>&1
1991
1992 return $SUCCESS
1993}
1994
1995
1996# ask user for VirtualBox modules+utils setup
1997ask_vmware_setup()
1998{
1999 if confirm "BlackArch Linux Setup > VMware" "[?] Setup VMware modules [y/n]: "
2000 then
2001 VMWARE_SETUP=$TRUE
2002 fi
2003
2004 return $SUCCESS
2005}
2006
2007
2008# setup vmware utils
2009setup_vmware_utils()
2010{
2011 title "BlackArch Linux Setup > VMware"
2012
2013 wprintf "[+] Setting up VMware utils"
2014 printf "\n\n"
2015
2016 chroot $CHROOT pacman -S open-vm-tools xf86-video-vmware \
2017 xf86-input-vmmouse --overwrite='*' --needed --noconfirm \
2018 > $VERBOSE 2>&1
2019
2020 chroot $CHROOT systemctl enable vmware-vmblock-fuse.service > $VERBOSE 2>&1
2021 chroot $CHROOT systemctl enable vmtoolsd.service > $VERBOSE 2>&1
2022
2023 return $SUCCESS
2024}
2025
2026
2027# ask user for BlackArch tools setup
2028ask_ba_tools_setup()
2029{
2030 if confirm "BlackArch Linux Setup > Tools" "[?] Setup BlackArch Linux tools [y/n]: "
2031 then
2032 BA_TOOLS_SETUP=$TRUE
2033 fi
2034
2035 return $SUCCESS
2036}
2037
2038
2039# setup blackarch tools from repository (binary) or via blackman (source)
2040setup_blackarch_tools()
2041{
2042 foo=5
2043
2044 if [ "$VERBOSE" = "/dev/null" ]
2045 then
2046 noconfirm='--noconfirm'
2047 fi
2048
2049 title "BlackArch Linux Setup > Tools"
2050
2051 wprintf "[+] Installing BlackArch Linux packages (grab a coffee)"
2052 printf "\n\n"
2053
2054 if [ $INSTALL_MODE = $INSTALL_REPO ]
2055 then
2056 wprintf "[+] All available BlackArch tools groups:\n\n"
2057 printf "blackarch blackarch-anti-forensic blackarch-automation
2058blackarch-backdoor blackarch-binary blackarch-bluetooth blackarch-code-audit
2059blackarch-cracker blackarch-crypto blackarch-database blackarch-debugger
2060blackarch-decompiler blackarch-defensive blackarch-disassembler blackarch-dos
2061blackarch-drone blackarch-exploitation blackarch-fingerprint blackarch-firmware
2062blackarch-forensic blackarch-fuzzer blackarch-hardware blackarch-honeypot
2063blackarch-ids blackarch-keylogger blackarch-malware blackarch-misc
2064blackarch-mobile blackarch-networking blackarch-nfc blackarch-packer
2065blackarch-proxy blackarch-recon blackarch-reversing blackarch-scanner
2066blackarch-sniffer blackarch-social blackarch-spoof blackarch-threat-model
2067blackarch-tunnel blackarch-unpacker blackarch-voip blackarch-webapp
2068blackarch-windows blackarch-wireless \n\n"
2069 wprintf "[?] BlackArch groups to install (space for multiple) [blackarch]: "
2070 read BA_GROUPS
2071 printf "\n"
2072 warn "This can take a while, please wait..."
2073 if [ -z "$BA_GROUPS" ]
2074 then
2075 printf "\n"
2076 check_space
2077 printf "\n\n"
2078 chroot $CHROOT pacman -S --needed --noconfirm --overwrite='*' blackarch \
2079 > $VERBOSE 2>&1
2080 else
2081 chroot $CHROOT pacman -S --needed --noconfirm --overwrite='*' $BA_GROUPS \
2082 > $VERBOSE 2>&1
2083 fi
2084 else
2085 warn "Installing all tools from source via blackman can take hours"
2086 printf "\n"
2087 wprintf "[+] <Control-c> to abort ... "
2088 while [ $foo -gt 0 ]
2089 do
2090 wprintf "$foo "
2091 sleep 1
2092 foo=`expr $foo - 1`
2093 done
2094 printf "\n"
2095 chroot $CHROOT pacman -S --needed --overwrite='*' $noconfirm blackman \
2096 > $VERBOSE 2>&1
2097 chroot $CHROOT blackman -a > $VERBOSE 2>&1
2098 fi
2099
2100 return $SUCCESS
2101}
2102
2103
2104# add user to newly created groups
2105update_user_groups()
2106{
2107 title "BlackArch Linux Setup > User"
2108
2109 wprintf "[+] Adding user $user to groups"
2110 printf "\n\n"
2111
2112 # TODO: more to add here
2113 if [ $VBOX_SETUP -eq $TRUE ]
2114 then
2115 chroot $CHROOT usermod -aG "vboxsf" "$user" > $VERBOSE 2>&1
2116 fi
2117
2118 return $SUCCESS
2119}
2120
2121
2122# dump data from the live-iso
2123dump_live_iso()
2124{
2125 live_dirs="/bin /sbin /etc /home /lib /lib64 /opt /root /srv /usr /var /tmp"
2126
2127 total_size=0 # no cheat
2128
2129 title "BlackArch Linux Setup"
2130
2131 wprintf "[+] Dumping data from Live-ISO. Grab a coffee and pop shells!"
2132 printf "\n\n"
2133
2134 wprintf "[+] Fetching total size to transfer, please wait..."
2135 printf "\n"
2136
2137 for d in $live_dirs
2138 do
2139 part_size=$(du -sm $d 2> /dev/null | awk '{print $1}')
2140 ((total_size+=part_size))
2141 printf "
2142 > $d $part_size MB"
2143 done
2144 printf "\n"
2145 printf "
2146 [ Total size = $total_size MB ]"
2147 printf "\n\n"
2148
2149 check_space
2150
2151 wprintf "[+] Installing the backdoors to /"
2152 printf "\n\n"
2153 warn "This can take a while, please wait... "
2154 printf "\n"
2155 rsync -aWx --human-readable --info=progress2 / $CHROOT > $VERBOSE 2>&1
2156 wprintf "[+] Installation done!\n"
2157
2158 # clean up files
2159 wprintf "[+] Cleaning Live Environment files, please wait... "
2160 sed -i 's/Storage=volatile/#Storage=auto/' ${CHROOT}/etc/systemd/journald.conf
2161 rm -rf "$CHROOT/etc/udev/rules.d/81-dhcpcd.rules"
2162 rm -rf "$CHROOT/etc/systemd/system/"{choose-mirror.service,pacman-init.service,etc-pacman.d-gnupg.mount,getty@tty1.service.d}
2163 rm -rf "$CHROOT/etc/systemd/scripts/choose-mirror"
2164 rm -rf "$CHROOT/etc/systemd/system/getty@tty1.service.d/autologin.conf"
2165 rm -rf "$CHROOT/root/"{.automated_script.sh,.zlogin}
2166 rm -rf "$CHROOT/etc/mkinitcpio-archiso.conf"
2167 rm -rf "$CHROOT/etc/initcpio"
2168 #rm -rf ${CHROOT}/etc/{group*,passwd*,shadow*,gshadow*}
2169 wprintf "done\n"
2170
2171 return $SUCCESS
2172}
2173
2174
2175# setup blackarch related stuff
2176setup_blackarch()
2177{
2178 update_etc
2179 sleep_clear 1
2180
2181 enable_iptables
2182 sleep_clear 1
2183
2184 ask_mirror
2185 sleep_clear 1
2186
2187 run_strap_sh
2188 sleep_clear 1
2189
2190 ask_x_setup
2191 sleep_clear 3
2192
2193 if [ $X_SETUP -eq $TRUE ]
2194 then
2195 setup_display_manager
2196 sleep_clear 1
2197 setup_window_managers
2198 sleep_clear 1
2199 fi
2200
2201 ask_vbox_setup
2202 sleep_clear 1
2203
2204 if [ $VBOX_SETUP -eq $TRUE ]
2205 then
2206 setup_vbox_utils
2207 sleep_clear 1
2208 fi
2209
2210 ask_vmware_setup
2211 sleep_clear 1
2212
2213 if [ $VMWARE_SETUP -eq $TRUE ]
2214 then
2215 setup_vmware_utils
2216 sleep_clear 1
2217 fi
2218
2219 sleep_clear 1
2220
2221 enable_pacman_multilib "chroot"
2222 sleep_clear 1
2223
2224 enable_pacman_color "chroot"
2225 sleep_clear 1
2226
2227 ask_ba_tools_setup
2228 sleep_clear 1
2229
2230 if [ $BA_TOOLS_SETUP -eq $TRUE ]
2231 then
2232 setup_blackarch_tools
2233 sleep_clear 1
2234 fi
2235
2236 if [ -n "$NORMAL_USER" ]
2237 then
2238 update_user_groups
2239 sleep_clear 1
2240 fi
2241
2242 return $SUCCESS
2243}
2244
2245
2246# for fun and lulz
2247easter_backdoor()
2248{
2249 foo=0
2250
2251 title "Game Over"
2252
2253 wprintf "[+] BlackArch Linux installation successfull!"
2254 printf "\n\n"
2255
2256 wprintf "Yo n00b, b4ckd00r1ng y0ur sy5t3m n0w "
2257 while [ $foo -ne 5 ]
2258 do
2259 wprintf "."
2260 sleep 1
2261 foo=`expr $foo + 1`
2262 done
2263 printf " >> ${BLINK}${WHITE}HACK THE PLANET! D00R THE PLANET!${NC} <<"
2264 printf "\n\n"
2265
2266 return $SUCCESS
2267}
2268
2269
2270# perform sync
2271sync_disk()
2272{
2273 title "Game Over"
2274
2275 wprintf "[+] Syncing disk"
2276 printf "\n\n"
2277
2278 sync
2279
2280 return $SUCCESS
2281}
2282
2283
2284# check if new version available. perform self-update and exit
2285self_updater()
2286{
2287 title "Self Updater"
2288 wprintf "[+] Checking for a new version of myself..."
2289 printf "\n\n"
2290
2291 pacman -Syy > $VERBOSE 2>&1
2292 ver="v$(pacman -Ss blackarch-installer | head -1 | cut -d ' ' -f 2 |
2293 cut -d '-' -f 1)"
2294
2295 if [ "$ver" != "$VERSION" ]
2296 then
2297 printf "\n\n"
2298 warn "A new version is available! Going to fuck, err, update myself."
2299 pacman -S --overwrite='*' --noconfirm blackarch-installer > $VERBOSE 2>&1
2300 yes | pacman -Scc > $VERBOSE 2>&1
2301 wprintf "\n[+] Updated successfully. Please restart the installer now!\n"
2302 chmod +x /usr/share/blackarch-installer/blackarch-install
2303 exit $SUCCESS
2304 fi
2305
2306 return $SUCCESS
2307}
2308
2309
2310# controller and program flow
2311main()
2312{
2313 # do some ENV checks
2314 sleep_clear 0
2315 check_uid
2316 check_env
2317 check_boot_mode
2318 check_iso_type
2319
2320 # install mode
2321 ask_install_mode
2322
2323 # output mode
2324 ask_output_mode
2325 sleep_clear 0
2326
2327 # locale
2328 ask_locale
2329 set_locale
2330 sleep_clear 0
2331
2332 # keymap
2333 ask_keymap
2334 set_keymap
2335 sleep_clear 0
2336
2337 # network
2338 ask_hostname
2339 sleep_clear 0
2340
2341 if [ "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
2342 then
2343 get_net_ifs
2344 ask_net_conf_mode
2345 if [ "$NET_CONF_MODE" != "$NET_CONF_SKIP" ]
2346 then
2347 ask_net_if
2348 fi
2349 case "$NET_CONF_MODE" in
2350 "$NET_CONF_AUTO")
2351 net_conf_auto
2352 ;;
2353 "$NET_CONF_WLAN")
2354 ask_wlan_data
2355 net_conf_wlan
2356 ;;
2357 "$NET_CONF_MANUAL")
2358 ask_net_addr
2359 net_conf_manual
2360 ;;
2361 "$NET_CONF_SKIP")
2362 ;;
2363 *)
2364 ;;
2365 esac
2366 sleep_clear 1
2367 check_inet_conn
2368 sleep_clear 1
2369
2370 # self updater
2371 self_updater
2372 sleep_clear 1
2373
2374 # pacman
2375 ask_mirror_arch
2376 sleep_clear 1
2377 update_pacman
2378 fi
2379
2380 # hard drive
2381 get_hd_devs
2382 ask_hd_dev
2383 umount_filesystems "harddrive"
2384 sleep_clear 1
2385 ask_cfdisk
2386 sleep_clear 3
2387 ask_luks
2388 get_partition_label
2389 ask_partitions
2390 print_partitions
2391 ask_formatting
2392 clear
2393 make_partitions
2394 clear
2395 mount_filesystems
2396 sleep_clear 1
2397
2398 # arch linux
2399 setup_base_system
2400 sleep_clear 1
2401 setup_time
2402 sleep_clear 1
2403
2404 # blackarch Linux
2405 if [ "$INSTALL_MODE" != "$INSTALL_LIVE_ISO" ]
2406 then
2407 setup_blackarch
2408 sleep_clear 1
2409 fi
2410
2411 # epilog
2412 umount_filesystems
2413 sleep_clear 1
2414 sync_disk
2415 sleep_clear 1
2416 easter_backdoor
2417
2418 return $SUCCESS
2419}
2420
2421
2422# we start here
2423main "$@"
2424
2425
2426# EOF