gnome 3 packaging using qt installer framework



  • I used 'qt installer framework' for package my app and I got '.run' package but after installation, it didn't show up in the software list, I know I need to configure it but I can't find a good documentation.





  • This is my take. Please comment back if you find a better way. Suggest you use a separate script for installation and de-installation and take care of both the application and maintenance tool together. There are 3 is steps involved:
    Step 1. Creating the scripts to be run on installation and de-installation
    Step 2. Including the scripts into the installation bundle
    Step 3. Modifying the installations and de-installation process to invoke the scrips at the appropriate time

    Step 1: Creating the Scripts
    Step 1a: Creating the Installation Scripts
    The installation scripts can perform the following actions:
    a. Create .desktop files for the application and the maintenance tool
    b. Move the icons to the appropriate location
    c. Use the gnome tool gio to associate the icon with the application and maintenance tool
    b. Add the new application to favourites

    The following is called linuxInstall.bash and is located in my ~/pkg folder

    #------Start of the installation script
    #!/bin/bash
    
    #Get the location  of the script = location of executables and icons
    SCRIPT=$(readlink -f "$0")
    SCRIPTPATH=$(dirname "$SCRIPT")
    
    #Work out the destination file locations
    ICONDESTINATION=$1"/.local/share/icons/hicolor/48x48/apps/MyApp.png"
    MYAPPDESKTOP=$1"/.local/share/applications/MyApp.desktop"
    MyAPPMAINTDESKTOP=$1"/.local/share/applications/MyAppMaintenance.desktop"
    
    #Move the icon
    mv $SCRIPTPATH/MyApp.png $ICONDESTINATION
    
    #Write out the MyApp.desktop file
    echo "[Desktop Entry]" >> $MyAppDESKTOP
    echo "Version=0.1" >> $MyAppDESKTOP
    echo "Name=MyApp" >> $MyAppDESKTOP
    echo "Comment=Does super important stuff" >> $MyAppDESKTOP
    echo "Exec=$SCRIPTPATH/MyApp" >> $MyAppDESKTOP
    echo "Icon=$ICONDESTINATION">> $MyAppDESKTOP
    echo "Terminal=false" >> $MyAppDESKTOP
    echo "Type=Application" >> $MyAppDESKTOP
    echo "Categories=Utility" >> $MyAppDESKTOP
    
    #Write out the MyAppMaintenance.desktop file
    echo "[Desktop Entry]" >> $MYAPPMAINTDESKTOP
    echo "Version=0.2" >> $MYAPPMAINTDESKTOP
    echo "Name=MyApp Maintenance Tool" >> $MYAPPMAINTDESKTOP
    echo "Comment=Install, update and delete MyApp" >> $MyAppMAINTDESKTOP
    echo "Exec=$SCRIPTPATH/MyAppMaintenanceTool --updater" >> $MyAppMAINTDESKTOP
    echo "Icon=$ICONDESTINATION">> $MyAppMAINTDESKTOP
    echo "Terminal=false" >> $MyAppMAINTDESKTOP
    echo "Type=Application" >> $MyAppMAINTDESKTOP
    echo "Categories=Utility" >> $MyAppMAINTDESKTOP
    
    #Associate the icon with the executable
    gio set $SCRIPTPATH/MyApp metadata::custom-icon file://$ICONDESTINATION
    
    #Add MyApp application to favourites
    FAVORITES=$(gsettings get org.gnome.shell favorite-apps)
    NEWFAVOURITES=${FAVORITES::-1}", 'MyApp.desktop']"
    dconf write /org/gnome/shell/favorite-apps "$NEWFAVOURITES"
    
    #------End of the installation script
    

    Once you have create this script test and debug. Copy it to the install directory manually and then invoke it from the command line with one parameter being you home directory. This might looks something like:
    /home/me/MyApp>./linuxInstall.bash /home/me

    Step 1b: Creating the deinstallation script

    #------Start of the de-installation script
    #!/bin/bash
    
    #Get the location  of the script = location of executables and icons
    SCRIPT=$(readlink -f "$0")
    SCRIPTPATH=$(dirname "$SCRIPT")
    
    #Work out the destination file locations
    MYAPPICON=$1"/.local/share/icons/hicolor/48x48/apps/MyApp.png"
    MYAPPDESKTOP=$1"/.local/share/applications/MyApp.desktop"
    MYAPPMAINTDESKTOP=$1"/.local/share/applications/MyAppMaintenance.desktop"
    
    #Remove MyApp application from favourites
    FAVORITES=$(gsettings get org.gnome.shell favorite-apps)
    NEWFAVOURITES=${FAVORITES/", 'MyApp.desktop']"}"]"
    dconf write /org/gnome/shell/favorite-apps "$NEWFAVOURITES"
    
    #Remove the files
    rm $MYAPPICON
    rm $MYAPPDESKTOP
    rm $MYAPPMAINTDESKTOP
    
    #------End of the de-installation script
    

    As for the installation script make sure you debug the deinstallation script and get it working correctly.

    NEXT STEP: I have not checked this deinstallation script in detail and in particular worry that removing the MyApp from the end of the favourites list will fail if additional favourites are added when MyApp is removed.

    Step 2. Including the scripts into the installation bundle
    I have a separate script that creates the .7z file in the data folder. At a high level it:
    a. Creates a tmp directory off ~/pkg
    B. Copies the MyApp executable, qt .so's the installation and de-installation scripts above and the icon.png into the tmp directory
    c. Uses the archive tool to create the .7z file
    d. Copies the .7z file to the data folder
    e. Removes the tmp directory
    f. Creates the installer
    g. Creates the download archive

    If you don't already have something similar, I'd suggest you create a script to do this - my experience is it takes quite a few iterations to get this right and the script really helps

    Once you've included the .bash scripts into the .7z file, when you run the installer you should find both the installation and deinstallation scripts in the install directory and invoking them manually from the command line should complete the gnome installation and de-installation as expected.

    Step 3. Modifying the installations and De-installation process
    In this final step we get the QT IFW to invoke the installation and deinstallation scripts automatically.

    Step 3a. Modifying the installation process
    In the meta directory in the package.xml file you need the following line:
    <Script>controller.qs</Script>

    Then in the meta directory create a file called controller.qs with something like the following content:

    //------Start of the controller.qs script
    
    Component.prototype.installationFinishedPageIsShown = function()
    {
    	try {
    		if (installer.isInstaller() && installer.status == QInstaller.Success) {
    			var message = "Installation got systemInfo.kernelType == " + systemInfo.kernelType;
    			console.log(message);
    
    			if (systemInfo.kernelType === "winnt") {
    				//Windows
    				console.log("Installing MyApp on Windows");
    
    			} else if (systemInfo.kernelType === "darwin") {
    				//macOS
    				console.log("Installing MyApp on MacOS");
    
    			} else if (systemInfo.kernelType === "linux"){
    
    				console.log("Installing MyApp on Linux");
    
    				//Use a bash to do the linux desktop specific setup
    				var args = ["@HomeDir@"];
    		    		installer.executeDetached("@TargetDir@/linuxInstall.bash", args);
    
    			}
    			else {
    				cancelInstaller("MyApp installers are available for Windows, MacOS and Linux only.");
    				return;
    			}
    		}
    	} catch(e) {
    		console.log(e);
    	}
    }
    
    function Component()
    {
    	installer.installationFinished.connect(this, Component.prototype.installationFinishedPageIsShown);
    }
    
    //------End of the controller.qs script
    

    Step 3b. Modifying the de-installation process
    In the config directory in the config.xml file you need the following line:
    <ControlScript>deinstallscript.qs</ControlScript>
    Then in the config directory create a file called deinstallscript.qs with something like the following content:

    //------Start of the deinstallscript.qs script
    
    Controller.prototype.uninstallationStartedFunction = function() {
    	try {
    		var message = "Uninstallation got systemInfo.kernelType == " + systemInfo.kernelType;
    		console.log(message);
    
    		if (systemInfo.kernelType === "winnt") {
    			//Windows
    			console.log("Uninstalling MyApp on Windows"); 
    
    		} else if (systemInfo.kernelType === "darwin") {
    			//macOS
    			console.log("Uninstalling MyApp on MacOS");
    
    
    		} else if (systemInfo.kernelType === "linux"){
    
    			console.log("Uninstalling MyApp on Linux");
    
    			//Use a bash to do the linux desktop specific de-installation
    			var args = ["@HomeDir@"];
    		    	installer.executeDetached("@TargetDir@/linuxUninstall.bash", args);
    
    		}
    	} catch(e) {
    		console.log(e);
    	}
    }
    
    function Controller() {
    	installer.uninstallationStarted.connect(this, Controller.prototype.uninstallationStartedFunction);
    }
    
    //------End of the deinstallscript.qs script
    

    I know the .qs scripts to install and de-install look similar, but note the use of 'Component' in controller.qs, but the use of 'Controller' in deinstallscript.qs.

    Some final thoughts:

    • The gnome script assume the user has installed MyApp for the current user only. I believe this is an appropriate default, but it might be nice if there was a check-box that allowed the user to specify if the application is for all users and acquired the admin right required. The paths where things are placed will need to be updated.
    • I spent some time looking for how to detect gnome vs KDE, but all methods seemed error prone. My current through is just to check if gio is present and if so do a gnome install, but haven't gotten around to adding it yet.
    • You can use ldd to check which qt .so's you application depends on. It might be nice to do this as part of the packing script.