#!/bin/bash

## Copyright (C) 2026 - 2026 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

## shellcheck source=../../../../helper-scripts/usr/libexec/helper-scripts/log_run_die.sh
source /usr/libexec/helper-scripts/log_run_die.sh

tb_updater_uid="$(id -u tb-updater)"
if [ -z "${tb_updater_uid}" ]; then
   log error "Unable to get UID of account 'tb-updater'! Exiting."
   exit 1
fi
tb_updater_gid="$(id -g tb-updater)"
if [ -z "${tb_updater_gid}" ]; then
   log error "Unable to get GID of account 'tb-updater'! Exiting."
   exit 1
fi

log notice "Executing under account tb-updater: '$*'"
setpriv --reuid "${tb_updater_uid}" --regid "${tb_updater_gid}" \
  --init-groups --reset-env -- "$@"
