blob: 1b8b703234b50cc4dc5f8a41ac08a5f193dab918 [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
David Spickett30a986f2021-04-29 09:37:00 +010052if ! python3 -c 'import pybuildkite' > /dev/null; then
53 echo 'python3-pybuildkite module missing'
54fi
Renato Golin188efc52016-06-06 15:08:49 +010055
56############################# Install
57
58# Creates bin for bot-status
59mkdir -p "$ROOT/bin"
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030060ln -sf "$BASE/bot-status.py" "$ROOT/bin/bot-status.py"
Renato Golin188efc52016-06-06 15:08:49 +010061if [ "$JSON" != "" ]; then
62 ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON"
63fi
64
David Spickettf6cd7d72022-10-31 15:10:40 +000065# Creates html dir for page
Renato Golin188efc52016-06-06 15:08:49 +010066mkdir -p "$ROOT/html"
Renato Golin188efc52016-06-06 15:08:49 +010067touch "$ROOT/html/index.html"
68
69echo
70echo "Installation complete"
71echo
72
73############################# Instructions
74
75echo
76echo "Post-Install instructions:"
77echo
78
79# JSON configuration
80if [ "$JSON" = "" ]; then
81 echo " * Multiple or empty JSON files, symlink the right one to $ROOT/bin"
82 echo
83 JSON="<json file>"
84fi
85
86# WebServer
87echo " * To make the HTML pages available to your WebServer,"
88echo " Create a link from the web server (ex. /var/www/html/monitor) to $ROOT/html"
89echo
90
91# Crontab
92echo " * To run the application every five minutes, add this line to your crontab:"
Adhemerval Zanellad3e8c482020-10-12 11:31:48 -030093echo " */5 * * * * $ROOT/bin/bot-status.py $ROOT/bin/$JSON $ROOT/html/index.html"
Renato Golin188efc52016-06-06 15:08:49 +010094echo