forked from pilight/pilight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·131 lines (125 loc) · 4.33 KB
/
setup.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
#!/usr/bin/env bash
#
# Copyright (C) 2014 CurlyMo
#
# This file is part of pilight.
#
# pilight is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# pilight is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pilight. If not, see <http://www.gnu.org/licenses/>
#
cmake --help &>/dev/null || { echo "This program requires cmake"; exit; }
dialog -v &>/dev/null || { echo "This program requires dialog"; exit; }
if [ $(uname -a | grep -c "FreeBSD") -eq 0 ] && [ $(uname -a | grep -c "ARCH") -eq 0 ]; then
dpkg --get-selections | grep -c libc6 &>/dev/null || { echo "This program requires libc6"; exit; }
fi
function clean {
rm -r CMakeFiles 2>/dev/null 1>/dev/null >/dev/null || true;
rm -r _CPack_Packages 2>/dev/null 1>/dev/null >/dev/null || true;
rm *.cmake 2>/dev/null 1>/dev/null >/dev/null || true;
rm CMakeCache.txt 2>/dev/null 1>/dev/null >/dev/null || true;
make clean 2>/dev/null 1>/dev/null >/dev/null || true;
rm Makefile 2>/dev/null 1>/dev/null >/dev/null || true;
rm install_manifest.txt 2>/dev/null 1>/dev/null >/dev/null || true;
rm config.h 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-control 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-daemon 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-raw 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-send 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-flash 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-learn 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-debug 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-receive 2>/dev/null 1>/dev/null >/dev/null || true;
rm pilight-uuid 2>/dev/null 1>/dev/null >/dev/null || true;
rm *.a* 2>/dev/null 1>/dev/null >/dev/null || true;
rm *.so* 2>/dev/null 1>/dev/null >/dev/null || true;
}
if [ $# -eq 1 ]; then
if [ "$1" == "clean" ] || [ "$1" == "clear" ]; then
clean;
fi
if [ "$1" == "uninstall" ] || [ "$1" == "deinstall" ]; then
make uninstall;
fi
if [ "$1" == "install" ]; then
if [ ! -f Makefile ]; then
cmake .
fi
make install;
fi
if [ "$1" == "help" ]; then
echo -e "Usage: ./setup.sh [options]";
echo -e "\t clean\t\tremove all cmake and make generated files";
echo -e "\t install\tinstall pilight";
echo -e "\t uninstall\tuninstall pilight";
fi
else
ORIGINALIFS=$IFS;
IFS=$'\n';
OPTIONS=($(cat CMakeConfig.txt));
MENU=();
for ROW in ${OPTIONS[@]}; do
[[ "$ROW" =~ (.*\"(.*)\".*) ]] && DESC=${BASH_REMATCH[2]};
[[ "$ROW" =~ (set\(([0-9A-Za-z_]+)[[:space:]].*) ]] && NAME=${BASH_REMATCH[2]};
if [[ "$ROW" =~ " ON " ]]; then
MENU+=($NAME $DESC on);
else
MENU+=($NAME $DESC off);
fi
done;
OUTPUT=$(dialog --cancel-label "Abort" --extra-button --extra-label "Cancel and Install" --ok-label "Save and Install" --checklist "pilight configuration options" 17 100 10 ${MENU[@]} 3>&1 1>&2 2>&3);
RETURN=$?;
UPDATE=0;
if [ $RETURN -eq 0 ]; then
IFS=" ";
RESULTS=($OUTPUT);
IFS=$'\n';
OPTIONS=($(cat CMakeConfig.txt));
for ROW in ${OPTIONS[@]}; do
MATCH=0;
[[ "$ROW" =~ (set\(([0-9A-Za-z_]+)[[:space:]].*) ]] && NAME=${BASH_REMATCH[2]};
for ROW1 in ${RESULTS[@]}; do
ROW1=${ROW1//\"/};
if [ "$ROW1" == "$NAME" ]; then
if [[ "$ROW" =~ " OFF " ]]; then
UPDATE=1
if [ $(uname -a | grep -c "FreeBSD") -eq 0 ]; then
sed -i "s/\(.*\)\($NAME\) OFF \(.*\)/\1$NAME ON \3/" CMakeConfig.txt
else
sed -i "" "s/\(.*\)\($NAME\) OFF \(.*\)/\1$NAME ON \3/" CMakeConfig.txt
fi
fi
MATCH=1
fi
done;
if [ $MATCH -eq 0 ]; then
if [[ "$ROW" =~ " ON " ]]; then
UPDATE=1
if [ $(uname -a | grep -c "FreeBSD") -eq 0 ]; then
sed -i "s/\(.*\)\($NAME\) ON \(.*\)/\1$NAME OFF \3/" CMakeConfig.txt
else
sed -i "" "s/\(.*\)\($NAME\) ON \(.*\)/\1$NAME OFF \3/" CMakeConfig.txt
fi
fi
fi
done
fi
IFS=$ORIGINALIFS;
if [ $RETURN -eq 1 ]; then
exit;
else
if [ $UPDATE -eq 1 ]; then
clean;
fi
cmake .
make install
fi
fi