aboutsummaryrefslogtreecommitdiff
path: root/monitor/install.sh
blob: 64fe2782c66692f15f28eedfab37f9fc37e31583 (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
94
95
96
97
98
99
100
101
102
103
#!/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" ]; 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 Perl modules
if ! perl -v > /dev/null; then
  echo "Please, install Perl"
  exit 1
fi
if ! perl -e "File::Temp" > /dev/null; then
  echo "Please, install Perl's File module"
  exit 1
fi
if ! perl -e "use JSON" > /dev/null; then
  echo "Please, install Perl's JSON module"
  exit 1
fi
if ! perl -e "use LWP" > /dev/null; then
  echo "Please, install Perl's LWP module"
  exit 1
fi

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

# Creates bin for bot-status
mkdir -p "$ROOT/bin"
ln -sf "$BASE/bot-status" "$ROOT/bin/bot-status"
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 $ROOT/bin/$JSON $ROOT/html/index/html"
echo