#!/bin/bash

## Copyright (C) 2012 - 2018 ENCRYPTED SUPPORT LP <adrelanos@riseup.net>
## See the file COPYING for copying conditions.

sigterm_trap() {
   if [ "$lastpid" = "" ]; then
      exit 143
   fi
   ps -p "$lastpid" >/dev/null 2>&1
   if [ ! "$?" = "0" ]; then
      ## Already terminated.
      exit 143
   fi
   kill -s sigterm "$lastpid"
   exit 143
}

trap "sigterm_trap" SIGTERM SIGINT

timeout_after="240"
kill_after="10"

timeout \
   --kill-after="$kill_after" \
   "$timeout_after" \
   /usr/lib/security-misc/apt-get-wrapper update &

lastpid="$!"
wait "$lastpid"

exit "$?"