blob: db8e10ddf8eb7f38c9c33acc2ab59616e6ee3396 [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
Renato Golinc5b3cd82016-06-06 21:27:54 +010016BASE=$(readlink -fn -- "$0")
17BASE=$(dirname "$BASE")
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030018if [ ! -x "$BASE/bot-status.py" ]; then
Renato Golin188efc52016-06-06 15:08:49 +010019 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
Renato Golinc5b3cd82016-06-06 21:27:54 +010036 JSON="$(basename "$json")"
Renato Golin188efc52016-06-06 15:08:49 +010037 else
38 MANY=1
39 fi
40done
41if [ $MANY -eq 1 ]; then
42 JSON=""
43fi
44
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030045# Checking for required Python3 modules
46if ! python3 --version > /dev/null; then
47 echo 'Python3 missing'
Renato Golin188efc52016-06-06 15:08:49 +010048fi
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030049if ! python3 -c 'import requests' > /dev/null; then
50 echo 'python3-requests module missing'
Renato Golin188efc52016-06-06 15:08:49 +010051fi
52
53############################# Install
54
55# Creates bin for bot-status
56mkdir -p "$ROOT/bin"
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030057ln -sf "$BASE/bot-status.py" "$ROOT/bin/bot-status.py"
Renato Golin188efc52016-06-06 15:08:49 +010058if [ "$JSON" != "" ]; then
59 ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON"
60fi
61
David Spickettf6cd7d72022-10-31 15:10:40 +000062# Creates html dir for page
Renato Golin188efc52016-06-06 15:08:49 +010063mkdir -p "$ROOT/html"
Renato Golin188efc52016-06-06 15:08:49 +010064touch "$ROOT/html/index.html"
65
66echo
67echo "Installation complete"
68echo
69
70############################# Instructions
71
72echo
73echo "Post-Install instructions:"
74echo
75
76# JSON configuration
77if [ "$JSON" = "" ]; then
78 echo " * Multiple or empty JSON files, symlink the right one to $ROOT/bin"
79 echo
80 JSON="<json file>"
81fi
82
83# WebServer
84echo " * To make the HTML pages available to your WebServer,"
85echo " Create a link from the web server (ex. /var/www/html/monitor) to $ROOT/html"
86echo
87
88# Crontab
89echo " * To run the application every five minutes, add this line to your crontab:"
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030090echo " */5 * * * * $ROOT/bin/bot-status.py $ROOT/bin/$JSON $ROOT/html/index.html"
Renato Golin188efc52016-06-06 15:08:49 +010091echo