This repository has been archived by the owner on May 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_install.sh
248 lines (230 loc) · 7.41 KB
/
build_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
#!/bin/bash
# WELCOME MESSAGE
printf "\nWelcome to the $(tput setaf 1)C$(tput setaf 3)R$(tput setaf 2)A$(tput setaf 6)P$(tput setaf 4)L$(tput setaf 5)O$(tput setaf 7)G$(tput sgr0)'s installer\n\n"
sleep 1 && wait
# GET THE PATH OF CRAPLOG-GIT'S FOLDER
crapdir="$(dirname $(realpath $0))"
# INITIAL WARNING ABOUT PRIVILEDGES
printf "This script will later ask for $(tput setaf 1)sudo$(tput sgr0) privileges to copy the executable inside $(tput setaf 3)/usr/bin/$(tput sgr0)\nIf you prefer to do it manually, answer [$(tput bold)N$(tput sgr0)] to the incoming question\n"
printf "CONTINUE? [Y/N] : "
read agree
case "$agree"
in
"y" | "Y")
printf ""
;;
*)
printf "\nInstruction about how to install can be found on Craplog's GitHub page or inside the README.md file in the download folder:\n"
printf " - $crapdir/README.md\n"
printf " - https://github.com/elB4RTO/craplog-javaGUI\n"
printf "\nInstallation ABORTED\n\n"
sleep 1 && wait
exit
;;
esac
# INSTALLATION SECTION
#
# GET THE INSTALLATION VERSION
version=$(cat "./version_check")
version=${version:15:4}
# CHECKING MAVEN COMPILER AVAILABILITY
if [[ $(which mvn) =~ ^/ ]]
then
$()
else
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nThe $(tput setaf 8)Maven Project Manager$(tput sgr0) is required but not installed\n"
printf "Instruction about how to get it can be found on Craplog's GitHub page or inside the README.md file in the download folder:\n"
printf " - $crapdir/README.md\n"
printf " - https://github.com/elB4RTO/craplog-javaGUI\n"
printf "Please install Maven and retry, or download a pre-compiled RELEASE from Craplog's GitHub page\n"
printf "$(tput setaf 1)Installation ABORTED$(tput sgr0)\n\n"
exit
fi
# CHECKING THE EXISTENCE OF A PREVIOUS EXECUTABLE FILE IN /usr/bins
if [ -e /usr/bin/craplog ]
then
while true;
do
printf "\n$(tput setaf 3)WARNING$(tput sgr0): file $(tput setaf 8)/usr/bin/$(tput setaf 1)craplog$(tput sgr0) already exists\n"
printf "If you choose to continue, the actual file will be lost forever\nOVERWRITE FILE? [Y/N] : "
read agree
case "$agree"
in
"y" | "Y")
printf "\n"
break
;;
*)
printf "\nInstallation ABORTED\n\n"
exit
;;
esac
done
fi
# SAVE THE ACTUAL PATH
actual_path=$(pwd)
# ASK FOR A PATH TO STORE CRAPLOG IN
while :
do
printf "INSERT THE FULL (ABSOLUTE) PATH TO WHERE YOU WANT TO INSTALL CRAPLOG IN\n $(tput bold):$(tput sgr0) "
read crappath
if [[ $crappath =~ /$ ]]
then
crappath=${crappath:0:$(( $(printf $crappath | wc -m) -1 ))}
fi
case "$crappath"
in
"")
printf "The path can't be null, please insert a valid path\n\n"
continue
;;
"exit" | "q" | "Q")
printf "\nInstallation ABORTED\n\n"
exit
;;
*)
printf "\nThe final installation path will be:\n$(tput bold)$crappath/craplog/$(tput sgr0)\n"
printf "CONTINUE? [Y/N] : "
read agree
case "$agree"
in
"y" | "Y")
$()
;;
*)
printf "\n"
continue
;;
esac
# CHECKING EXISTENCE CONFLICTS
if [ -e "$crappath/craplog" ]
then
if [ -f "$crappath/craplog" ]
then
printf "NAME CONFLICT: the given path corresponds to a file. Please insert a valid path or delete the file\n"
continue
fi
elif [ ! -e "$crappath" ]
then
printf "\nThe given path does not exists yet. Every missing folder in the path will be created\n"
printf "CONTINUE? [Y/N] : "
read agree
case "$agree"
in
"y" | "Y")
mkdir -p "$crappath"
;;
*)
printf "\n"
continue
;;
esac
fi
# CHECKING THE EXISTENCE OF A PREVIOUS INSTALLATION
if [ -d "$crappath/craplog" ] \
&& [[ $(ls -l "$crappath/craplog/" | wc -l) -gt 1 ]]
then
printf "\n$(tput setaf 3)WARNING$(tput sgr0): the installation folder is not empty\n"
printf "If you choose to proceed, the folder will be completely erased\n"
printf "CONTINUE? [Y/N] : "
read agree
case "$agree"
in
"y" | "Y")
while [ -e "$crappath/craplog" ]
do
rm -r "$crappath/craplog"
done
;;
*)
printf "\n"
continue
;;
esac
fi
;;
esac
break
done
# MOVE IN CRAPLOG'S FOLDER
cd craplog
# EVERYTHING OK, INSTALL CRAPLOG
printf "\n\n$(tput setaf 15)STARTING INSTALLATION$(tput sgr0)\n\n"
# COMPILE THE PROJECT WITH MAVEN
printf "$(tput setaf 11)Compiling project\n$(tput setaf 7)"
mvn clean install
if [ "$?" = "0" ]
then
# compiled succesfully
printf "$(tput setaf 10)Done compiling$(tput sgr0)\n"
else
# an error occured during compilation
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nAn error occured during compilation\n"
printf "\nInstallation ABORTED\n\n"
exit
fi
# MOVE THE JAR INSIDE THE FINAL FOLDER
mv -f "./target/CRAPLOG-$version-jar-with-dependencies.jar" "../pre-made_folder/CRAPLOG-$version.jar"
if [ "$?" = "1" ]
then
# an error occured
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nAn error occured while moving the JAR\n"
printf "\nInstallation ABORTED\n\n"
exit
fi
rm "../pre-made_folder/crapstats/DELETEME" &> /dev/null
# COMPLETE THE LAUNCH FILES
if [ ! -d "../installation_stuff/" ]
then
# missing stuff
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nThe folder named "$(tput bold)installation_stuff$(tput sgr0)" is needed to complete the installation, but it's missing\n"
printf "\nInstallation ABORTED\n\n"
exit
fi
cd "../installation_stuff/"
printf "\n$(tput setaf 11)Making launchers\n$(tput setaf 7)"
sudo printf "$(cat "./craplog")\n\njava -jar $crappath/craplog/CRAPLOG-$version.jar\n\n" > "/usr/bin/craplog" &&\
sudo chmod +x "/usr/bin/craplog"
if [ "$?" = "1" ]
then
# an error occured
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nAn error occured while creating the bins entry\n"
printf "\nInstallation ABORTED\n\n"
exit
fi
if [ ! -d ~/".local/share/applications" ]
then
# missing dir
printf "\n$(tput setaf 3)WARNING$(tput sgr0): the folder designed to hold menu entries does not exist\n"
printf "Please report this issue here: $(tput setaf 12)https://github.com/elB4RTO/craplog-javaGUI/issues$(tput sgr0)\n"
printf "$(tput bold)Skipping the creation of a menu entry$(tput sgr0)\n\n"
else
printf "$(cat "./craplog.desktop")" > ~/".local/share/applications/craplog.desktop"
if [ "$?" = "1" ]
then
# an error occured during compilation
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nAn error occured while creating the menu entry\n"
printf "$(tput bold)Skipping the creation of a menu entry$(tput sgr0)\n\n"
fi
fi
printf "$(tput setaf 10)Done making launchers$(tput sgr0)\n"
# MOVE CRAPLOG'S DIR
cd ..
printf "\n$(tput setaf 11)Moving files\n$(tput setaf 7)"
mv "./pre-made_folder/" "$crappath/craplog"
if [ "$?" = "0" ]
then
# succesfully moved
printf "$(tput setaf 10)Done moving files$(tput sgr0)\n"
else
# an error occured
printf "\n$(tput setaf 1)WARNING$(tput sgr0):\nAn error occured while moving files\n"
printf "\nInstallation ABORTED\n\n"
exit
fi
# FIN
printf "\n$(tput setaf 15)INSTALLATION COMPLETED$(tput sgr0)\n\n\n"
sleep 1 && wait
printf "You can now run CRAPLOG from inside your terminal or from the menu entry\n\n"
sleep 1 && wait
printf "$(tput setaf 3)F$(tput setaf 2)I$(tput setaf 6)N$(tput sgr0)\n\n"