| #!/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.py" ]; 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 Python3 modules |
| if ! python3 --version > /dev/null; then |
| echo 'Python3 missing' |
| fi |
| if ! python3 -c 'import requests' > /dev/null; then |
| echo 'python3-requests module missing' |
| fi |
| |
| ############################# Install |
| |
| # Creates bin for bot-status |
| mkdir -p "$ROOT/bin" |
| ln -sf "$BASE/bot-status.py" "$ROOT/bin/bot-status.py" |
| if [ "$JSON" != "" ]; then |
| ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON" |
| fi |
| |
| # Creates html dir for page |
| mkdir -p "$ROOT/html" |
| 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.py $ROOT/bin/$JSON $ROOT/html/index.html" |
| echo |