Skip to content

Commit

Permalink
use utc again, fedora support
Browse files Browse the repository at this point in the history
  • Loading branch information
ipitio committed Feb 8, 2024
1 parent dce50a9 commit 8551bdd
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 29 deletions.
77 changes: 54 additions & 23 deletions advanced/Scripts/speedtestmod/mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ manageHistory() {
}

notInstalled() {
apt-cache policy "$1" | grep 'Installed: (none)' >/dev/null
if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then
rpm -q "$1" &>/dev/null || return 0
elif [ -x "$(command -v apt-get)" ]; then
dpkg -s "$1" &>/dev/null || return 0
else
echo "Unsupported package manager!"
exit 1
fi
return 1
}

install() {
Expand All @@ -120,32 +128,55 @@ install() {
fi

local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2)
apt-get update
apt-get install -y bc sqlite3 php$PHP_VERSION-sqlite3 jq tmux curl wget

if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then
echo "Adding speedtest source..."
if [ -e /etc/os-release ]; then
. /etc/os-release
local base="ubuntu debian"
local os=${ID}
local dist=${VERSION_CODENAME}
if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then
os=${ID_LIKE%% *}
[ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs)
dist=${UBUNTU_CODENAME}
[ -z "$dist" ] && dist=${VERSION_CODENAME}
local PKG_MANAGER=$(command -v apt-get || command -v yum || command -v dnf)
local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3")

if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then
apt-get update
fi

local missingPkgs=()
for pkg in "${PKGS[@]}"; do
if notInstalled "$pkg"; then
missingPkgs+=("$pkg")
fi
done

if [ ${#missingPkgs[@]} -gt 0 ]; then
sudo $PKG_MANAGER install -y "${missingPkgs[@]}"
fi

if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then
if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then
echo "Adding speedtest source for RPM..."
sudo bash -c 'curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash'
fi
elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then
if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then
echo "Adding speedtest source for DEB..."
if [ -e /etc/os-release ]; then
. /etc/os-release
local base="ubuntu debian"
local os=${ID}
local dist=${VERSION_CODENAME}
if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then
os=${ID_LIKE%% *}
[ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs)
dist=${UBUNTU_CODENAME}
[ -z "$dist" ] && dist=${VERSION_CODENAME}
fi
wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1
chmod +x /tmp/script.deb.sh
os=$os dist=$dist /tmp/script.deb.sh
rm -f /tmp/script.deb.sh
else
curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
fi
wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1
chmod +x /tmp/script.deb.sh
os=$os dist=$dist /tmp/script.deb.sh
rm -f /tmp/script.deb.sh
else
curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
fi
fi

if notInstalled speedtest && notInstalled speedtest-cli; then
apt-get install -y speedtest
sudo $PKG_MANAGER install -y speedtest
fi
if [ -f /usr/local/bin/speedtest ]; then
rm -f /usr/local/bin/speedtest
Expand Down
32 changes: 26 additions & 6 deletions advanced/Scripts/speedtestmod/speedtest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
FILE=/tmp/speedtest.log
start=$(date +"%Y-%m-%d %H:%M:%S %Z")
start=$(date -u -I'minutes')
serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2)

create_table="create table if not exists speedtest (
Expand Down Expand Up @@ -35,7 +35,7 @@ speedtest() {
}

internet() {
stop=$(date +"%Y-%m-%d %H:%M:%S %Z")
stop=$(date -u -I'minutes')
res="$(<$FILE)"
server_name=$(jq -r '.server.name' <<< "$res")
server_dist=0
Expand Down Expand Up @@ -68,17 +68,37 @@ internet() {
}

nointernet(){
stop=$(date +"%Y-%m-%d %H:%M:%S %Z")
stop=$(date -u -I'minutes')
echo "No Internet"
sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');"
exit 1
}

notInstalled() {
if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then
rpm -q "$1" &>/dev/null || return 0
elif [ -x "$(command -v apt-get)" ]; then
dpkg -s "$1" &>/dev/null || return 0
else
echo "Unsupported package manager!"
exit 1
fi
return 1
}

tryagain(){
if apt-cache policy speedtest-cli | grep -q 'Installed: (none)'; then
apt-get install -y speedtest-cli speedtest-
if notInstalled speedtest-cli; then
if [ -x "$(command -v apt-get)" ]; then
apt-get install -y speedtest-cli speedtest-
else
yum install -y --allowerasing speedtest-cli
fi
else
apt-get install -y speedtest speedtest-cli-
if [ -x "$(command -v apt-get)" ]; then
apt-get install -y speedtest speedtest-cli-
else
yum install -y --allowerasing speedtest
fi
fi
speedtest > "$FILE" && internet || nointernet
}
Expand Down

0 comments on commit 8551bdd

Please sign in to comment.