-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·285 lines (245 loc) · 8.25 KB
/
install.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
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
#!/bin/bash
# File generated automatically by build.sh. Do not modify
# DO NOT MODIFY
#!/bin/bash
enum ()
{
# skip index ???
shift
AA=${@##*\{} # get string strip after {
AA=${AA%\}*} # get string strip before }
AA=${AA//,/} # delete commaa
((DEBUG)) && echo $AA
local I=0
for A in $AA ; do
eval "$A=$I"
((I++))
done
}
enum VERSION_TYPE { STABLE, DEV, DEV_DETACHED, NO_GIT };
VERBOSE=0
while getopts ":v" option; do
case "${option}" in
v)
VERBOSE=1
;;
*)
echo "Usage: $0 [-v]"
exit 1
;;
esac
done
shift "$((OPTIND-1))"
LOGS=/dev/null
INSTALLATION_FOLDER="$HOME/shurikenpi"
GIT_FOLDER="$HOME/shurikenpi/shurikenpi.io"
TMP_DIRECTORY=/tmp/shuriken_io
ARCHITECTURE=$(uname -m)
rm -fr $TMP_DIRECTORY 2>&1
mkdir $TMP_DIRECTORY 2>&1
GIT_URL=https://github.com/Urban-Hacker/shurikenpi.io/
if command -v screen >/dev/null 2>&1; then
SESSION_COUNT=$(screen -ls | grep -c "\.shurikenpi.io")
else
SESSION_COUNT=0
fi
extract_version(){
INSTALLED_VERSION=""
INSTALLED_TYPE=""
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
INSTALLED_VERSION="NO GIT"
INSTALLED_TYPE=$NO_GIT
return 0
fi
local branch=$(git rev-parse --abbrev-ref HEAD)
local tag=$(git describe --tags --abbrev=0 2>/dev/null)
local commit_hash=$(git rev-parse HEAD)
local commit_hash=${commit_hash:0:5}
if [[ "$branch" == "HEAD" ]]; then
INSTALLED_VERSION="$commit_hash (dev)"
INSTALLED_TYPE=$DEV_DETACHED
else
if [[ "$branch" == "stable" && -n "$tag" ]]; then
INSTALLED_VERSION="$tag"
INSTALLED_TYPE=$STABLE
else
INSTALLED_VERSION="$commit_hash (dev)"
INSTALLED_TYPE=$DEV
fi
fi
}
extract_version
#!/bin/bash
r(){
p $1
while read -t 0; do :; done
read -p " › " $2
}
p() {
echo -e " » $1"
sleep 0.1
}
p_user() {
echo -e " \e[35m› $1\033[0m"
sleep 0.1
}
p_err(){
echo -e " \033[31m»\033[0m $1"
sleep 0.1
}
p_fatal(){
echo -e " \033[31m» $1\033[0m"
sleep 0.1
}
p_ok(){
echo -e " \033[32m»\033[0m $1"
sleep 0.1
}
p_warn(){
echo -e " \033[33m!\033[0m $1"
sleep 0.1
}
msg() {
echo ""
sleep 0.1
while IFS= read -r line
do
echo -e "$line"
sleep 0.1
done < "../Messages/$1"
echo "$line"
sleep 0.1
echo ""
sleep 0.1
}
ask_yes_or_no(){
echo -e " \033[33m?\033[0m $1"
local result=$(gum choose --cursor= › Yes No)
if [[ $result == "Yes" ]]; then
p_user "Yes"
return 0
fi
p_user "No"
return 1
}
user_pause(){
local result=$(gum choose --cursor= › Continue)
p_user "Continue"
}
spin_it(){
local msg=$1
shift
local command=$@
local hash=$(echo -n "$command" | md5sum | awk '{print $1}')
local logfile="$TMP_DIRECTORY/$hash.txt"
"$@" > $logfile 2>&1 &
chars=(" ⠋ " " ⠙ " " ⠹ " " ⠸ " " ⠼ " " ⠴ " " ⠦ " " ⠧ " " ⠇ " " ⠏ ")
pid=$!
while kill -0 $pid 2> /dev/null; do
for char in "${chars[@]}"; do
echo -ne "\r$char"
sleep 0.1
done
done
wait $pid
local exit_status=$?
echo -ne "\r\033[K"
if [ $exit_status -eq 0 ]; then
p $msg
else
p_fatal "$msg [FATAL ERROR]"
p_fatal "--- BEGIN ERROR DUMP ---"
awk '{print " \033[31m " $0 "\033[0m"}' $logfile
p_fatal "--- END ERROR DUMP ---"
exit 1
fi
if [ $VERBOSE -eq 1 ]; then
awk '{print " ‣ " $0}' $logfile
echo ""
fi
}
install_prerequisites(){
p "Installing pre-requisites..."
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --batch --yes --dearmor -o /etc/apt/keyrings/charm.gpg
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list >/dev/null
if [[ "$ARCHITECTURE" == "aarch64" ]]; then
spin_it "dpkg --add-architecture armhf \033[32m✓\033[0m" sudo dpkg --add-architecture armhf
fi
spin_it "Update cache..." sudo apt update
spin_it "apt install gum \033[32m✓\033[0m" sudo apt-get install -y gum
spin_it "apt install git \033[32m✓\033[0m" sudo apt-get install -y git
spin_it "apt install tor \033[32m✓\033[0m" sudo apt-get install -y tor
spin_it "apt install curl \033[32m✓\033[0m" sudo apt-get install -y curl
spin_it "apt install screen \033[32m✓\033[0m" sudo apt-get install -y screen
if [[ "$ARCHITECTURE" == "aarch64" ]]; then
spin_it "apt install libc6:armhf \033[32m✓\033[0m" sudo apt-get install -y libc6:armhf
spin_it "apt install libstdc++6:armhf \033[32m✓\033[0m" sudo apt-get install -y libstdc++6:armhf
spin_it "apt install libcurl4:armhf \033[32m✓\033[0m" sudo apt-get install -y libcurl4:armhf
spin_it "apt install libssl1.1:armhf \033[32m✓\033[0m" sudo apt-get install -y libssl1.1:armhf
spin_it "apt install libjansson4:armhf \033[32m✓\033[0m" sudo apt-get install -y libjansson4:armhf
fi
}
go_to_install_directory(){
echo ""
p "Install directory will be: $INSTALLATION_FOLDER"
if [ -d $INSTALLATION_FOLDER ]; then
echo ""
p_warn "An existing installation of ShurikenPi was detected!"
ask_yes_or_no "Would you like to re-install ShurikenPi and wipe the existing installation?"
local result=$?
if [ $result == 0 ]; then
rm -fr $INSTALLATION_FOLDER
else
p_err "Fatal: Aborting the installation script now"
exit 1
fi
fi
mkdir $INSTALLATION_FOLDER
cd $INSTALLATION_FOLDER
}
check_if_root(){
echo ""
p "Root user check..."
if [[ $EUID -ne 0 ]]; then
echo ""
echo -e " ShurikenPi called with non-root priviledeges \033[31m:(\033[0m"
echo -e " Elevated priviledeges are required to install and run ShurikenPi"
echo -e " Please check the installer for any concerns about this requirement"
echo -e " Make sure you downloaded this script from a trusted source"
echo ""
if sudo true; then
p "Correct password."
else
p_err "Wrong password. Exiting."
exit 1
fi
fi
p_ok "We are root :)"
}
check_if_upgrade(){
UPGRADABLE_COUNT=$(apt list --upgradable 2>$LOGS| grep -c ^)
if (( UPGRADABLE_COUNT > 0 )); then
p_warn "There are $UPGRADABLE_COUNT packages that can be upgraded."
p_warn "It is recommended to run 'sudo apt upgrade' afterwards."
else
p "All packages are up to date."
fi
}
clone_repository(){
spin_it "Downloading ShurikenPi, please wait..." git clone $GIT_URL
}
# Entry point
check_if_root
echo ""
p "The next steps might take some time, be patient"
install_prerequisites
check_if_upgrade
go_to_install_directory
clone_repository
if ! grep -q "alias shuriken=" ~/.bashrc; then
echo "alias shuriken=$GIT_FOLDER/shuriken.sh" >> ~/.bashrc
fi
source ~/.bashrc
cd $GIT_FOLDER/
./shuriken.sh config