42 lines
663 B
Bash
42 lines
663 B
Bash
|
#!/usr/bin/bash
|
||
|
|
||
|
# error if 'pwsh' not in path
|
||
|
if [ ! which pwsh > /dev/null 2>&1 ]; then
|
||
|
echo "no 'pwsh' in \$PATH"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# set mode (linux/dos)
|
||
|
if [[ "$1" == "-l" ]]; then
|
||
|
mode='linux'
|
||
|
shift
|
||
|
elif [[ "$1" == "-w" ]]; then
|
||
|
mode='dos'
|
||
|
shift
|
||
|
fi
|
||
|
|
||
|
# error if no target
|
||
|
if [ "$#" -eq 0 ]; then
|
||
|
echo "elevate: no target"
|
||
|
exit 3
|
||
|
fi
|
||
|
|
||
|
# consume target based on mode
|
||
|
if [[ "$mode" == "linux" ]]; then
|
||
|
target='wsl.exe'
|
||
|
elif [[ "$mode" == "dos" ]]; then
|
||
|
target="$1"
|
||
|
shift
|
||
|
else
|
||
|
echo "elevate: no mode set; use '-l' or '-w'"
|
||
|
exit 2
|
||
|
fi
|
||
|
|
||
|
arglist=''
|
||
|
if [ "$#" -ne 0 ]; then
|
||
|
arglist="-ArgumentList '$@'"
|
||
|
fi
|
||
|
|
||
|
pwsh -C "Start-Process -Verb runas $target $arglist"
|
||
|
|