#!/bin/bash

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

#set -x
set -e

## Cannot check if it is a file first because then no new files could be created.
# if ! test -f "$@" ; then
#   exit 1
# fi

## Running any editor as root is insecure.
## sudoedit copies the file to a temporary location, edits it as a normal user
## and then overwrites the original using sudo.
## This way is much more secure as it does not run the editor as root.
##
## How to prompt for the sudo password with a graphical GUI when using sudoedit?
##
## Must be Wayland compatible.

## sudo does not pass environment variables to SUDO_ASKPASS tool.
# askpass_title="$0: Authorization Required."
# askpass_message="Open the following file with root rights?
#
# '$@'"
#
# export askpass_title
# export askpass_message

SUDO_ASKPASS=/usr/libexec/usability-misc/sudo-askpass-gui sudoedit --askpass -- "$@"
