-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
138 lines (123 loc) · 3.7 KB
/
configure.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
#!/bin/bash
export CWD="${PWD}" status="true" exist=() trigger=()
alternatives() {
local status="true"
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
delphi)
local project="https://github.com/themispkg/bash-utils"
command -v "git" &> /dev/null || return 1
command -v "make" &> /dev/null || return 1
if [[ ! -d "${project##*/}" ]] ; then
git clone "${project}" || return 1
fi
cd "${project##*/}" || return 1
if [[ "${UID}" = "0" ]] ; then
make install || local status="false"
elif [[ "${UID}" != "0" ]] && command -v "sudo" &> /dev/null ; then
sudo make install || local status="false"
else
echo "please run it as root privalages this script."
return 1
fi
shift
;;
*)
echo -e "\t\talternatives do not support '${1}'."
local status="false"
shift
;;
esac
done
if [[ "${status}" = "false" ]] ; then
export status="false"
return 1
fi
}
check() {
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--exist|-e)
shift
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--trigger|-t)
break
;;
*)
export exist+=("${1}")
shift
;;
esac
done
;;
--trigger|-t)
shift
while [[ "${#}" -gt 0 ]] ; do
case "${1}" in
--exist|-e)
break
;;
*)
export trigger+=("${1}")
shift
;;
esac
done
;;
*)
shift
;;
esac
done
if [[ -n "${exist}" ]] ; then
for i in ${exist[@]} ; do
if [[ ! -e "${i}" ]] ; then
echo -e "\t'${i}' doesn't exist!"
export status="false"
fi
done
fi
if [[ -n "${trigger}" ]] ; then
for i in ${trigger[@]} ; do
cd "${CWD}"
if ! command -v "${i}" &> /dev/null ; then
echo -e "\t'${i}' not found, trying to get it with using alternatives.."
alternatives "${i}" || export status="false"
fi
done
fi
if [[ "${status}" = "false" ]] ; then
echo "Some requirements were not met."
return 1
fi
}
check -e "src/btbshell.sh" "lib/bashtextbank.sh" -t "make" "gzip" "tar" "mkdir" "rm" "cp" "file" "grep" "delphi"
if [[ "${status}" = "true" ]] ; then
cd "${CWD}"
tabs 8
t="$(printf '\t')"
cat - > "Makefile" <<EOF
PREFIX := ""
BINDIR := \$(PREFIX)/usr/bin
LIBDIR := "/usr/local/lib/bash"
define setup
${t}install -m 755 ./src/btbshell.sh \${BINDIR}/btbshell
${t}install -m 755 ./lib/bashtextbank.sh \${LIBDIR}
endef
define remove
${t}rm -f \${LIBDIR}/bashtextbank.sh \${BINDIR}/btbshell
endef
install:
${t}\$(setup)
uninstall:
${t}\$(remove)
reinstall:
${t}\$(remove)
${t}\$(setup)
EOF
[[ -f "Makefile" ]] && echo "All good, now you can type 'sudo make install'" || echo "Please reconfigure the project."
else
echo "Cannot create file 'Makefile' because requirements are not met."
exit 1
fi