#!/bin/sh
# Linux Terminal, run as administrator: a root shell on the machine, for what only
# Linux itself can do -- installing a driver, a kernel module, a Debian
# package. Opening it asks for the user's own password (sudo), and only an
# administrator (sg-admins) gets in. Started from the Start menu by
# sg-rootterm64.exe --admin (Start's "Run as administrator" on Linux Terminal).
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# shellcheck disable=SC2016  # $1 is the inner shell's
MSG='Linux Terminal (Administrator): what you run here runs as root, for the whole machine.'
# Copy and paste as in the Windows console (David 2026-10-01: Ctrl+Shift+V
# did nothing, and nothing could be copied out): what you select is copied,
# a right-click pastes; Ctrl+Shift+C / Ctrl+Shift+V and Shift+Insert too.
# xterm's own default pasted only with the middle button.
SG_XTERM_COPY_PASTE='*VT100.translations: #override \nCtrl Shift <Key>C: copy-selection(CLIPBOARD) \nCtrl Shift <Key>V: insert-selection(CLIPBOARD) \nShift <Key>Insert: insert-selection(CLIPBOARD) \n<Btn1Up>: select-end(CLIPBOARD, PRIMARY) \n<Btn3Down>: ignore() \n<Btn3Up>: insert-selection(CLIPBOARD)'
exec xterm -class SgRootTerminal -title 'Administrator: Linux Terminal' \
    -fa 'Cascadia Mono' -fs 11 -bg '#0c0c0c' -fg '#cccccc' -cr '#cccccc' \
    -geometry 110x30 -sl 5000 -xrm '*selectToClipboard: true' -xrm "$SG_XTERM_COPY_PASTE" \
    -e sh -c 'printf "%s\n\n" "$1"; sudo -i || { printf "\nOnly an administrator can open this terminal. Press Enter to close it."; read -r _; }' \
    sg-root-terminal "$MSG"
