blob: 64fe2782c66692f15f28eedfab37f9fc37e31583 [file] [log] [blame]
Renato Golin188efc52016-06-06 15:08:49 +01001#!/usr/bin/env bash
2
3# This script installs the monitor on a new machine.
4#
5# Syntax: install.sh [/root/install/dir]
6#
7# ROOT default is $HOME.
8#
9# Instructions:
10# 1. Create a monitor user, its directory and give admins sudo -u monitor
11# 2. Make sure that Perl, File, JSON and LWP are installed
12# 3. Go to linaro-scripts/monitor; ./install.sh
13# 4. Follow the instructions
14
15# Full path
16BASE=`readlink -fn -- "$0"`
17BASE=`dirname "$BASE"`
18if [ ! -x "$BASE/bot-status" ]; then
19 echo "Make sure the install script is in the monitor directory"
20 exit 1
21fi
22
23############################# Prepare
24
25# Default root is home
26ROOT="$HOME"
27if [ "$1" != "" ]; then
28 ROOT="$1"
29fi
30
31# If there is more than one JSON file, don't guess
32JSON=
33MANY=0
34for json in "$BASE"/*.json; do
35 if [ "$JSON" = "" ]; then
36 JSON="`basename $json`"
37 else
38 MANY=1
39 fi
40done
41if [ $MANY -eq 1 ]; then
42 JSON=""
43fi
44
45# Checking for required Perl modules
46if ! perl -v > /dev/null; then
47 echo "Please, install Perl"
48 exit 1
49fi
50if ! perl -e "File::Temp" > /dev/null; then
51 echo "Please, install Perl's File module"
52 exit 1
53fi
54if ! perl -e "use JSON" > /dev/null; then
55 echo "Please, install Perl's JSON module"
56 exit 1
57fi
58if ! perl -e "use LWP" > /dev/null; then
59 echo "Please, install Perl's LWP module"
60 exit 1
61fi
62
63############################# Install
64
65# Creates bin for bot-status
66mkdir -p "$ROOT/bin"
67ln -sf "$BASE/bot-status" "$ROOT/bin/bot-status"
68if [ "$JSON" != "" ]; then
69 ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON"
70fi
71
72# Creates html dir for page and icons
73mkdir -p "$ROOT/html"
74ln -sf "$BASE/fail.ico" "$ROOT/html/fail.ico"
75ln -sf "$BASE/ok.ico" "$ROOT/html/ok.ico"
76touch "$ROOT/html/index.html"
77
78echo
79echo "Installation complete"
80echo
81
82############################# Instructions
83
84echo
85echo "Post-Install instructions:"
86echo
87
88# JSON configuration
89if [ "$JSON" = "" ]; then
90 echo " * Multiple or empty JSON files, symlink the right one to $ROOT/bin"
91 echo
92 JSON="<json file>"
93fi
94
95# WebServer
96echo " * To make the HTML pages available to your WebServer,"
97echo " Create a link from the web server (ex. /var/www/html/monitor) to $ROOT/html"
98echo
99
100# Crontab
101echo " * To run the application every five minutes, add this line to your crontab:"
102echo " */5 * * * * $ROOT/bin/bot-status $ROOT/bin/$JSON $ROOT/html/index/html"
103echo