-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneric-cli
executable file
·231 lines (204 loc) · 4.87 KB
/
generic-cli
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
#!/bin/sh
# Licence: https://github.com/riera90/generic-CLI/blob/master/LICENSE.md
create_cmake(){
printf "WIP: the generic-cmake is not done yet, please wait.\n"
}
delete_cmake(){
printf "WIP: the generic-cmake is not done yet, please wait.\n"
}
update_cmake(){
printf "WIP: the generic-cmake is not done yet, please wait.\n"
}
recreate_makefile(){
printf "do you want googletest?\n"
read -p " [Y/N]: " answer
case $answer in
[yY]*)
git clone https://github.com/google/googletest.git
rm -rf ./googletest/.git
mv ./googletest ./make-files/googletest
;;
*)
;;
esac
}
create_makefile(){
if [ -d make-files ]; then
printf "re-creating makefile.\n"
recreate_makefile
else
printf "creating makefile.\n"
git clone https://github.com/riera90/generic-makefile.git
mv ./generic-makefile/*.md ./generic-makefile/make-files/
rm -rf ./generic-makefile/.git
rm -rf ./generic-makefile/.github
rm -rf ./generic-makefile/example
if [ -f ./../.gitignore ]; then
cat ./generic-makefile/.gitignore >> ./.gitignore
rm ./generic-makefile/gitignore
else
mv ./generic-makefile/.gitignore ./.gitignore
fi
mv ./generic-makefile/* ./
rm -rf ./generic-makefile
recreate_makefile
fi
}
delete_makefile(){
rm -rf Makefile make-files
}
update_makefile(){
if [ -f ./make-files/googletest/README.md ]; then
echo "detected googletest, mooving files to /tmp"
rm -rf /tmp/gmf
mkdir -p /tmp/gmf
mv ./make-files/googletest /tmp/gmf
fi
git clone https://github.com/riera90/generic-makefile.git
rm -rf ./make-files
mv ./generic-makefile/*.md ./generic-makefile/make-files/
rm -rf ./generic-makefile/.git
rm -rf ./generic-makefile/.github
rm -rf ./generic-makefile/example
mv ./generic-makefile/make-files ./make-files
if [ -f /tmp/gmf/googletest/README.md ]; then
echo "mooving back googletest and deleting files in /tmp"
mv /tmp/gmf/googletest ./make-files
rmdir /tmp/gmf
fi
printf "do you want to update the configuration file?\nthe previous configuration will be stored in Makefile.old\n"
read -p " [Y/N]: " answer
case $answer in
[yY]*)
if [ -f Makefile.old ]; then
rm -f Makefile.old
fi
mv ./Makefile ./Makefile.old
mv ./generic-makefile/Makefile ./Makefile
if [ -d make-files/googletest ]; then
rm -rf ./make-files/googletest
git clone https://github.com/google/googletest.git
rm -rf ./googletest/.git
mv ./googletest ./make-files/googletest
fi
;;
*)
;;
esac
rm -rf ./generic-makefile
}
update_cli(){
printf "updating cli.\n"
git clone https://github.com/riera90/generic-cli.git
rm -f ~/.gcli/gcli_banner.txt
mv ./generic-cli/gcli_banner.txt ~/.gcli/gcli_banner.txt
mv ./generic-cli/generic-cli ./generic-cli.sh
rm -rf ./generic-cli
echo "rm /usr/bin/generic-cli && mv ./generic-cli.sh /usr/bin/generic-cli && chmod +x /usr/bin/generic-cli && rm /tmp/tmp.sh" > /tmp/tmp.sh
sudo chmod +x /tmp/tmp.sh
sudo /tmp/tmp.sh
}
create(){
case $OPTARG in
make)
create_makefile
;;
makefile)
create_makefile
;;
gmf)
create_makefile
;;
cmake)
create_cmake
;;
gcm)
create_cmake
;;
*)
printf "Invalid argument: $OPTARG\nplease, use one of the followings\n"
printf " for the generic-makefile: 'makefile', 'make' or 'gmf'.\n"
printf " for the generic-cmake: 'cmake' or 'gcm'.\n"
;;
esac
}
update(){
if [ -f Makefile ]; then
update_makefile
fi
if [ -f cmake ]; then
update_cmake
fi
update_cli
}
delete(){
if [ -f Makefile ]; then
printf "Are you sure you want to delete the generic-makefile and all the configuration?\n"
read -p " [Y/N]: " answer
case $answer in
[yY]*)
printf "DELETING GENERIC-MAKEFILE!\n"
delete_makefile
;;
*)
printf "Doing nothing.\n"
;;
esac
elif [ -f cmake ]; then
printf "Are you sure you want to delete the generic-cmake and all the configuration?\n"
read -p " [Y/N]: " answer
case $answer in
[yY]*)
printf "DELETING GENERIC-CMAKE!\n"
delete_cmake
;;
*)
printf "Doing nothing.\n"
;;
esac
else
printf "You are not in a project with a generic family builder.\n"
fi
}
help(){
printf "generic-CLI for GNU/Linux\n"
printf " usage:\n"
printf " -c <cmake/makefile>\n Creates a generic cmake or makefile in the current directory\n"
printf " -d Delete the makefile or cmake of the current directory\n"
printf " -u Updates this scripts and the current directory's makefile or cmake\n (if there is one)\n"
}
cat ~/.gcli/gcli_banner.txt
while getopts ":c:hud" opt; do
case $opt in
h)
help
exit 0;
;;
c)
create
exit 0;
;;
u)
update
exit 0;
;;
d)
delete
exit 0;
;;
\?)
printf "Invalid option: -$OPTARG\n"
printf "use -h to get help.\n"
exit 1
;;
:)
printf "Option -$OPTARG requires an argument.\n"
printf "use -h to get help.\n"
exit 1
;;
esac
done
help
# __
# __( o)>
# \ <_ ) r90