-
Notifications
You must be signed in to change notification settings - Fork 9
/
INSTALL
98 lines (85 loc) · 2.28 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
#!/bin/bash
set -e
# Make sure only root can run this script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Check dependencies
requiredAptDependencies=( "cec-utils" )
missingAptDependencies=()
echo "Checking apt dependencies..."
for elem in "${requiredAptDependencies[@]}"
do
dpkg -s $elem &> /dev/null
if [ $? -ne 0 ]
then
missingAptDependencies=("${missingAptDependencies[@]}" "$elem")
fi
done
if [ ${#missingAptDependencies[@]} -gt 0 ]
then
# printf "Please install missing apt packages via\n"
# printf "\t'sudo apt install"
for elem in "${missingAptDependencies[@]}"
do
printf "trying to install $elem\n"
apt -y -q install $elem
# printf " $elem"
done
printf "'\n"
else
echo "All apt dependencies are met"
fi
echo ""
echo "Checking pip dependencies..."
requiredPipDependencies=( "requests" "cec" "yaml" )
missingPipDependencies=()
for elem in "${requiredPipDependencies[@]}"
do
python3 -c "import $elem" &> /dev/null
if [ $? -ne 0 ]
then
if [ "$elem" = "yaml" ]
then
missingPipDependencies=("${missingPipDependencies[@]}" "pyyaml")
else
missingPipDependencies=("${missingPipDependencies[@]}" "$elem")
fi
fi
done
if [ ${#missingPipDependencies[@]} -gt 0 ]
then
# printf "Please install missing pip packages via\n"
# printf "\t'pip3 install --system"
for elem in "${missingPipDependencies[@]}"
do
# printf " $elem"
printf "Insalling $elem\n"
pip3 install --system $elem
done
# printf "'\n"
printf "\n"
printf "Note that a user has to be in the group 'staff' to install Python packages globally.\n"
printf "To add a user to the 'staff' group execute 'sudo adduser <username> staff'.\n"
else
echo "All pip dependencies are met"
fi
echo ""
# if [ ${#missingAptDependencies[@]} -gt 0 ] || [ ${#missingPipDependencies[@]} -gt 0 ]
# then
# exit 1
# fi
# Starting installation
echo "Starting installation..."
echo "Setting up systemd service..."
sed -i "s|WorkingDirectory=.*|WorkingDirectory=$(pwd)|g" alarmmonitor.service \
&& ln -s "$(pwd)"/alarmmonitor.service /etc/systemd/system/alarmmonitor.service \
&& systemctl enable alarmmonitor \
&& systemctl start alarmmonitor
echo ""
if [ $? -ne 0 ]; then
echo "Errors occured during installation" > /dev/stderr
exit 1
fi
echo "Installation successful"