Cannot get Desktop shortcut to be created on Linux-64 when installing under SUDO

Comments

2 comments

  • Avatar
    wojciechka

    Running with sudo causes the shortcuts to be put in root user's desktop, not current user. Unfortunately Unix systems do not provide equivalent of Windows' common desktop items that are put on all users' desktops.

    It is possible to determine directory for creation of icons by checking SUDO_USER environment variable and creating the shortcuts as actions:

    <setInstallerVariable> <name>desktop_directory</name> <value>~/Desktop</value> </setInstallerVariable> <setInstallerVariable> <name>desktop_directory</name> <value>~${env(SUDO_USER)}/Desktop</value> <ruleList> <compareTextLength> <length>0</length> <logic>greater</logic> <text>${env(SUDO_USER)}</text> </compareTextLength> </ruleList> </setInstallerVariable> <createShortcuts> <destination>${desktop_directory}</destination> <shortcutList> <!-- shortcuts to create --> </shortcutList> </createShortcuts>

    However, this may not work for gksu or kdesu commands.

  • Avatar
    Chard Nelson

    I got this to work with both sudo and kdesu as follows:

    <setInstallerVariable>
        <name>realUser</name>
        <value>${env(SUDO_USER)}</value>
        <ruleList>
            <stringTest text="${env(SUDO_USER)}" type="not_empty"/>
        </ruleList>
    </setInstallerVariable>
    <setInstallerVariable>
        <name>realUser</name>
        <value>${env(KDESU_USER)}</value>
        <ruleList>
            <stringTest text="${env(KDESU_USER)}" type="not_empty"/>
        </ruleList>
    </setInstallerVariable>
    <setInstallerVariable name="desktopDir" value="/home/${realUser}/Desktop"/>
    

    Then when you go to create the shortcuts, make sure the desktopDir exists:

    <createShortcuts>
      <destination>${desktopDir}</destination>
      <shortcutList>
       ...
      </shortcutList>
      <ruleList>
        <fileTest path="${desktopDir}" condition="is_directory"/>
      </ruleList>
    </createShortcuts>
    

    I think it also works with the GNOME gksudo, which also sets SUDO_USER, if I recall correctly.

Please sign in to leave a comment.