#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o errtrace
set -o pipefail
shopt -s inherit_errexit
shopt -s shift_verbose

# shellcheck source=./has.sh
source "${HELPER_SCRIPTS_PATH:-}"/usr/libexec/helper-scripts/has.sh

has start-stop-daemon

pidfile="/run/helper-scripts/apt-get-update-pid"

if ! test -f "${pidfile}" ; then
  printf "%s\n" "$0: INFO: pidfile ${pidfile} does not exist, ok."
  exit 0
fi

if start-stop-daemon --stop --quiet --retry=TERM/5/KILL/5 --pidfile "${pidfile}" &>/dev/null ; then
  printf "%s\n" "$0: INFO: apt-get update pid killed, ok."
else
  printf "%s\n" "$0: INFO: apt-get update pid was no longer running, ok"
fi

exit 0
