#!/bin/bash

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

set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit
shopt -s shift_verbose
export LC_ALL=C

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

if [ ! "$(id -u)" = "0" ]; then
   printf '%s\n' "$0: ERROR: Needs to run as root. Run:
sudo $0" >&2
   exit 1
fi

if ! has gcc ; then
   printf '%s\n' "$0: ERROR: gcc not installed. To install:

   sudo apt update

sudo apt --no-install-recommends install gcc" >&2
   exit 1
fi

gcc /usr/share/debug-misc/segfault.c -g -o /usr/bin/segfault-run

printf '%s\n' "$0: SUCCESS. You can now run:"
printf '%s\n' "segfault-run"
