From 6b974b75315eb80e604153b10aa73588f092216c Mon Sep 17 00:00:00 2001 From: ThomasKaiser Date: Fri, 18 Mar 2016 17:07:39 +0100 Subject: [PATCH] Added disk checking to armbianmonitor and f3 to additional packages --- configuration.sh | 2 +- scripts/armbianmonitor/armbianmonitor | 134 +++++++++++++++++++++++--- 2 files changed, 123 insertions(+), 13 deletions(-) diff --git a/configuration.sh b/configuration.sh index 97f9351db..4513e1ef6 100644 --- a/configuration.sh +++ b/configuration.sh @@ -536,7 +536,7 @@ PACKAGE_LIST="automake bash-completion bc bridge-utils build-essential cmake cpu # Non-essential packages PACKAGE_LIST_ADDITIONAL="alsa-utils btrfs-tools bluez hddtemp i2c-tools iperf ir-keytable iotop iozone3 weather-util weather-util-data stress \ dvb-apps sysbench libbluetooth-dev libbluetooth3 subversion screen ntfs-3g vim pciutils evtest htop mtp-tools python-smbus \ - apt-transport-https libfuse2 libdigest-sha-perl libproc-processtable-perl w-scan aptitude dnsutils" + apt-transport-https libfuse2 libdigest-sha-perl libproc-processtable-perl w-scan aptitude dnsutils f3" # Release specific packages case $RELEASE in diff --git a/scripts/armbianmonitor/armbianmonitor b/scripts/armbianmonitor/armbianmonitor index fc0f7b1af..1baa041a7 100755 --- a/scripts/armbianmonitor/armbianmonitor +++ b/scripts/armbianmonitor/armbianmonitor @@ -82,6 +82,17 @@ Main() { export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + + # check if stdout is a terminal... + if test -t 1; then + # see if it supports colors... + ncolors=$(tput colors) + if test -n "$ncolors" && test $ncolors -ge 8; then + BOLD="$(tput bold)" + NC='\033[0m' # No Color + LGREEN='\033[1;32m' + fi + fi [ $# -eq 0 ] && (DisplayUsage ; exit 0) @@ -108,7 +119,7 @@ Main() { } # Main ParseOptions() { - while getopts 'hHbBuUrRmMdD' c ; do + while getopts 'hHbBuUrRmMdDc:C:' c ; do case ${c} in H) # display full help test @@ -181,22 +192,17 @@ ParseOptions() { echo -e "Please post the URL in the Armbian forum where you've been asked for." exit 0 ;; + c|C) + # check card mode + CheckCard "${OPTARG}" + exit 0 + ;; esac done } # ParseOptions DisplayUsage() { - # check if stdout is a terminal... - if test -t 1; then - # see if it supports colors... - ncolors=$(tput colors) - if test -n "$ncolors" && test $ncolors -ge 8; then - BOLD="$(tput bold)" - NC='\033[0m' # No Color - LGREEN='\033[1;32m' - fi - fi - echo -e "Usage: ${BOLD}${0##*/} [-h] [-b] [-d] [-m] [-r] [-u]${NC}\n" + echo -e "Usage: ${BOLD}${0##*/} [-h] [-b] [-d \$path] [-d] [-m] [-r] [-u]${NC}\n" echo -e "############################################################################" if [ ${FullUsage} ]; then echo -e "\nDetailed Description:" @@ -204,6 +210,7 @@ DisplayUsage() { fi echo -e "\n Use ${BOLD}armbianmonitor${NC} for the following tasks:\n" echo -e " armbianmonitor ${BOLD}-b${NC} switches between verbose and normal boot" + echo -e " armbianmonitor ${BOLD}-c /path/to/test${NC} performs disk health/performance tests" echo -e " armbianmonitor ${BOLD}-d${NC} tries to upload debug disk info to improve armbianmonitor" echo -e " armbianmonitor ${BOLD}-m${NC} provides simple CLI monitoring" echo -e " armbianmonitor ${BOLD}-r${NC} tries to install RPi-Monitor" @@ -642,4 +649,107 @@ BAKBQCAQCAQCgUAgEAgEwjPhPzou6T0AoAAA" | base64 --decode | tar xzf - esac } # PatchRPiMonitor_for_sun8i +CheckCard() { + if [ "$(id -u)" = "0" ]; then + echo "Checking disks is not permitted as root or through sudo. Exiting" >&2 + exit 1 + fi + + if [ ! -d "$1" ]; then + echo "\"$1\" does not exist or is no directory. Exiting" >&2 + exit 1 + fi + TargetDir="$1" + + # check requirements + which f3write >/dev/null 2>&1 || MissingTools=" f3" + which iozone >/dev/null 2>&1 || MissingTools="${MissingTools} iozone3" + if [ "X${MissingTools}" != "X" ]; then + echo "Some tools are missing, please do an \"sudo apt-get -f -y install${MissingTools}\" before and try again" >&2 + exit 1 + fi + + # check provided path + Device="$(GetDevice "$1")" + set ${Device} + DeviceName=$1 + FileSystem=$2 + echo "${DeviceName}" | grep -q "mmcblk0" || echo -e "\n${BOLD}WARNING:${NC} It seems you're not testing the SD card but instead ${DeviceName} (${FileSystem})\n" + + TestDir="$(mktemp -d "${TargetDir}/cardtest.XXXXXX" || exit 1)" + date "+%s" >"${TestDir}/.starttime" || exit 1 + trap "rm -rf \"${TestDir}\" ; exit 0" 0 1 2 3 15 + + # start actual test, create a small file for some space reserve + fallocate -l 32M "${TestDir}/empty.32m" + # Start writing + echo -e "Now starting to write to the card, please be patient, this might take a very long time" + f3write "${TestDir}" | tee /tmp/CheckCard.log + touch "${TestDir}/.starttime" || (echo -e "\n${BOLD}Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e "${NC}" ; exit 1) + rm "${TestDir}/empty.32m" + # Start verify + echo -e "\nNow verifying the written data:" + f3read "${TestDir}" | tee -a /tmp/CheckCard.log + touch "${TestDir}/.starttime" || (echo -e "\n${BOLD}Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e "${NC}" ; exit 1) + rm "${TestDir}/"*.h2w + echo -e "\nStarting iozone tests:" + cd "${TestDir}" + iozone -e -I -a -s 100M -r 4k -r 512k -r 16M -i 0 -i 1 -i 2 "${TestDir}" | tee -a /tmp/CheckCard.log + touch "${TestDir}/.starttime" || (echo -e "\n${BOLD}Test stopped, read-only filesystem" ; dmesg | grep 'I/O error' ; echo -e "${NC}" ; exit 1) + echo -e "\n${BOLD}The results from testing ${DeviceName} (${FileSystem}):${NC}" + egrep "Average|Data" /tmp/CheckCard.log | sort -r + echo " random random" + echo -e "reclen write rewrite read reread read write\c" + awk -F"102400 " '/102400/ {print $2}'