-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathstrap.sh
230 lines (188 loc) · 4.59 KB
/
strap.sh
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
#!/bin/sh
# strap.sh - setup BlackArch Linux keyring and install initial packages
ARCH=$(uname -m)
# mirror file to fetch and write
MIRROR_F='blackarch-mirrorlist'
GPG_CONF='/etc/pacman.d/gnupg/gpg.conf'
# simple error message wrapper
err()
{
echo >&2 "$(tput bold; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)"
exit 1337
}
# simple warning message wrapper
warn()
{
echo >&2 "$(tput bold; tput setaf 1)[!] WARNING: ${*}$(tput sgr0)"
}
# simple echo wrapper
msg()
{
echo "$(tput bold; tput setaf 2)[+] ${*}$(tput sgr0)"
}
# check for root privilege
check_priv()
{
if [ "$(id -u)" -ne 0 ]; then
err "you must be root"
fi
}
# make a temporary directory and cd into
make_tmp_dir()
{
tmp="$(mktemp -d /tmp/blackarch_strap.XXXXXXXX)"
trap 'rm -rf $tmp' EXIT
cd "$tmp" || err "Could not enter directory $tmp"
}
set_umask()
{
OLD_UMASK=$(umask)
umask 0022
trap 'reset_umask' TERM
}
reset_umask()
{
umask $OLD_UMASK
}
check_internet()
{
tool='curl'
tool_opts='-s --connect-timeout 8'
if ! $tool $tool_opts https://blackarch.org/ > /dev/null 2>&1; then
err "You don't have an Internet connection!"
fi
return $SUCCESS
}
# add necessary GPG options
add_gpg_opts()
{
# tmp fix for SHA-1 + >= gpg-2.4 versions
if ! grep -q 'allow-weak-key-signatures' $GPG_CONF
then
echo 'allow-weak-key-signatures' >> $GPG_CONF
fi
return $SUCCESS
}
# retrieve the BlackArch Linux keyring
fetch_keyring()
{
curl -s -O \
'https://www.blackarch.org/keyring/blackarch-keyring.pkg.tar.zst'
curl -s -O \
'https://www.blackarch.org/keyring/blackarch-keyring.pkg.tar.zst.sig'
}
# verify the keyring signature
# note: this is pointless if you do not verify the key fingerprint
verify_keyring()
{
if ! gpg --keyserver keyserver.ubuntu.com \
--recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1
then
if ! gpg --keyserver hkps://keyserver.ubuntu.com:443 \
--recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1
then
if ! gpg --keyserver hkp://pgp.mit.edu:80 \
--recv-keys 4345771566D76038C7FEB43863EC0ADBEA87E4E3 > /dev/null 2>&1
then
err "could not verify the key. Please check: https://blackarch.org/faq.html"
fi
fi
fi
if ! gpg --keyserver-options no-auto-key-retrieve \
--with-fingerprint blackarch-keyring.pkg.tar.zst.sig > /dev/null 2>&1
then
err "invalid keyring signature. please stop by https://matrix.to/#/#/BlackaArch:matrix.org"
fi
}
# delete the signature files
delete_signature()
{
if [ -f "blackarch-keyring.pkg.tar.zst.sig" ]; then
rm blackarch-keyring.pkg.tar.zst.sig
fi
}
# make sure /etc/pacman.d/gnupg is usable
check_pacman_gnupg()
{
pacman-key --init
}
# install the keyring
install_keyring()
{
if ! pacman --config /dev/null --noconfirm \
-U blackarch-keyring.pkg.tar.zst ; then
err 'keyring installation failed'
fi
# just in case
pacman-key --populate
}
# ask user for mirror
get_mirror()
{
mirror_p="/etc/pacman.d"
mirror_r="https://blackarch.org"
msg "fetching new mirror list..."
if ! curl -s "$mirror_r/$MIRROR_F" -o "$mirror_p/$MIRROR_F" ; then
err "we couldn't fetch the mirror list from: $mirror_r/$MIRROR_F"
fi
msg "you can change the default mirror under $mirror_p/$MIRROR_F"
}
# update pacman.conf
update_pacman_conf()
{
# delete blackarch related entries if existing
sed -i '/blackarch/{N;d}' /etc/pacman.conf
cat >> "/etc/pacman.conf" << EOF
[blackarch]
Include = /etc/pacman.d/$MIRROR_F
EOF
}
# synchronize and update
pacman_update()
{
if pacman -Syy; then
return $SUCCESS
fi
warn "Synchronizing pacman has failed. Please try manually: pacman -Syy"
return $FAILURE
}
pacman_upgrade()
{
echo 'perform full system upgrade? (pacman -Su) [Yn]:'
read conf < /dev/tty
case "$conf" in
''|y|Y) pacman -Su ;;
n|N) warn 'some blackarch packages may not work without an up-to-date system.' ;;
esac
}
# setup blackarch linux
blackarch_setup()
{
msg 'installing blackarch keyring...'
check_priv
set_umask
make_tmp_dir
check_internet
add_gpg_opts
fetch_keyring
#verify_keyring
delete_signature
check_pacman_gnupg
install_keyring
echo
msg 'keyring installed successfully'
# check if pacman.conf has already a mirror
if ! grep -q "\[blackarch\]" /etc/pacman.conf; then
msg 'configuring pacman'
get_mirror
msg 'updating pacman.conf'
update_pacman_conf
fi
msg 'updating package databases'
pacman_update
reset_umask
msg 'installing blackarch-officials meta-package...'
pacman -S --noconfirm --needed blackarch-officials
msg 'BlackArch Linux is ready!'
}
blackarch_setup