#!/bin/env sh
# Pixel 2025
# https://pi66.xyz/pind | github:pixel2175/pind
# this script runs the daemon with the client env
env_cmd="$1"
[ -z "$env_cmd" ] && env_cmd="sudo"
pgrep -x "pindd" >/dev/null 2>&1 && $env_cmd pkill -x "pindd" >/dev/null 2>&1
if [ "$env_cmd" = "doas" ]; then
exec doas -u root env <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mo stretchy="false">(</mo><mi>p</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>t</mi><mi>e</mi><mi>n</mi><mi>v</mi><mo stretchy="false">|</mo><mi>g</mi><mi>r</mi><mi>e</mi><mi>p</mi><mo>−</mo><mi>v</mi><msup><mi>"</mi><mi>′</mi></msup><mi>"</mi><mo stretchy="false">|</mo><mi>t</mi><msup><mi>r</mi><mi>′</mi></msup><msup><mi>\n</mi><mi>″</mi></msup><mi>\</mi><msup><mn>0</mn><mi>′</mi></msup><mo stretchy="false">|</mo><mi>x</mi><mi>a</mi><mi>r</mi><mi>g</mi><mi>s</mi><mo>−</mo><mn>0</mn><mo>−</mo><mi>I</mi><mrow /><mi>e</mi><mi>c</mi><mi>h</mi><mi>o</mi><mi>"</mi><mrow /><mi>"</mi><mo stretchy="false">)</mo><mi>p</mi><mi>i</mi><mi>n</mi><mi>d</mi><mi>d</mi><mi>"</mi></mrow></math>USER"
elif [ "$env_cmd" = "sudo" ]; then
exec sudo -E env pindd "$USER"
else
exec "<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>e</mi><mi>n</mi><msub><mi>v</mi><mi>c</mi></msub><mi>m</mi><mi>d</mi><mi>"</mi><mi>p</mi><mi>i</mi><mi>n</mi><mi>d</mi><mi>d</mi><mi>"</mi></mrow></math>USER"
fi