-
Notifications
You must be signed in to change notification settings - Fork 0
/
nettemp_install_on_raspberry_pi.sh
executable file
·200 lines (166 loc) · 6.57 KB
/
nettemp_install_on_raspberry_pi.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
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
#/bin/bash
# nettemp.pl
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
R='\033[0m'
RED='\033[00;31m'
REDB='\033[01;41;35m'
GREEN='\033[00;32m'
YELLOW='\033[00;33m'
x1="$1"
x2="$2"
rpi=$(cat /proc/cmdline | awk -v RS=" " -F= '/boardrev/ { print $2 }')
if [ "$x1" = "rpi" ] || [ "$x2" = "rpi" ]
then
rpi="1"
fi
if [[ $UID -ne 0 ]]; then
echo -e "${GREEN} $0 must be run as root ${R}"
exit 1
fi
echo -e "${GREEN}Nettemp installer${R}"
apt-get update
echo -e "${GREEN}Install packages${R}"
apt-get -y install lighttpd php5-cgi php5-sqlite rrdtool sqlite3 msmtp digitemp gammu git-core mc sysstat \
sharutils bc htop snmp sudo ntp watchdog python-smbus i2c-tools openvpn iptables rcconf arp-scan snmpd httping fping make gcc build-essential
if [ "$?" -eq "0" ]; then
echo "${GREEN}All packages installed ok${R}"
else
echo "${GREEN}error when install packages, try again${R}"
exit
fi
echo -e "${GREEN}Configure WWW server${R}"
# enable fastcgi
lighty-enable-mod fastcgi-php
# enable modrewrite
sed -i -e 's/# "mod_rewrite",/ "mod_rewrite",/g' /etc/lighttpd/lighttpd.conf
# www dir
sed -i -e 's/server.document-root = \"\/var\/www\"/server.document-root = \"\/var\/www\/nettemp\"/g' /etc/lighttpd/lighttpd.conf
# didable dir access
sed -i '/url.access-deny/d' /etc/lighttpd/lighttpd.conf
sed -i '$a url.access-deny = ( "~", ".inc", ".dbf", ".db", ".txt", ".rrd" )' /etc/lighttpd/lighttpd.conf
# set url rewrite
if cat /etc/lighttpd/lighttpd.conf |grep url.rewrite-once 1> /dev/null
then
echo -e "${GREEN}Url rewrite exist${R}"
else
echo "url.rewrite-once = ( \"^/([A-Za-z0-9-_-]+)\$\" => \"/index.php?id=\$1\" )" >> /etc/lighttpd/lighttpd.conf
fi
# htaccess
if cat /etc/lighttpd/lighttpd.conf |grep Password 1> /dev/null ; then
echo -e "${GREEN}Passwors already set${R}"
else
sed -i '$aauth.debug = 2' /etc/lighttpd/lighttpd.conf
sed -i '$aauth.backend = "plain"' /etc/lighttpd/lighttpd.conf
sed -i '$aauth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword"' /etc/lighttpd/lighttpd.conf
sed -i '$aauth.require = ( "/" =>' /etc/lighttpd/lighttpd.conf
sed -i '$a(' /etc/lighttpd/lighttpd.conf
sed -i '$a"method" => "basic",' /etc/lighttpd/lighttpd.conf
sed -i '$a"realm" => "Password protected area",' /etc/lighttpd/lighttpd.conf
sed -i '$a"require" => "user=admin"' /etc/lighttpd/lighttpd.conf
sed -i '$a)' /etc/lighttpd/lighttpd.conf
sed -i '$a)' /etc/lighttpd/lighttpd.conf
sed -i '$a www-data ALL=(ALL) NOPASSWD: /usr/sbin/lighttpd-enable-mod *, /usr/sbin/lighttpd-disable-mod *' /etc/sudoers
touch /etc/lighttpd/.lighttpdpassword
chown www-data:www-data /etc/lighttpd/.lighttpdpassword
echo "admin:admin" > /etc/lighttpd/.lighttpdpassword
lighttpd-enable-mod auth
fi
# php.ini upload file max size
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 300M/g' /etc/php5/cgi/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 300M/g' /etc/php5/cgi/php.ini
cd /var/www
if [ -d "nettemp" ]; then
mv nettemp nettempOLD
echo -e "${GREEN}Your nettemp dir is moved to nettempOLD${R}"
fi
if [ "$x1" = "beta" ] || [ "$x2" = "beta" ]
then
echo -e "${GREEN}Nettemp beta version${R}"
git clone -b beta --recursive git://github.com/sosprz/nettemp
else
echo -e "${GREEN}Nettemp master version${R}"
git clone -b master --recursive git://github.com/sosprz/nettemp
fi
echo -e "${GREEN}Create nettemp database${R}"
/var/www/nettemp/modules/tools/db_reset
echo -e "${GREEN}Add cron line${R}"
echo "*/1 * * * * /var/www/nettemp/modules/cron/1" > /var/spool/cron/crontabs/root
echo "*/5 * * * * /var/www/nettemp/modules/cron/5" >> /var/spool/cron/crontabs/root
echo "0 * * * * /var/www/nettemp/modules/cron/1h" >> /var/spool/cron/crontabs/root
echo "@reboot /var/www/nettemp/modules/cron/r" >> /var/spool/cron/crontabs/root
chmod 600 /var/spool/cron/crontabs/root
if [ -n "$rpi" ]
then
echo -e "${GREEN}Add wiringPI for gpio${R}"
if which gpio 1> /dev/null
then
echo -e "${GREEN}WiringPI exist${R}"
else
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build
fi
# echo -e "${GREEN}Add watchdog${R}"
# update-rc.d watchdog defaults
# if cat /etc/modules |grep bcm2708_wdog 1> /dev/null
# then
# echo "bcm2708_wdog exist in file"
# else
# echo "bcm2708_wdog" | sudo tee -a /etc/modules
# fi
# sed -i -e '10s/#max-load-1/max-load-1/' /etc/watchdog.conf
# sed -i -e '23s/#watchdog-device/watchdog-device/' /etc/watchdog.conf
# /etc/init.d/watchdog start
fi
echo -e "${GREEN}Add 1-wire modules${R}"
if cat /etc/modules |grep w1_ 1> /dev/null
then
echo -e "${GREEN}1-wire modules exist in file${R}"
else
if [ -n "$rpi" ]
then
echo "w1_gpio" | sudo tee -a /etc/modules
modprobe w1_gpio
fi
echo "w1_therm" | sudo tee -a /etc/modules
modprobe w1_therm
fi
echo -e "${GREEN} UPS status function${R}"
/var/www/nettemp/modules/ups/install
echo -e "${GREEN} OpenVPN serwer${R}"
/var/www/nettemp/modules/security/vpn/install
echo -e "${GREEN} Firewall${R}"
/var/www/nettemp/modules/security/fw/install
#i2c
echo -e "${GREEN} I2C install${R}"
if [ -n "$rpi" ]
then
sed -i '$ai2c-bcm2708' /etc/modules
sed -i 's/blacklist spi-bcm2708/#blacklist spi-bcm2708/g' /etc/modprobe.d/raspi-blacklist.conf
sed -i 's/blacklist i2c-bcm2708/#blacklist i2c-bcm2708/g' /etc/modprobe.d/raspi-blacklist.conf
fi
sed -i '$ai2c-dev' /etc/modules
sed -i '$ads2482' /etc/modules
sed -i '$a www-data ALL=(ALL) NOPASSWD: /usr/sbin/i2cdetect *' /etc/sudoers
echo -e "${GREEN}Add permisions${R}"
chown -R root.www-data /var/www/nettemp
chmod -R 775 /var/www/nettemp
gpasswd -a www-data dialout
sed -i '$a www-data ALL=(ALL) NOPASSWD: /bin/chmod *, /bin/chown *, /bin/chgrp *, /sbin/reboot' /etc/sudoers
sed -i '$a www-data ALL=(ALL) NOPASSWD: /usr/bin/whoami, /usr/bin/killall *, /usr/bin/nohup *' /etc/sudoers
sed -i '$a www-data ALL=(ALL) NOPASSWD: /usr/bin/pkill -f nettemp_kwh' /etc/sudoers
sed -i '$a www-data ALL=(ALL) NOPASSWD: /sbin/iptables *, /sbin/iptables-save *' /etc/sudoers
sed -i '$a www-data ALL=(ALL) NOPASSWD: /usr/sbin/chpasswd *, /usr/sbin/useradd *, /usr/sbin/userdel *, /usr/sbin/groupadd *, /usr/sbin/service *, /usr/sbin/update-rc.d *, /bin/sed *, /bin/cat *' /etc/sudoers
echo -e "${GREEN}Starting services${R}"
#update-rc.d ntp enable
service ntp start
service apache2 stop
update-rc.d apache2 disable
#update-rc.d lighttpd enable
service lighttpd restart
#update-rc.d cron defaults
#service cron start
echo -e "${GREEN}Nettemp instalation complette${R}"
echo -e "${GREEN}Nettemp default login and pasword is admin${R}"