Skip to content

Commit

Permalink
Huge improvements to speedtest - PATCH-000004
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Mar 28, 2019
1 parent 4e51b22 commit 55a3cc5
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions info.sh
Expand Up @@ -97,6 +97,10 @@ elif [[ $COMMAND == "hwid" ]]; then
/sbin/ifconfig enp0s3 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | md5sum | cut -d"-" -f1 -
fi

elif [[ $COMMAND == "speedtest" ]]; then
# output json response of detected wifi networks
/usr/local/share/nems/nems-scripts/info2.sh 10 $VARIABLE

elif [[ $COMMAND == "rootdev" ]]; then
# output json response of detected wifi networks
/usr/local/share/nems/nems-scripts/info2.sh 8
Expand Down
38 changes: 38 additions & 0 deletions info2.sh
Expand Up @@ -7,6 +7,12 @@

if (!isset($argv[1])) exit('Invalid usage. Please use the nems-info command.' . PHP_EOL);

if (isset($argv[2]) && strlen($argv[2]) > 0) {
$VARIABLE = trim($argv[2]);
} else {
$VARIABLE = '';
}

switch($argv[1]) {

case 1: // temperature
Expand Down Expand Up @@ -130,6 +136,38 @@ switch($argv[1]) {
}
break;

case 10: // output the recommended speedtest server number
if ($VARIABLE == 'best') {
exec('/usr/local/share/nems/nems-scripts/speedtest --list',$servernum_tmp);
if (is_array($servernum_tmp)) {
foreach ($servernum_tmp as $line) {
$tmp = explode(')',$line);
if (intval($tmp[0]) > 0) {
$speedtestservers[] = array(
'num'=>intval($tmp[0]),
);
break; // we only need one
}
}
}
echo $speedtestservers[0]['num'];
} elseif ($VARIABLE == 'which') {
$speedtestwhich = intval(trim(shell_exec("cat /usr/local/share/nems/nems.conf | grep speedtestwhich | printf '%s' $(cut -n -d '=' -f 2)")));
// best = most local server as detected by NEMS
// switch = the passed server number on the check_command's arg
if ($speedtestwhich == 0) { echo 'best'; } else { echo 'switch'; }
} else {
$speedtestserver = intval(trim(shell_exec("cat /usr/local/share/nems/nems.conf | grep speedtestserver | printf '%s' $(cut -n -d '=' -f 2)")));
if ($speedtestserver > 0) {
echo $speedtestserver;
} else {
$speedtestserver = intval(trim(shell_exec("/usr/local/bin/nems-info speedtest best")));
file_put_contents('/usr/local/share/nems/nems.conf','speedtestserver=' . $speedtestserver . PHP_EOL, FILE_APPEND);
echo $speedtestserver;
}
}
break;

}


Expand Down
14 changes: 14 additions & 0 deletions upgrade.sh
Expand Up @@ -301,13 +301,27 @@ vm.swappiness = 10
fi
fi

if ! grep -q "PATCH-000004" /var/log/nems/patches.log; then
echo "PATCH-000004 is available."
echo "This patch upgrades the Internet speedtest check command so you"
echo "can have it automatically use the best available server rather"
echo "than the one specified in the checkcommand's arg."
echo "Alternatively you can just download a newer NEMS Linux build for"
echo "your platform, released after March 28, 2019."
read -r -p "Do you want to install this patch? [y/N] " PATCH000004
echo ""
fi

# Run the selected patches
if [[ $PATCH000001 =~ ^([yY][eE][sS]|[yY])$ ]]; then
/root/nems/nems-admin/nems-upgrade/patches/000001 && upgraded=1
fi
if [[ $PATCH000003 =~ ^([yY][eE][sS]|[yY])$ ]]; then
/root/nems/nems-admin/nems-upgrade/patches/000003 && upgraded=1
fi
if [[ $PATCH000004 =~ ^([yY][eE][sS]|[yY])$ ]]; then
/root/nems/nems-admin/nems-upgrade/patches/000004 && upgraded=1
fi

fi

Expand Down

0 comments on commit 55a3cc5

Please sign in to comment.