#!/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

command -v start-stop-daemon >/dev/null

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
