-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·88 lines (75 loc) · 2.34 KB
/
setup.sh
File metadata and controls
executable file
·88 lines (75 loc) · 2.34 KB
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
#!/bin/bash
# install the required modules.
# apt-get clean && apt-get update && apt-get install -y python-pip python-dev
# pip install influxdb
# pip install pyserial
# pip install spidev
# pip install py-opc
# Let user enter the parameter to customize(location, frequency etc.)
while getopts ":s:u:p:d:l:f:" opt; do
case $opt in
s)
sensor=$OPTARG
;;
u)
user=$OPTARG
;;
p)
passwd=$OPTARG
;;
d)
database=$OPTARG
;;
l)
location=$OPTARG
;;
f)
frequency=$OPTARG
# echo "-f was triggered" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Verify if the sensor is valid.
if [ "$sensor" == "ADC" ]; then
run_script="nohup python $PWD/apolline/Alphasense_ADC/AlphasenseADC.py --user $user --password $passwd --database $database --location $location --frequency $frequency &"
echo "The sensor is $sensor"
elif [ "$sensor" == "NDIR" ]; then
run_script="nohup python $PWD/apolline/Alphasense_NDIR/AlphasenseNDIR.py --user $user --password $passwd --database $database --location $location --frequency $frequency &"
echo "The sensor is $sensor"
elif [ "$sensor" == "OPC-N2" ]; then
run_script="nohup python $PWD/apolline/Alphasense_OPC-N2/AlphasenseOPC.py --user $user --password $passwd --database $database --location $location --frequency $frequency &"
echo "The sensor is $sensor"
else
run_script=""
echo "Not a valid sensor: $sensor"
fi
# Once it is a valid sensor
# rewrite the rc.local each time we run this script.
echo "Writing to rc.local"
(
cat << EOF
# !/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# in order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.
# You can find log file at /tmp/rc.local.log if there are any problem.
exec 2> /tmp/rc.local.log
exec 1>&2
set -e
$run_script
exit 0
EOF
) > /etc/rc.local
echo "Writing to rc.local completed, you can reboot the Raspberry."