-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
59 lines (53 loc) · 1.34 KB
/
functions.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
#!/usr/bin/env bash
function trailingSlash () {
if [ ${1: -1} != "/" ]
then
echo $1/
else
echo $1
fi
}
function askRepository() {
repositoryPath=null
while ! [ -d $repositoryPath ] || ! [ -x $repositoryPath ];
do
if [ $repositoryPath != null ]
then
echo "$1 \"${repositoryPath}\" : No such file or directory" >&2
fi
echo "$1 :" >&2
read repositoryPath;
done
echo $(trailingSlash $repositoryPath);
}
function askDatabaseType() {
databaseType=null
while ! [ $databaseType = "mysql" ] && ! [ $databaseType = "mongo" ];
do
echo "Database type (mysql|mongo) : " >&2
read databaseType
done
echo $databaseType
}
function askBinPath() {
binPath=$(trailingSlash $(trailingSlash $1)bin)
if ! [ -d $binPath ] || ! [ -x $binPath ];
then
echo -e "\"$binPath\" does not exist, you want to create it?\n - (y) Yes, create it\n - (n) No, I want to specify the bin path" >&2
read answer
if [ $answer == "y" ]
then
mkdir $binPath
else
binPath=`askRepository "Bin asbolute path"`
fi
fi
echo $binPath
}
function checkUserRoot() {
if [ $(whoami) != "root" ];
then
echo "Les droits root sont nécessaires." >&2
exit 1
fi
}