#!/bin/sh
#Copyright: 2026 Aitor <aitor@genuen.org>
#License: CC0-1.0
#Comment: oneshot; invoke with: sv once sudo
#Comment: prepare /run/sudo

exec 2>&1

ebegin() { [ "${VERBOSE:-}" = no ] || echo "$@"; }
eend() { r=${1:-0}; shift || true; [ "$r" -eq 0 ] || [ "${VERBOSE:-}" = no ] || echo "$*" >&2; return "$r"; }
einfo() { [ "${VERBOSE:-}" = no ] || echo "$@"; }
ewarn() { echo "$@" >&2; }
eerror() { echo "$@" >&2; }

[ -d /run/systemd/system ] && exit 0
ebegin "Setting up sudo privilege state"
if [ -d /run/sudo ]; then
  find /run/sudo -exec touch -d @0 '{}' \;
else
  mkdir /run/sudo /run/sudo/ts
  chown root:root /run/sudo /run/sudo/ts
  chmod 0711 /run/sudo
  chmod 0700 /run/sudo/ts
  [ -x /sbin/restorecon ] && /sbin/restorecon /run/sudo /run/sudo/ts
fi
eend 0
exit 0
