@@ -22,10 +22,38 @@ WRAPPER_PATH="/usr/bin/undervolt-go-wrapper"
2222echo " Creating pkexec wrapper at ${WRAPPER_PATH} ..."
2323cat << EOF > "${WRAPPER_PATH} "
2424#!/bin/bash
25- export DISPLAY=:0
26- export XAUTHORITY=/home/\$ {SUDO_USER}/.Xauthority
25+ # Determine the user who initiated the pkexec action
26+ if [ -n "$PKEXEC_UID " ]; then
27+ USER=$( id -un " $PKEXEC_UID " )
28+ elif [ -n "$SUDO_USER " ]; then
29+ USER="$SUDO_USER "
30+ else
31+ echo "Error: Could not determine the user. PKEXEC_UID and SUDO_USER are unset." >&2
32+ exit 1
33+ fi
34+ # Check if the user was found
35+ if [ -z "$USER " ]; then
36+ echo "Error: Could not determine the user." >&2
37+ exit 1
38+ fi
39+ # Get the user's home directory
40+ USER_HOME=$( eval echo " ~${USER} " )
41+ # Set up the display environment
42+ if [ -z "$DISPLAY " ]; then
43+ export DISPLAY=:0 # Fallback to :0 if DISPLAY is not set
44+ fi
45+ # Set up Xauthority
46+ if [ -f "${USER_HOME} /.Xauthority" ]; then
47+ export XAUTHORITY="${USER_HOME} /.Xauthority"
48+ else
49+ echo "Warning: .Xauthority file not found for user ${USER} ." >&2
50+ fi
51+ # Debugging: Log environment variables
52+ echo "Launching undervolt-go-pro with DISPLAY=$DISPLAY , XAUTHORITY=$XAUTHORITY , USER=$USER " >&2
53+ # Execute the binary
2754exec ${INSTALL_PATH}
2855EOF
56+
2957chmod +x " ${WRAPPER_PATH} "
3058
3159# Install icon (optional: replace with your own icon)
@@ -42,6 +70,8 @@ echo "Creating PolicyKit policy at ${POLKIT_FILE}..."
4270cat << EOF > "${POLKIT_FILE} "
4371<?xml version="1.0" encoding="UTF-8"?>
4472<policyconfig>
73+ <vendor>Softorage</vendor>
74+ <vendor_url>https://softorage.com</vendor_url>
4575 <action id="com.softorage.undervolt-go">
4676 <description>Run 'Undervolt Go' as root</description>
4777 <message>Authentication is required to run 'Undervolt Go'</message>
@@ -51,10 +81,16 @@ cat <<EOF > "${POLKIT_FILE}"
5181 <allow_inactive>auth_admin</allow_inactive>
5282 <allow_active>auth_admin</allow_active>
5383 </defaults>
84+ <annotate key="org.freedesktop.policykit.exec.path">/usr/bin/undervolt-go-wrapper</annotate>
85+ <annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
86+ <annotate key="org.freedesktop.policykit.exec.environment">DISPLAY XAUTHORITY</annotate>
5487 </action>
5588</policyconfig>
5689EOF
5790
91+ # set file permissions, allowing the owner read and write access, while group and others have only read access
92+ chmod 644 /usr/share/polkit-1/actions/com.softorage.undervolt-go.policy
93+
5894# Install desktop file
5995DESKTOP_FILE=" /usr/share/applications/undervolt-go.desktop"
6096echo " Creating desktop shortcut at ${DESKTOP_FILE} ..."
0 commit comments