Skip to content

Instantly share code, notes, and snippets.

@Ste74
Created November 20, 2017 17:13
Show Gist options
  • Save Ste74/ec87ff0c8ad5f90002c80f81309c90b8 to your computer and use it in GitHub Desktop.
Save Ste74/ec87ff0c8ad5f90002c80f81309c90b8 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
<policyconfig>
<vendor>Manjaro</vendor>
<vendor_url>http://manjaro.org/</vendor_url>
<icon_name>package-x-generic</icon_name>
<action id="org.manjaro.pkexec.pacman_mirrors">
<message gettext-domain="pacman-mirrors">Authentication is required to run pacman-mirrors</message>
<description>Run pacman-mirrors as Administrator</description>
<defaults>
<allow_any>auth_admin</allow_any>
<allow_inactive>auth_admin</allow_inactive>
<allow_active>auth_admin</allow_active>
</defaults>
<annotate key="org.freedesktop.policykit.exec.path">/usr/bin/pacman_mirrors</annotate>
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
</action>
</policyconfig>
#!/bin/bash
app="pacman-mirrors $*"
if [ `id -u` -eq 0 ]; then
#user is admin
${app}
else
#user is not admin
if `echo $- | grep "i" >/dev/null 2>&1`; then
#script is running in interactive mode
su - -c "${app}"
else
#script is running in non-interactive mode
if [ $XDG_SESSION_TYPE = "wayland" ] ; then
xhost +SI:localuser:root
pkexec ${app}
xhost -SI:localuser:root
xhost
elif command -v pkexec >/dev/null 2>&1; then
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY ${app}
elif command -v sudo >/dev/null 2>&1; then
x-terminal-emulator -e "sudo ${app}"
elif command -v su >/dev/null 2>&1; then
x-terminal-emulator -e "su - -c '${app}'"
else
x-terminal-emulator -e "echo 'Command must be run as root user: ${app}'"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment