aboutsummaryrefslogtreecommitdiff
path: root/monitor/install.sh
blob: beceec4816cde777306d3b3358bea9d6ca0d28d6 (plain)
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
#!/usr/bin/env bash

# This script installs the monitor on a new machine.
#
# Syntax: install.sh [/root/install/dir]
#
# ROOT default is $HOME.
#
# Instructions:
# 1. Create a monitor user, its directory and give admins sudo -u monitor
# 2. Make sure that Perl, File, JSON and LWP are installed
# 3. Go to linaro-scripts/monitor; ./install.sh
# 4. Follow the instructions

# Full path
BASE=$(readlink -fn -- "$0")
BASE=$(dirname "$BASE")
if [ ! -x "$BASE/bot-status.py" ]; then
  echo "Make sure the install script is in the monitor directory"
  exit 1
fi

############################# Prepare

# Default root is home
ROOT="$HOME"
if [ "$1" != "" ]; then
  ROOT="$1"
fi

# If there is more than one JSON file, don't guess
JSON=
MANY=0
for json in "$BASE"/*.json; do
  if [ "$JSON" = "" ]; then
    JSON="$(basename "$json")"
  else
    MANY=1
  fi
done
if [ $MANY -eq 1 ]; then
  JSON=""
fi

# Checking for required Python3 modules
if ! python3 --version > /dev/null; then
  echo 'Python3 missing'
fi
if ! python3 -c 'import requests' > /dev/null; then
  echo 'python3-requests module missing'
fi

############################# Install

# Creates bin for bot-status
mkdir -p "$ROOT/bin"
ln -sf "$BASE/bot-status.py" "$ROOT/bin/bot-status.py"
if [ "$JSON" != "" ]; then
  ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON"
fi

# Creates html dir for page and icons
mkdir -p "$ROOT/html"
ln -sf "$BASE/fail.ico" "$ROOT/html/fail.ico"
ln -sf "$BASE/ok.ico" "$ROOT/html/ok.ico"
touch "$ROOT/html/index.html"

echo
echo "Installation complete"
echo

############################# Instructions

echo
echo "Post-Install instructions:"
echo

# JSON configuration
if [ "$JSON" = "" ]; then
  echo " * Multiple or empty JSON files, symlink the right one to $ROOT/bin"
  echo
  JSON="<json file>"
fi

# WebServer
echo " * To make the HTML pages available to your WebServer,"
echo "   Create a link from the web server (ex. /var/www/html/monitor) to $ROOT/html"
echo

# Crontab
echo " * To run the application every five minutes, add this line to your crontab:"
echo "   */5 * * * * $ROOT/bin/bot-status.py $ROOT/bin/$JSON $ROOT/html/index.html"
echo