-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·122 lines (95 loc) · 2.73 KB
/
install
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
#!/bin/bash
SERVICE_NAME='sensoric-r2d2'
if [ `whoami` != 'root' ]; then
echo "Please run as root";
exit 1;
fi;
pushd `dirname $0` > /dev/null
LOCATION=`pwd`
popd > /dev/null
verbose_code(){
code=$?
if [ $code -eq 0 ];then
echo Ok
else
echo Fail
fi;
return $code
}
echo -n "Installing $SERVICE_NAME daemon..."
cat > /etc/init.d/$SERVICE_NAME << _BODY_
#!/bin/sh
### BEGIN INIT INFO
# Provides: R2D2 main service
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts r2d2 sensors and operations
# Description: Starts r2d2 sensors and operations
### END INIT INFO
DIR=$LOCATION
DAEMON=\$DIR/robot.d
DAEMON_NAME=$SERVICE_NAME
# Add any command line options for your daemon here
DAEMON_OPTS=""
# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root
# The process ID of the script when it runs is stored here:
PIDFILE=/var/run/\$DAEMON_NAME.pid
. /lib/lsb/init-functions
do_start () {
log_daemon_msg "Starting system \$DAEMON_NAME daemon"
start-stop-daemon --start --background --pidfile \$PIDFILE --make-pidfile --user \$DAEMON_USER --chuid \$DAEMON_USER --startas \$DAEMON -- \$DAEMON_OPTS
log_end_msg \$?
}
do_stop () {
log_daemon_msg "Stopping system \$DAEMON_NAME daemon"
start-stop-daemon --stop --pidfile \$PIDFILE --retry 10
log_end_msg \$?
}
case "\$1" in
start|stop)
do_\${1}
;;
restart|reload|force-reload)
do_stop
do_start
;;
status)
status_of_proc "\$DAEMON_NAME" "\$DAEMON" && exit 0 || exit \$?
;;
*)
echo "Usage: /etc/init.d/\$DAEMON_NAME {start|stop|restart|status}"
exit 1
;;
esac
exit 0
_BODY_
verbose_code
chmod +x /etc/init.d/$SERVICE_NAME
echo -n "Adding $SERVICE_NAME to startup..."
update-rc.d $SERVICE_NAME defaults
verbose_code
echo "Installing packages..."
apt-get install alsa-base fail2ban python2.7 mpg123 espeak monit libssl-dev libavahi-client-dev libasound2-dev
which pip 1>/dev/null 2>&1
if [ $? -ne 0 ];then
echo -n "Downloading get-pip..."
curl -k -o get-pip.py https://bootstrap.pypa.io/get-pip.py
verbose_code
if [ $? -eq 0 ];then
echo -n "Installing pip..."
python get-pip.py
verbose_code
fi;
fi;
echo -n "Installing required pip packages..."
pip install python-daemon pyttsx alsaaudio
verbose_code
echo -n "Configure modprobe 8192cu (for wifi)..."
cat > /etc/modprobe.d/8192cu.conf << _BODY_
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0
_BODY_
verbose_code