forked from WOnder93/argon2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-argon2.sh
142 lines (119 loc) · 5.18 KB
/
build-argon2.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
#!/bin/bash
#### COLOR SETTINGS ####
BLACK=$(tput setaf 0 && tput bold)
RED=$(tput setaf 1 && tput bold)
GREEN=$(tput setaf 2 && tput bold)
YELLOW=$(tput setaf 3 && tput bold)
BLUE=$(tput setaf 4 && tput bold)
MAGENTA=$(tput setaf 5 && tput bold)
CYAN=$(tput setaf 6 && tput bold)
WHITE=$(tput setaf 7 && tput bold)
BLACKbg=$(tput setab 0 && tput bold)
REDbg=$(tput setab 1 && tput bold)
GREENbg=$(tput setab 2 && tput bold)
YELLOWbg=$(tput setab 3 && tput bold)
BLUEbg=$(tput setab 4 && tput dim)
MAGENTAbg=$(tput setab 5 && tput bold)
CYANbg=$(tput setab 6 && tput bold)
WHITEbg=$(tput setab 7 && tput bold)
STAND=$(tput sgr0)
### System dialog VARS
showinfo="$GREEN[info]$STAND"
showerror="$RED[error]$STAND"
showexecute="$YELLOW[running]$STAND"
showok="$MAGENTA[OK]$STAND"
showdone="$BLUE[DONE]$STAND"
showinput="$CYAN[input]$STAND"
showwarning="$RED[warning]$STAND"
showremove="$GREEN[removing]$STAND"
shownone="$MAGENTA[none]$STAND"
redhashtag="$REDbg$WHITE#$STAND"
abortte="$CYAN[abort to Exit]$STAND"
showport="$YELLOW[PORT]$STAND"
##
### GENERAL_VARS
get_libtool=$(if [[ $(cat /etc/*release | grep -o -m 1 Ubuntu) ]]; then echo "$(apt-cache policy libtool | grep Installed | grep none | awk '{print$2}')"; else if [[ $(cat /etc/*release | grep -o -m 1 Debian) ]]; then echo "$(apt-cache policy libtool | grep Installed | grep none | awk '{print$2}')"; else if [[ $(cat /etc/*release | grep -o -m 1 centos) ]]; then echo "$(yum list libtool | grep -o Installed)"; fi fi fi)
###
#### Dependencies START
function deps(){
if [[ "$get_libtool" == "(none)" ]]; then
echo "$showinfo We need to install libtool"
if [[ $(cat /etc/*release | grep -o -m 1 Ubuntu) ]]; then sudo apt install -y libtool; else if [[ $(cat /etc/*release | grep -o -m 1 Debian) ]]; then sudo apt-get install -y libtool; else if [[ $(cat /etc/*release | grep -o -m 1 centos) ]]; then sudo yum install -y libtool; fi fi fi
else
if [[ "$get_libtool" == * ]]; then
echo "$showok libtool is already installed!"
fi
fi
}
#### Dependencies check END
deps # call deps function
if [[ $(pwd) =~ Node-WebDollar[[:alnum:]]+ || Node-WebDollar ]]; then
if [[ $(find . -type d -name argon2 | grep -x './argon2') == ./argon2 ]]; then
echo "$showinfo argon2 is already inside Node-WebDollar."
read -e -p "$showinput Do you want to compile argon2 again? (y or n): " yn_compile
if [[ $yn_compile == [nN] ]]; then
echo -e "$showinfo OK..."
elif [[ $yn_compile == [yY] ]]; then
echo "$showexecute Changing dir to ${YELLOW}argon2$STAND" && cd argon2
echo "$showexecute Compiling argon2..." && make
echo "$showexecute Going back to Node-WebDollar folder..." && cd ..
if [[ -d dist_bundle/CPU ]]; then
echo "$showok CPU folder inside dist_bundle exists!"
echo "$showexecute Copying argon2/* files to dist_bundle/CPU" && cp -a argon2/* dist_bundle/CPU/
else
if [[ ! -d dist_bundle/CPU ]]; then
echo "$showerror CPU folder inside dist_bundle not found!"
echo "$showexecute Creating one now..." && mkdir dist_bundle/CPU
echo "$showexecute Copying argon2/* files to dist_bundle/CPU" && cp -a argon2/* dist_bundle/CPU/
fi
fi
elif [[ $yn_compile == * ]]; then
echo -e "$showerror Possible options are: yY or nN."
fi
else
if [[ ! $(find . -type d -name argon2 | grep -x './argon2') == ./argon2 ]]; then
echo "$showerror argon2 not found inside Node-WebDollar!"
echo "$showinfo Cloning argon2 from WebDollar repository..."
git clone https://github.com/WebDollar/argon2.git
cd argon2
if [[ $(pwd) =~ argon[[:alnum:]]+ ]]; then
echo "$showinfo Current dir is $(pwd)"
echo "$showexecute ${GREEN}autoreconf -i$STAND" && autoreconf -i
echo "$showexecute ${GREEN}./configure$STAND" && ./configure
echo "$showexecute ${GREEN}make$STAND" && make
echo "$showexecute ${GREEN}make check$STAND" && make check # check if reponse PASSES
if [[ -d ../dist_bundle/CPU ]]; then
echo "$showok CPU folder inside dist_bundle exists!"
echo "$showexecute Copying argon2/* files to dist_bundle/CPU" && cp -a * ../dist_bundle/CPU/
else
if [[ ! -d ../dist_bundle/CPU ]]; then
echo "$showerror CPU folder inside dist_bundle not found!"
echo "$showexecute Creating one now..." && mkdir ../dist_bundle/CPU
echo "$showexecute Copying argon2/* files to dist_bundle/CPU" && cp -a * ../dist_bundle/CPU/
fi
fi
else
if [[ ! $(pwd) =~ argon[[:alnum:]]+ ]]; then
echo "$showerror You are not inside the ${YELLOW}argon2$STAND folder."
echo "$showinfo Run this script inside argon2 folder."
fi
fi
fi
fi
else
if [[ $(pwd) =~ argon[[:alnum:]]+ ]]; then
read -e -p "$showinput Do you want to compile argon2 again? (y or n): " yn_compile
if [[ $yn_compile == [nN] ]]; then
echo -e "$showinfo OK..."
elif [[ $yn_compile == [yY] ]]; then
echo "$showexecute Compiling argon2..." && make
elif [[ $yn_compile == * ]]; then
echo -e "$showerror Possible options are: yY or nN."
fi
else
if [[ ! $(pwd) =~ argon[[:alnum:]]+ ]]; then
echo "$showerror You are not inside the ${YELLOW}argon2$STAND folder."
echo "$showinfo Run this script inside argon2 folder."
fi
fi
fi