Skip to content

Commit

Permalink
fix failing tests and package cache check (#113)
Browse files Browse the repository at this point in the history
* fix package check

* git status was the issue
  • Loading branch information
ipitio authored Apr 27, 2024
1 parent 27695c5 commit 1879f77
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
24 changes: 14 additions & 10 deletions advanced/Scripts/speedtestmod/mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ getVersion() {
if [[ -d "$1" ]]; then
pushd "$1" &>/dev/null || exit 1
found_version=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}')
[[ $found_version != *"("* ]] || found_version=$(git rev-parse HEAD 2>/dev/null)

if [[ -z "${2:-}" ]]; then
local tags
Expand All @@ -38,7 +39,10 @@ getVersion() {
found_version=$(cut -d ' ' -f 6 <<<"$versions")

if [[ "$found_version" != *.* ]]; then
[[ "$found_version" != "$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions")
local found_branch
found_branch="$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')"
[[ $found_branch != *"("* ]] || found_branch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3)
[[ "$found_version" != "$found_branch" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions")
fi
fi

Expand Down Expand Up @@ -476,7 +480,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then

readonly update backup online install reinstall stable uninstall database verbose chk_dep cleanup
trap '[ "$?" -eq "0" ] && commit || abort' EXIT
printf "%s\n\nRunning The Mod Script by @ipitio...\n" "$(date)"
printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)"
! $verbose || set -x

if $database; then
Expand All @@ -503,7 +507,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then

if ! $database || [[ "$num_args" -gt 1 ]]; then
pushd ~ >/dev/null || exit 1
pihole -v
pihole -v || :

if [[ -f $CURR_WP ]] && grep -q SpeedTest "$CURR_WP"; then
if $reinstall; then
Expand Down Expand Up @@ -574,13 +578,13 @@ if [[ "${SKIP_MOD:-}" != true ]]; then

readonly missingpkgs
if [[ ${#missingpkgs[@]} -gt 0 ]]; then
if [[ "$pkg_manager" == *"apt-get"* ]] && apt-cache show "${missingpkgs[@]}" | grep -q "Unable to locate package"; then
echo "Updating Package Cache..."
apt-get update -y &>/dev/null
fi

echo "Installing Missing Dependencies..."
$pkg_manager install -y "${missingpkgs[@]}" &>/dev/null # hide an unimportant warning in docker
if ! $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null; then
[[ "$pkg_manager" == *"apt-get"* ]] || exit 1
echo "And Updating Package Cache..."
$pkg_manager update -y &>/dev/null
$pkg_manager install -y "${missingpkgs[@]}" &>/dev/null
fi
fi
fi

Expand Down Expand Up @@ -623,7 +627,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then
fi

pihole updatechecker
pihole -v
pihole -v || :
popd >/dev/null
fi

Expand Down
10 changes: 7 additions & 3 deletions advanced/Scripts/updatecheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function get_local_branch() {
cd "${1}" 2> /dev/null || return 1
local foundBranch
foundBranch=$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')
[[ $foundBranch != *"("* ]] || foundBranch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3)
echo "${foundBranch:-HEAD}"
}

Expand All @@ -21,8 +22,9 @@ function get_local_version() {
cd "${1}" 2> /dev/null || return 1
local tags
local foundVersion
tags=$(git ls-remote -t origin)
tags=$(git ls-remote -t origin || git show-ref --tags)
foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}')
[[ $foundVersion != *"("* ]] || foundVersion=$(git rev-parse HEAD 2>/dev/null)
local foundTag=$foundVersion
# shellcheck disable=SC2015
grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || :
Expand All @@ -32,7 +34,9 @@ function get_local_version() {

function get_local_hash() {
cd "${1}" 2> /dev/null || return 1
git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' || return 1
foundHash=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}')
[[ $foundHash != *"("* ]] || foundHash=$(git rev-parse HEAD 2>/dev/null)
echo "${foundHash}"
}

function get_remote_version() {
Expand All @@ -48,7 +52,7 @@ function get_remote_hash(){

for repo in "arevindh" "pi-hole" "ipitio"; do
foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' 2> /dev/null)
[[ -n "${foundHash}" ]] && break
[[ -z "${foundHash}" ]] || break
done

[[ -n "${foundHash}" ]] && echo "${foundHash}" || return 1
Expand Down

0 comments on commit 1879f77

Please sign in to comment.