Here are fixes for this and the other issues that stop Unix shortcuts from working when there is a space in the install path. (Using code from IzPack 4.3)
Issue 1: In the generated .desktop files, the opening and closing quote should be removed from the line beginning with Path= . (See original bug report.)
This can be done by changing line
hlp.append("Path=" + $P_QUOT + $Path + $P_QUOT + N);
to
hlp.append("Path=" + $Path + N);
in the source file lib/com/izforge/izpack/util/os/Unix_Shortcut.java.
The value for Icon should NOT be enclosed in quotation marks or have escaped spaces. (e.g. Icon=/home/andrew/my favorite program/icon/Icon.png)
The value for Exec SHOULD be enclosed in quotation marks, or have escaped spaces. (e.g. Exec="/home/andrew/my favorite program/bin/program")
Issue 2: While installing shortcuts, the installer tries to execute a script located in $INSTALL_PATH/Shortcuts. However, if the INSTALL_PATH has a space in it, the installer cannot find the script to run, and the shortcuts are not installed to the desktop. The instruction to execute the script needs to have spaces escaped.
This is accomplished by changing lines
myInstallScript.appendln(new String[]
{ myXdgDesktopIconCmd, "install",
"--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}
);
to
myInstallScript.appendln(new String[]
{ StringTool.escapeSpaces(myXdgDesktopIconCmd), "install",
"--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}
);
in the source file lib/com/izforge/izpack/util/os/Unix_Shortcut.java.
The same problem exists when uninstalling, i.e. the instruction to run the script needs to have spaces escaped.
This is accomplished by changing the line
myUninstallScript.appendln(new String[]
{ myXdgDesktopIconCmd, "uninstall",
"--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}
);
to
myUninstallScript.appendln(new String[]
{ StringTool.escapeSpaces(myXdgDesktopIconCmd), "uninstall",
"--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}
);
in the same file.
Issue 3: The xdgdesktopiconscript.sh script that the installer calls during shortcut installation fails to copy the .desktop file to the desktop if there are spaces in the install path. This problem can be fixed by putting quotation marks around three variables in the script.
The line
eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
should be changed to
eval 'cp "$desktop_file" "$x/$basefile"'$xdg_redirect_output
in the file lib/com/izforge/izpack/util/os/unix/xdgdesktopiconscript.sh.
After implementing these fixes, installation and uninstallation of shortcuts on Unix using IzPack worked perfectly for me, even when there were spaces in the install path.
Here are fixes for this and the other issues that stop Unix shortcuts from working when there is a space in the install path. (Using code from IzPack 4.3)
Issue 1: In the generated .desktop files, the opening and closing quote should be removed from the line beginning with Path= . (See original bug report.)
This can be done by changing line
hlp.append("Path=" + $P_QUOT + $Path + $P_QUOT + N);
to
hlp.append("Path=" + $Path + N);
in the source file lib/com/izforge/izpack/util/os/Unix_Shortcut.java.
The value for Icon should NOT be enclosed in quotation marks or have escaped spaces. (e.g. Icon=/home/andrew/my favorite program/icon/Icon.png)
The value for Exec SHOULD be enclosed in quotation marks, or have escaped spaces. (e.g. Exec="/home/andrew/my favorite program/bin/program")
Issue 2: While installing shortcuts, the installer tries to execute a script located in $INSTALL_PATH/Shortcuts. However, if the INSTALL_PATH has a space in it, the installer cannot find the script to run, and the shortcuts are not installed to the desktop. The instruction to execute the script needs to have spaces escaped.
This is accomplished by changing lines
myInstallScript.appendln(new String[]
{ myXdgDesktopIconCmd, "install", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())});
{ StringTool.escapeSpaces(myXdgDesktopIconCmd), "install", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}to
myInstallScript.appendln(new String[]
);
in the source file lib/com/izforge/izpack/util/os/Unix_Shortcut.java.
The same problem exists when uninstalling, i.e. the instruction to run the script needs to have spaces escaped.
This is accomplished by changing the line
myUninstallScript.appendln(new String[]
{ myXdgDesktopIconCmd, "uninstall", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())});
{ StringTool.escapeSpaces(myXdgDesktopIconCmd), "uninstall", "--novendor", StringTool.escapeSpaces(writtenDesktopFile.toString())}to
myUninstallScript.appendln(new String[]
);
in the same file.
Issue 3: The xdgdesktopiconscript.sh script that the installer calls during shortcut installation fails to copy the .desktop file to the desktop if there are spaces in the install path. This problem can be fixed by putting quotation marks around three variables in the script.
The line
eval 'cp $desktop_file $x/$basefile'$xdg_redirect_output
should be changed to
eval 'cp "$desktop_file" "$x/$basefile"'$xdg_redirect_output
in the file lib/com/izforge/izpack/util/os/unix/xdgdesktopiconscript.sh.
After implementing these fixes, installation and uninstallation of shortcuts on Unix using IzPack worked perfectly for me, even when there were spaces in the install path.