Adding icons and many improvements

This commit is contained in:
Igor Pecovnik
2020-03-27 18:32:04 +01:00
parent 5a8e46d3bc
commit c6bbee74df
15 changed files with 200 additions and 97 deletions

170
go.sh
View File

@@ -3,112 +3,176 @@
# Simple autotest script.
#
#
# Install host dependencies
#
apt install -y -qq jq expect sshpass nmap &>/dev/null
#
# Create working directories
#
mkdir -p userconfig logs reports
# create sample configuration
# create sample configuration if id does not exits
if [[ ! -f userconfig/configuration.sh ]]; then
cp lib/configuration.sh userconfig/configuration.sh
echo "Setup finished. Edit userconfig/configuration.sh and run ./go.sh again!"
exit
fi
# start measuring executing time
START=$(date +%s)
# define absolute path
SRC="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
# report file name
REPORT="$(date +%Y%m%d%H%M%S)"
# load user configuration
source userconfig/configuration.sh
# load libraries
source lib/functions.sh
# remove logs
rm -rf logs/*
# remove logs each time we ran the script. Need to be changed
rm -rf ${SRC}/logs/* ${SRC}/reports/data.out
# exclude IP addresses defined in EXCLUDE
[[ -n $EXCLUDE ]] && HOST_EXCLUDE="--exclude ${EXCLUDE}"
# include IP addresses defined in INCLUDE
[[ -n $INCLUDE ]] && IFS=', ' read -r -a includearray <<< "$INCLUDE"
if [[ -n $SUBNET ]]; then
readarray -t hostarray < <(nmap $HOST_EXCLUDE --open -sn ${SUBNET} 2> /dev/null | grep "ssh\|Nmap scan report" | grep -v "gateway" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
elif [[ -n $HOSTS ]]; then
if [[ -n $SUBNET ]]; then # scan subnet if SUBNET is defined
readarray -t hostarray < <(nmap $HOST_EXCLUDE --open -sn ${SUBNET} 2> /dev/null \
| grep "ssh\|Nmap scan report" | grep -v "gateway" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
elif [[ -n $HOSTS ]]; then # otherwise read comma delimited IP address from HOSTS
IFS=', ' read -r -a hostarray <<< "$HOSTS"
else
echo "\$HOST not defined. Exiting." && exit 1
else # otherwise stops with an error
echo "\$HOST not defined. Exiting." && exit 1
fi
# merge HOSTS/SUBNET with INCLUDE
hostarray=("${includearray[@]}" "${hostarray[@]}")
DRY_RUN=true
HEADER_HTML="<html>
<head>
<style>
# html report header
HEADER_HTML="<html>\n<head><style>
td, tr {
border: 1px solid black;
padding: 8px;
border: 1px solid #00bfff;
padding: 8px;
}
table {
border-collapse: collapse;
}
</style>
</head>
<body><table cellspacing=0 width=100% border=1><tr><td align=right rowspan=2>#</td><td align=center rowspan=2>Board<br>/<br>Cycle</td><td rowspan=2>Version / distribution <br>Kernel / variant</td>\n"
HEADER_MD="|Board|"
</style>\n</head>\n<body><table cellspacing=0 width=100% border=1>
<tr><td align=right rowspan=2>#</td><td align=center rowspan=2>Board<br>/<br>
Cycle</td><td rowspan=2>Version / distribution <br>Kernel / variant</td>\n"
# cycle test cases and make a header row
#
# when DRY_RUN is set we cycle over test to basic information about tests, but do not run them
#
DRY_RUN=true
readarray -t array < <(find $SRC/tests -maxdepth 2 -type f -name '*.bash' | sort)
COLOUMB=0
for u in "${array[@]}"
do
unset TEST_SKIP
. $u
[[ $TEST_SKIP != "true" ]] && HEADER_MD+=$TEST_TITLE" |" && COLOUMB=$((COLOUMB+1)) && if [[ COLOUMB -gt 5 ]]; then row=2; else row=1; fi && HEADER_HTML+="<td align=center rowspan=$row>$TEST_ICON<br><small>$TEST_TITLE</small></td>"
if [[ $TEST_SKIP != "true" ]]; then
COLOUMB=$((COLOUMB+1))
if [[ COLOUMB -gt 5 ]]; then
row=2;
else
row=1;
fi
HEADER_HTML+="<td align=center rowspan=$row>$TEST_ICON<br><small>$TEST_TITLE</small></td>"
fi
done
HEADER_MD+="\n|:-|"
for u in "${array[@]}"
do
unset TEST_SKIP
. $u
[[ $TEST_SKIP != "true" ]] && HEADER_MD+=":-|"
done
HEADER_HTML+="</tr><tr><td align=middle colspan=3>Iperf send/receive (MBits/s)</td><td align=middle colspan=2>IO read/write (MBits/s)</td></tr>\n"
HEADER_HTML+="</tr><tr><td align=middle colspan=3>Iperf send/receive (MBits/s)</td>
<td align=middle colspan=2>IO read/write (MBits/s)</td></tr>\n"
unset DRY_RUN
x=1
BOARD_NAMES=()
BOARD_KERNELS=()
BOARD_URLS=()
BOARD_VERSIONS=()
BOARD_DISTRIBUTION_CODENAMES=()
# Read cached database from previous succesfull test run. Display / log error if this run is different.
# Some host might not returned after the test cycle
#
i=0
while IFS="\n" read -r line; do
eval "declare -a a$i=($line)"
i=$((i+1))
done < ${SRC}/reports/data.in
# Cycle hosts and see if they are alive, login/create username
# and read /etc/armbian-release and compare with previous run
x=0
for USER_HOST in "${hostarray[@]}"; do
readarray -t array < <(find $SRC/init -maxdepth 2 -type f -name '*.bash' | sort)
for u in "${array[@]}"
do
. $u
# always start with the stock build
if [[ $BOARD_IMAGE_TYPE != stable ]]; then
vara="a$x[0]"
varb="a$x[1]"
# creating data for next comparission
echo '"'$USER_HOST'" "'$BOARD_NAME'"' >> ${SRC}/reports/data.out
if [[ "${COMPARE}" == "yes" && $i -gt 1 && ("$USER_HOST" != "${!vara}" || "$BOARD_NAME" != "${!varb}") ]]; then
[[ -n $BOARD_NAME ]] && x=$((x+1))
display_alert "${x}. ${!varb} was expected on $(mask_ip "${!vara}")" "$(date +%R:%S)" "err"
fi
# always switch to stable build from repository if not already there
if [[ -n "$BOARD_IMAGE_TYPE" && "$BOARD_IMAGE_TYPE" != stable ]]; then
display_alert "Switch to stable builds" "$(date +%R:%S)" "wrn"
remote_exec "LANG=C armbian-config main=System selection=Stable; reboot"
#sshpass -p ${PASS_ROOT} ssh -t ${USER_ROOT}@${USER_HOST} "LANG=C armbian-config main=System selection=Stable; reboot" &>/dev/null
remote_exec "apt update; apt -y -qq install armbian-config; \
LANG=C armbian-config main=System selection=Stable; reboot" "-t" &>/dev/null
fi
x=$((x+1))
done
done
#sleep 15
#w=0
#for BOARD_PID in "${BOARD_PIDS[@]}"; do
# kill $BOARD_PID 2> /dev/null
# echo $?
# w=$((w+1))
#done
# Cycle boards and run tests
x=0
for USER_HOST in "${hostarray[@]}"; do
rm -f logs/${HOST}.log
run_tests
[[ $? -ne 0 ]] && display_alert "Host failed" "$USER_HOST" "err"
[[ $? -ne 0 ]] && display_alert "Host failed" "$(mask_ip "$USER_HOST")" "err"
x=$((x+1))
done
HEADER_HTML+="</table></body>
</html>\n"
# close HTML file
HEADER_HTML+="</table></body>\n</html>\n"
echo -e $HEADER_HTML >> ${SRC}/reports/${REPORT}.html
# make a diff between current and previous board list
DIFF=$(diff --suppress-common-lines ${SRC}/reports/data.in ${SRC}/reports/data.out | sed 1d)
[[ -z $DIFF ]] && cp ${SRC}/reports/data.out ${SRC}/reports/data.in
# Show script run duration
echo "This whole procedure took "$((($(date +%s) - $START)/60))" minutes".

BIN
icons/bluetooth.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 714 B

BIN
icons/checked.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

BIN
icons/error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 822 B

BIN
icons/fire.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

BIN
icons/lan.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 B

BIN
icons/na.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

BIN
icons/storage.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

BIN
icons/wifi.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B

View File

@@ -45,9 +45,7 @@ if [[ $? -eq 1 ]]; then
echo "${MAKE_USER}" >> ${SRC}/logs/${USER_HOST}.log
fi
remote_exec "chsh -s /bin/bash; apt -y purge armbian-config; apt -qq -y install jq stress armbian-config bluez-tools iozone3" &>/dev/null
#sshpass -p ${PASS_ROOT} ssh ${USER_ROOT}@${USER_HOST} "chsh -s /bin/bash; apt -y purge armbian-config; apt -qq -y install jq stress armbian-config bluez-tools iozone3" &>/dev/null
remote_exec "chsh -s /bin/bash; apt -y purge armbian-config; apt update; apt -qq -y install jq stress armbian-config bluez-tools iozone3" "-t" &>/dev/null
get_board_data
display_alert "${x}. $BOARD_NAME $BOARD_KERNEL $BOARD_IMAGE_TYPE" "$(mask_ip "$USER_HOST")" "info"
[[ -n $BOARD_NAME ]] && display_alert "${x}. $BOARD_NAME $BOARD_KERNEL $BOARD_IMAGE_TYPE" "$(mask_ip "$USER_HOST")" "info"

View File

@@ -2,6 +2,7 @@
PASSES=5
STRESS_TIME=100 # seconds
COMPARE="no" # compare with previous buils
# user

View File

@@ -10,6 +10,7 @@
#
# Masking IP prefix address to make report copy/paste ready
#
function mask_ip(){
echo $1 | sed -r 's!/.*!!; s!.*\.!!' | awk '{print "###.###.###."$1}'
@@ -51,12 +52,19 @@ function get_board_data(){
}
#
# get_ip_addresses or interfaces
#
function get_device() {
local ips=()
remote_exec '
for f in /sys/class/net/*; do
intf=$(basename $f)
# match only interface names starting with e (Ethernet), br (bridge), w (wireless), r (some Ralink drivers use ra<number> format)
# match only interface names starting with e (Ethernet), br (bridge)
# w (wireless), r (some Ralink drivers use ra<number> format)
if [[ "$intf" =~ '$1' ]]; then
tmp=$(ip -4 addr show dev $intf | grep inet | awk "{print \$2}" | cut -d"/" -f1)
if [[ "'$2'" == ip ]]; then
@@ -69,14 +77,15 @@ function get_device() {
fi
done'
} # get_ip_addresses
}
#--------------------------------------------------------------------------------------------------------------------------------
#
# Let's have unique way of displaying alerts
#--------------------------------------------------------------------------------------------------------------------------------
#
display_alert()
{
local tmp=""
@@ -84,7 +93,7 @@ display_alert()
case $3 in
err)
echo -e "[\e[0;31m error \x1B[0m] $1 $tmp" | tee -a ${SRC}/logs/${USER_HOST}.log
echo -e "[\e[0;31m err. \x1B[0m] $1 $tmp" | tee -a ${SRC}/logs/${USER_HOST}.log
echo "$(date +%R:%S) $1" >> ${SRC}/logs/${USER_HOST}.txt
;;
@@ -111,6 +120,33 @@ display_alert()
}
function wait_for_board
{
# wait for a board for a while
i=1
while ! ping -c1 $USER_HOST &>/dev/null; do
display_alert "Ping $USER_HOST failed $i" "$(date +%R:%S)" "info"
sleep 10
i=$(( $i + 1 ))
# give up after 50s
[[ $i -gt 5 ]] && false && break
done
display_alert "Host $(mask_ip "$USER_HOST") found" "Run $r out of ${PASSES}" "info";
# wait for SSHD to come up
f=1
while ! nc -zvw3 $USER_HOST 22 &>/dev/null
do
sleep 10
f=$(( $f + 1 ))
[[ $f -gt 4 ]] && false && break
display_alert "Probing SSH port on $USER_HOST" "$(date +%R:%S)" "info"
done
}
function run_tests
@@ -119,35 +155,45 @@ r=1
i=1
SUM=0
START=$(date +%s)
# run board test loop PASSES time
while [ $r -le ${PASSES} ]
do
while ! ping -c1 $USER_HOST &>/dev/null; do display_alert "Ping $USER_HOST failed $i" "$(date +%R:%S)" "info"; sleep 10; i=$(( $i + 1 )); [[ $i -gt 5 ]] && return 1;done ; START=$(date +%s); echo ""; display_alert "Host $(mask_ip "$USER_HOST") found" "Run $r out of ${PASSES}" "info";
i=1
while ! nc -zvw3 $USER_HOST 22 &>/dev/null
do
sleep 3; f=$(( $f + 1 )); [[ $f -gt 3 ]] && exit 1
display_alert "Probing SSH port on $USER_HOST" "$(date +%R:%S)" "info"
done
if [[ $? -ne 0 ]]; then
display_alert "Can't connect. SSH on $USER_HOST is closed" "$(date +%R:%S)" "wrn"
else
readarray -t array < <(find $SRC/tests -maxdepth 2 -type f -name '*.bash' | sort)
get_board_data
HEADER_MD+="\n|$BOARD_NAME|"
HEADER_HTML+="\n<tr>"$( [[ ${r} -eq 1 ]] && echo "<td align=right rowspan=$((PASSES+1))>$((x+1))</td><td colspan=$((COLOUMB+2))>${BOARD_NAME} $(mask_ip "$USER_HOST")</td></td></tr><tr>")"<td align=center>$r/${PASSES}<br><small>$(date +%R:%S)</small></td><td>${BOARD_VERSION} (${BOARD_DISTRIBUTION_CODENAME})<br>${BOARD_KERNEL} ${BOARD_IMAGE_TYPE}</td>"
for u in "${array[@]}"
do
unset TEST_OUTPUT
DATA_ALIGN="center"
. $u
[[ $TEST_SKIP != "true" ]] && HEADER_MD+="$TEST_OUTPUT|" && HEADER_HTML+="<td align=$DATA_ALIGN>$TEST_OUTPUT</td>"
unset TEST_SKIP
done
HEADER_HTML+="</tr>\n"
#echo -e $HEADER_MD
#echo -e $HEADER_HTML
# wait until you get ping and sshd response
wait_for_board
# show error that we can't connect to the hosts sshd
if [[ $? -ne 0 ]]; then
display_alert "Can't connect. SSH on $USER_HOST is closed" "$(date +%R:%S)" "err"
else
# otherwise proceed with running test cases
# read tests
readarray -t array < <(find $SRC/tests -maxdepth 2 -type f -name '*.bash' | sort)
# read board information
get_board_data
# construct HTML for report
HEADER_HTML+="\n<tr>"$( [[ ${r} -eq 1 ]] && \
echo "<td align=right rowspan=$((PASSES+1))>&nbsp;$((x+1))&nbsp;</td>\
<td colspan=$((COLOUMB+2))>${BOARD_NAME} $(mask_ip "$USER_HOST")</td></td></tr><tr>")"\
<td align=center>$r/${PASSES}<br><small>$(date +%R:%S)</small></td>\
<td>${BOARD_VERSION} (${BOARD_DISTRIBUTION_CODENAME})<br>${BOARD_KERNEL} ${BOARD_IMAGE_TYPE}</td>"
# run tests
for u in "${array[@]}"
do
unset TEST_OUTPUT
DATA_ALIGN="center"
. $u
[[ $TEST_SKIP != "true" ]] && HEADER_HTML+="<td align=$DATA_ALIGN>$TEST_OUTPUT</td>"
unset TEST_SKIP
done
HEADER_HTML+="</tr>\n"
fi
r=$(( $r + 1 ))

View File

@@ -9,10 +9,4 @@ display_alert "$(basename $BASH_SOURCE)" "$(date +%R:%S)" "info"
display_alert "Rebooting in 3 seconds" "${BOARD_NAME}" "info"
sleep 3
remote_exec "reboot" &>/dev/null
sleep 3
i=0
# return error if machine does not come back after 10 seconds
echo -en "[\e[0;32m o.k. \x1B[0m] "
while ping -c1 $USER_HOST &>/dev/null; do echo -n "."; sleep 2; i=$(( $i + 1 )); [[ $i -gt 10 ]] && return 1; done
i=0
sleep 20

View File

@@ -13,7 +13,7 @@ do
unset speed_from
fi
display_alert "... $device" "${speed_from} ${speed_to} MBits/s" "info"
TEST_OUTPUT+="<small>$(echo $device | cut -d \( -f2 | cut -d \) -f1)</small><br>${speed_from}${speed_to}<br>"
TEST_OUTPUT+="<small>$(echo $device | cut -d \( -f2 | cut -d \) -f1)</small> ${speed_from}${speed_to}<br>"
done
[[ ${#array[@]} -eq 0 ]] && TEST_OUTPUT="<img width=16 src=https://upload.wikimedia.org/wikipedia/commons/thumb/1/18/Philippines_road_sign_R3-1.svg/220px-Philippines_road_sign_R3-1.svg.png>"