#!/bin/bash
# Launcher for PartitionManager that requires an interactive sudo
# password before the application is allowed to perform disk
# operations. The application itself runs as the normal user (not
# root);

set -e

echo "PartitionManager requires administrator privileges for disk operations."
echo "Please authenticate with sudo to continue."
echo

# Prompts for password and caches a sudo credential for this user,
# without running any command yet.
if ! sudo -v; then
    echo
    echo "Authentication failed or was cancelled. Not launching PartitionManager."
    read -n 1 -s -r -p "Press any key to close this window..."
    exit 1
fi

echo
echo "Authenticated. Launching PartitionManager..."
sleep 1

# Run unprivileged; mainwindow.cpp's askForPermissions() checks for the
# sudo credential just established above via `sudo -n -v`.
/usr/bin/partitionmanager

