-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinstaller
executable file
·234 lines (197 loc) · 6.57 KB
/
installer
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
#!/bin/bash
#############################################################
# Const Vars
#############################################################
DEFAULTINSTALLDIR="/opt/raspadmin"
DEFAULTPORT="443"
CONFIGDIR="/etc/raspadmin"
#############################################################
# Functions
#############################################################
function ask_question {
message=$1
has_constraints=0
if [ "$2" != "" ] ; then
constraints=$2
has_constraints=1
fi
not_valid=1
while [ $not_valid -ne 0 ] ; do
echo -en $message
read var
not_valid=0
if [ $has_constraints -ne 0 ]; then
not_valid=1
for i in $(echo $constraints | sed -e "s/;/ /g"); do
if [ "$var" == "$i" ]; then
ask_question=$var
return
fi
done
fi
done
ask_question=$var
}
function get_boolean_value {
mess=$(expr substr $1 1 1)
if [ "$mess" == "y" ] || [ "$mess" == "Y" ] ; then
echo -n "1"
else
echo -n "0"
fi
}
function read_ini_file {
inifile=$1
pattern=$2
[[ ! -f $inifile ]] && return
result=$(grep $pattern $inifile | cut -d'=' -f2)
echo $result
}
#############################################################
# Checking requirements
#############################################################
clear
echo "---------------------------------------------"
echo "Welcome to raspadmin installer"
echo "---------------------------------------------"
echo ""
echo -e " Checking requirements : \e[34mIn progress\e[0m"
echo -e " Configuration : \e[91mWaiting\e[0m"
echo -e " Copying files : \e[91mWaiting\e[0m"
echo ""
echo ""
echo "----- Package configuration"
echo ""
if [ "$(whoami)" != "root" ] ; then
echo "######### Error, you need to be root to execute this script"
echo " Please use sudo"
exit 2
fi
dpkg -s python-pip > /dev/null 2>&1
pip=$?
dpkg -s python-dev > /dev/null 2>&1
dev=$?
if [ "$pip" == "1" ]; then
echo "Installing pip"
apt-get install python-pip
fi
if [ "$dev" == "1" ]; then
echo "Installing python-dev"
apt-get install python-dev
fi
echo "Installing needed libraries via pip"
pip install quik
pip install netifaces
pip install RPi.GPIO
pip install psutil
pip install requests
#############################################################
# Asking question
#############################################################
clear
echo "---------------------------------------------"
echo "Welcome to raspadmin installer"
echo "---------------------------------------------"
echo ""
echo -e " Checking requirements : \e[92mDone\e[0m"
echo -e " Configuration : \e[34mIn progress\e[0m"
echo -e " Copying files : \e[91mWaiting\e[0m"
echo ""
echo "Please answer few questions for the installation process"
echo ""
echo "----- Directory configuration"
echo ""
NO_CONSTRAINTS="y;Y;n;N;No;NO;no;yes;Yes;YEs;YES"
installdir=""
if [ -f /etc/raspadmin/raspadmin.conf ] ; then
echo -e "Setup has detected an existing configuration file"
ask_question "Would you like to keep it ? [y/n] [ \e[31mSelection y if you just want to update\e[0m ] : " $NO_CONSTRAINTS
answer=$(get_boolean_value $ask_question)
if [ $answer -eq 1 ] ; then
installdir=$(read_ini_file "/etc/raspadmin/raspadmin.conf" "staticfiledir" | sed -e "s/static//g")
fi
fi
if [ "$installdir" == "" ] ; then
ask_question "Please enter the default home directory for user [ $DEFAULTINSTALLDIR ] : "
installdir=$ask_question
[[ "$installdir" == "" ]] && installdir=$DEFAULTINSTALLDIR
ask_question "Please enter the port [ $DEFAULTPORT ] : "
port=$ask_question
[[ "$port" == "" ]] && port=$DEFAULTPORT
ask_question "Use SSL [y/n] : " $NO_CONSTRAINTS
ssl=$(get_boolean_value $ask_question)
[[ ! -d $CONFIGDIR ]] && mkdir $CONFIGDIR
if [ "$ssl" == "1" ] ; then
ssl=yes
ask_question "Do you have your own certificate [y/n] : " $NO_CONSTRAINTS
owncert=$(get_boolean_value $ask_question)
if [ $owncert -eq 1 ] ; then
certificate_path="/"
while [ ! -f "$certificate_path" ] ; do
ask_question "Path to your certificate : "
certificate_path=$ask_question
[[ -f $certificate_path ]] || echo "Invalid path"
done
key_path="/"
while [ ! -f "$key_path" ] ; do
ask_question "Path to your private key : "
key_path=$ask_question
[[ -f $key_path ]] || echo "Invalid path"
done
else
openssl genrsa -out $CONFIGDIR/cert.key 1024
openssl req -new -key $CONFIGDIR/cert.key -out $CONFIGDIR/cert.csr
openssl x509 -req -days 4000 -in $CONFIGDIR/cert.csr -signkey $CONFIGDIR/cert.key -out $CONFIGDIR/cert.crt
rm -f $CONFIGDIR/cert.csr
certificate_path="$CONFIGDIR/cert.crt"
key_path="$CONFIGDIR/cert.key"
fi
else
ssl="no"
certificate_path=""
key_path=""
fi
sed -e "s#\$PORT#$port#" -e "s#\$INSTALLDIR#$installdir#" -e "s#\$CERT#$certificate_path#" -e "s#\$KEY#$key_path#" -e "s#\$SSL#$ssl#" conf/raspadmin.conf > $CONFIGDIR/raspadmin.conf
fi
clear
echo "---------------------------------------------"
echo "Welcome to raspadmin installer"
echo "---------------------------------------------"
echo ""
echo -e " Checking requirements : \e[92mDone\e[0m"
echo -e " Configuration : \e[92mDone\e[0m"
echo -e " Copying files : \e[34mWaiting\e[0m"
echo ""
echo "----- Installation"
echo ""
[[ -d /var/log/raspadmin ]] || mkdir /var/log/raspadmin
echo ""
echo "----- File copy"
[[ -d "$installdir" ]] || mkdir $installdir
cp -R sources/* $installdir
echo "----- Right management"
chown -R root:root $installdir
chmod -R 770 $installdir
chmod +x /etc/init.d/raspadmin
chmod 770 /var/log/raspadmin
echo "----- StartUp "
sed -e "s#\$INSTALLDIR#$installdir#" init/raspadmin > /etc/init.d/raspadmin
chmod 755 /etc/init.d/raspadmin
update-rc.d raspadmin defaults
echo ""
clear
echo "---------------------------------------------"
echo "Welcome to raspadmin installer"
echo "---------------------------------------------"
echo ""
echo -e " Checking requirements : \e[92mDone\e[0m"
echo -e " Configuration : \e[92mDone\e[0m"
echo -e " Copying files : \e[92mDone\e[0m"
echo ""
echo " To start the application : sudo service raspadmin start"
echo " To install modules (NAS, pyload, gateone, ...), proceed as following :"
echo " * cd modules"
echo " * sudo ./installer"
echo ""
echo " Please read information about this module in the wiki page of this project"
echo " https://github.com/air01a/raspadmin/wiki/Module"