| #!/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" ]; 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 Perl modules |
| if ! perl -v > /dev/null; then |
| echo "Please, install Perl" |
| exit 1 |
| fi |
| if ! perl -e "File::Temp" > /dev/null; then |
| echo "Please, install Perl's File module" |
| exit 1 |
| fi |
| if ! perl -e "use JSON" > /dev/null; then |
| echo "Please, install Perl's JSON module" |
| exit 1 |
| fi |
| if ! perl -e "use LWP" > /dev/null; then |
| echo "Please, install Perl's LWP module" |
| exit 1 |
| fi |
| |
| ############################# Install |
| |
| # Creates bin for bot-status |
| mkdir -p "$ROOT/bin" |
| ln -sf "$BASE/bot-status" "$ROOT/bin/bot-status" |
| if [ "$JSON" != "" ]; then |
| ln -sf "$BASE/$JSON" "$ROOT/bin/$JSON" |
| fi |
| |
| # Creates html dir for page and icons |
| mkdir -p "$ROOT/html" |
| ln -sf "$BASE/fail.ico" "$ROOT/html/fail.ico" |
| ln -sf "$BASE/ok.ico" "$ROOT/html/ok.ico" |
| 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 $ROOT/bin/$JSON $ROOT/html/index.html" |
| echo |