Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 1 | #!/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 Golin | c5b3cd8 | 2016-06-06 21:27:54 +0100 | [diff] [blame] | 16 | BASE=$(readlink -fn -- "$0") |
| 17 | BASE=$(dirname "$BASE") |
Adhemerval Zanella | d3e8c48 | 2020-10-12 11:31:48 -0300 | [diff] [blame] | 18 | if [ ! -x "$BASE/bot-status.py" ]; then |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 19 | echo "Make sure the install script is in the monitor directory" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | ############################# Prepare |
| 24 | |
| 25 | # Default root is home |
| 26 | ROOT="$HOME" |
| 27 | if [ "$1" != "" ]; then |
| 28 | ROOT="$1" |
| 29 | fi |
| 30 | |
| 31 | # If there is more than one JSON file, don't guess |
| 32 | JSON= |
| 33 | MANY=0 |
| 34 | for json in "$BASE"/*.json; do |
| 35 | if [ "$JSON" = "" ]; then |
Renato Golin | c5b3cd8 | 2016-06-06 21:27:54 +0100 | [diff] [blame] | 36 | JSON="$(basename "$json")" |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 37 | else |
| 38 | MANY=1 |
| 39 | fi |
| 40 | done |
| 41 | if [ $MANY -eq 1 ]; then |
| 42 | JSON="" |
| 43 | fi |
| 44 | |
Adhemerval Zanella | d3e8c48 | 2020-10-12 11:31:48 -0300 | [diff] [blame] | 45 | # Checking for required Python3 modules |
| 46 | if ! python3 --version > /dev/null; then |
| 47 | echo 'Python3 missing' |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 48 | fi |
Adhemerval Zanella | d3e8c48 | 2020-10-12 11:31:48 -0300 | [diff] [blame] | 49 | if ! python3 -c 'import requests' > /dev/null; then |
| 50 | echo 'python3-requests module missing' |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 51 | fi |
| 52 | |
| 53 | ############################# Install |
| 54 | |
| 55 | # Creates bin for bot-status |
| 56 | mkdir -p "$ROOT/bin" |
Adhemerval Zanella | d3e8c48 | 2020-10-12 11:31:48 -0300 | [diff] [blame] | 57 | ln -sf "$BASE/bot-status.py" "$ROOT/bin/bot-status.py" |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 58 | if [ "$JSON" != "" ]; then |
| 59 | ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON" |
| 60 | fi |
| 61 | |
David Spickett | f6cd7d7 | 2022-10-31 15:10:40 +0000 | [diff] [blame] | 62 | # Creates html dir for page |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 63 | mkdir -p "$ROOT/html" |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 64 | touch "$ROOT/html/index.html" |
| 65 | |
| 66 | echo |
| 67 | echo "Installation complete" |
| 68 | echo |
| 69 | |
| 70 | ############################# Instructions |
| 71 | |
| 72 | echo |
| 73 | echo "Post-Install instructions:" |
| 74 | echo |
| 75 | |
| 76 | # JSON configuration |
| 77 | if [ "$JSON" = "" ]; then |
| 78 | echo " * Multiple or empty JSON files, symlink the right one to $ROOT/bin" |
| 79 | echo |
| 80 | JSON="<json file>" |
| 81 | fi |
| 82 | |
| 83 | # WebServer |
| 84 | echo " * To make the HTML pages available to your WebServer," |
| 85 | echo " Create a link from the web server (ex. /var/www/html/monitor) to $ROOT/html" |
| 86 | echo |
| 87 | |
| 88 | # Crontab |
| 89 | echo " * To run the application every five minutes, add this line to your crontab:" |
Adhemerval Zanella | d3e8c48 | 2020-10-12 11:31:48 -0300 | [diff] [blame] | 90 | echo " */5 * * * * $ROOT/bin/bot-status.py $ROOT/bin/$JSON $ROOT/html/index.html" |
Renato Golin | 188efc5 | 2016-06-06 15:08:49 +0100 | [diff] [blame] | 91 | echo |