-
Notifications
You must be signed in to change notification settings - Fork 15
/
chroot-install
executable file
·382 lines (308 loc) · 9.18 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
#!/bin/bash
################################################################################
# #
# blackarchinstall - Blackarch Install #
# #
# FILE #
# chroot-install #
# #
# DATE #
# 2013-12-16 #
# #
# DESCRIPTION #
# Script for easy install #
# #
# AUTHOR #
# #
################################################################################
# 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
# BA REPO DEFAULT
BLACKARCH_REPO_URL='http://www.blackarch.org/blackarch/$repo/os/$arch'
# 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}"
}
# 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_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}"
}
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 wget installed
command -v wget >/dev/null 2>&1 ||
pacman -S wget --noconfirm
wget -q "${github_url}" -O "${mirror_file}"
[ "${?}" != "0" ] && wprintf "[-] wget failed - setting BlackArch repository" &&
return "${FAILURE}"
wprintf "[+] Select BlackArch Repository"
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 "%sSelect 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_system()
{
wprintf "[+] Adding BlackArch Official Repo"
select_ba_repo
[ "${?}" == "${FAILURE}" ] &&
wprintf "[-] Mirror selection failed - We go with default one..."
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
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_packages_repo()
{
pacman -S blackarch
return "${SUCCESS}"
}
install_grub()
{
pacman -S grub --noconfirm --needed
#wprintf "[+] Patching grub2 syntax error"
#printf "GRUB_DISABLE_SUBMENU=y\n" >> /etc/default/grub
# adding blackarch splash
mv /boot/splash.png /boot/grub/
printf 'GRUB_BACKGROUND="/boot/grub/splash.png"\n' >> /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
sed -i 's/Arch Linux, with Linux core repo kernel/BlackArch Linux/' \
/boot/grub/grub.cfg
sed -i 's/rw quiet/rw cryptdevice=\/dev\/sda3:cryptboot/' \
/boot/grub/grub.cfg
grub-install "${HD}"
#update-grub
return "${SUCCESS}"
}
# set passwd check
set_passwd()
{
user=${1}
if [ -n "${user}" ]; then
passwd "${user}"
else
passwd
fi
if [ "${?}" != "0" ]; then
wprintf "Wrong passwd - try again d00d"
set_passwd "${user}"
else
return "${SUCCESS}"
fi
return "${SUCCESS}"
}
configure_users()
{
printf "%s" "${WHITE}"
printf "[+] Setup root password\n"
set_passwd
mv /mnt/shell/root/.bashrc /root/
cp /root/.bashrc /root/.bash_profile
printf "[+] Do you want to 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_initfs()
{
sed -i 's/block filesystems/block encrypt filesystems/' /etc/mkinitcpio.conf
mkinitcpio -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
mkinitcpio -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-falback.img -S autodetect
#mkinitcpio -c /etc/mkinitcpio-archiso.conf -g /boot/blackarch-linux.img
return "${SUCCESS}"
}
install()
{
menu_opt=${1}
wprintf "[+] Installing packages..."
case "${menu_opt}" in
"live")
wprintf "[+] Updating system..."
update_system
;;
"repository")
wprintf "[+] Updating system..."
update_system
install_packages_repo
;;
"blackman")
install_packages_blackman
;;
esac
wprintf "[+] Configure system users..."
configure_users
wprintf "[+] Re-Generating initfs..."
generate_initfs
wprintf "[+] Setting blackarch hostname..."
hostname blackarch
wprintf "[+] Installing grub..."
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:vVH flags
do
case "${flags}" in
l)
opt_arg="live"
;;
r)
opt_arg="repository"
;;
b)
opt_arg="blackman"
;;
d)
HD=${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()
{
check_argc ${*}
get_opts ${*}
check_args ${*}
check_env
install "${opt_arg}"
return "${SUCCESS}"
}
# program start
main ${*}
# EOF