How to avoid problems on Linux with gksudo

Answered

Comments

1 comment

  • Avatar
    juanjo

    From the point of view of the installer (from the environment it gets), the user running the binary is root. If you need to retrieve the logged in user that runs the installer, you could try the below:

    <!-- SUDO_USER is defined just when using sudo -->
     <setInstallerVariable name="username"
    value="${env(SUDO_USER)}">
      <ruleList>
        <platformTest>
           <type>osx</type>
        </platformTest>
      </ruleList>
     </setInstallerVariable>
     <setInstallerVariable name="username"
    value="${env(SUDO_USER)}">
       <ruleList>
          <platformTest>
            <type>linux</type>
          </platformTest>
       </ruleList>
     </setInstallerVariable>
     <setInstallerVariable name="username"
    value="${system_username}">
      <ruleList>
       <!-- Accessing non-existent environment
    variables result in an empty string -->
        <compareText text="${username}"
    logic="equals" value=""/>
      </ruleList>
     </setInstallerVariable>
     <setInstallerVariableFromScriptOutput>
     <name>desktopDir</name>
     <exec>xdg-user-dir</exec>
     <execArgs></execArgs>
     <ruleList>
          <programTest>
              <condition>is_in_path</condition>
              <name>xdg-user-dir</name>
          </programTest>
     </ruleList>
     </setInstallerVariableFromScriptOutput>
     <setInstallerVariable name="homeDir" value="~${username}">
     <ruleList>
          <programTest>
              <condition>is_in_path</condition>
              <name>xdg-user-dir</name>
              <negate>1</negate>
          </programTest>
     </ruleList>
     </setInstallerVariable>
    

    In any case, the above will still fail if the user launches the installer with 'su -'

Please sign in to leave a comment.