Gambas application installer maker

So you have written that new, must have program. Let us see it here.
Post Reply
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Gambas application installer maker

Post by BruceSteers »

I have here a completely working application installer script maker.
Well it does not install the application it installs the gambas components required and sets up the gambas application mime type if needed so the app can just be double clicked and stuff.

It's something for the developer not the end user, it makes an installation script to include with your app for the end user.

What it does...
First it asks for your gambas project folder.
It then reads the .project settings file and gets the components your app needs.

then it asks for an output folder.
Then it creates a script called "Install_gambas3_components.sh" (see example below)
It also copies the application-x-gambas3.png icon to the install script folder.

What the script does...
handles apt , yum or dnf packagers
Offers to install the complete package "gambas3" or just your applications requirements.
Then it lists the /usr/lib/gambas3 folder for installed components and sees if any are missing and installs if so.
Checks for gbr3 and installs the runtime if needed.
Then it checks the application-x-gambas3 filetype is configured and sets that up if not.


I just tested it on a newly installed Mint and Debian and it worked (after a couple of bug fixes)
not bugs in my app , bugs like an app can use gb.form.stock component but the .project file might not list it.
I've catered for gb.qt5 gb.form.stock and gb.jit that a project file might not list and the fact the project WILL list gb.eval if you use a TextEditor but gb.eval isn't on the repos it just auto installs.

I installed NOTHING before-hand, freshly installed linux systems no gambas items or system tools installed. xdg is already installed on mint and deb.
And it works

ToDo,
Incorporate the App Installer that offers to "Copy" the gambas app somewhere and sets up a menu/desktop entry for it...

PS. this is ripped from my GambasTweak app that now also makes an installer script like this.


Example output script, (I used the install maker on itself to produce this)

Code: Select all

#!/usr/bin/env bash

# Gambas component Installer script for Gambas basic application 'GambasAppInstallMaker.gambas'

# Must be run from terminal, will give option to install full Gambas3 or minimum components

# Function to check for installed package installer
GetPKGR() {
echo "Checking for installed packager apt, yum or dnf..."
PKGR=$(which apt-get)
if [ "$PKGR" = "" ]; then
 PKGR=$(which yum)
 if [ "$PKGR" = "" ]; then
  PKGR=$(which dnf)
  if [ "$PKGR" = "" ]; then
  echo -n "Sorry cannot find your package installer\nPress return to exit."
  read
  exit
  fi
 fi
fi

echo "found packager '$PKGR', for install okay."
}

# Function to ask user what type of install they want and start installing...
SelectInstall() {
echo "Install $AppName's minimum required gambas components or the complete Gambas3 package?"
echo -ne "Press return for minimum components (default) or type 'f' for full Gambas3\nor Ctrl-C to cancel: "
read REPLY
if [ "${REPLY,,}" = "f" ]; then
 echo "Installing the complete Gambas3 developement package..."
 sudo "$PKGR" install gambas3
 echo "Gambas3 full install complete\nEnsuring application components are present.."
 sleep 0.5
 NeededComponents
else
NeededComponents
fi

echo "Gambas component install finished."
}

# function to check for missing required gambas components and make a list $DEPLIST
NeededComponents() {

if [ ! -e "/usr/lib/gambas3" ]; then
DEPLIST="$(echo "$DEPS"|tr '.' '-')"
DEPLIST="gambas3-$(echo "$DEPLIST"|sed 's/ / gambas3-/g')"
else
INSTALLED=$(ls -Q /usr/lib/gambas3/*.component)
TIFS=$IFS
IFS='\"'

read -d '\"' -a CO_ARRAY <<< $INSTALLED
IFS=' '
read -a DEP_ARRAY <<< $DEPS
CNT=0
DEPLIST=""

while [ $CNT -lt ${#DEP_ARRAY[@]} ]; do
IsInstalled "${DEP_ARRAY[$CNT]}"

if [ $IsInstalled -eq 0 ]; then
NDED="gambas3-"$(echo "${DEP_ARRAY[$CNT]}"|tr '.' '-')
 if [ "$DEPLIST" = "" ]; then
 DEPLIST="$NDED"
 else
 DEPLIST="$DEPLIST $NDED"
 fi
fi
((CNT++))
done
fi
AddRuntime

if [ "$DEPLIST" = "" ]; then
echo "No additional gambas3 components need to be installed.."
else
echo -e "Installing the following items..\n'$DEPLIST'"
echo -ne "Press return to continue or Ctrl-C to exit: "
read

 sudo "$PKGR" install -y $DEPLIST

fi
}

# Function. check for gbr3 in the path and add gambas3-runtime if not found
AddRuntime() {
 RT_Yes=$(which gbr3)
 if [ -z "$RT_Yes" ]; then DEPLIST="gambas3-runtime $DEPLIST"; fi
}

# Function Check if a component exists in the list
IsInstalled() {
if [ "${#CO_ARRAY[@]}" = "0" ]; then
IsInstalled=0
return
fi
ICNT=0
while [ $ICNT -lt ${#CO_ARRAY[@]} ]; do
CNAME="${CO_ARRAY[$ICNT]##*/}"
CNAME="${CNAME%.*}"
if [ "$CNAME" = "$1" ]; then
IsInstalled=1
return
fi
((ICNT++))
done
IsInstalled=0
}

GambasFiletype() {
# Check xdg components are installed..
if [ -e "/usr/share/mime/packages/application-x-gambas3.xml" ]; then
echo "Skipping Gambas3 application filetype install, already configured."
return
fi
XDGYes=$(which xdg-mime)
if [ ! -z "$XDGYes" ]; then
XDGYes=$(which xdg-icon-resource)
fi
if [ -z "$XDGYes" ]; then
echo -ne "xdg not installed, cannot setup gambas filetype."
return
fi

# Check application-x-gambas3.png icon exists in current folder and install it.
echo "Installing default filetype icon.."
if [ -e "./.application-x-gambas3.png" ]; then
 sudo xdg-icon-resource install --context mimetypes --size 48 ./.application-x-gambas3.png x-application-x-gambas3
else
 echo -ne "error, application-x-gambas3.png icon not found, cannot configure filetype."
 return
fi

echo -e "done.\n\nNow installing mime filetype and updating database..\nPlease wait a moment..."

# write temp default fyletype xml file from Gambas3 distro
echo -e '<?xml version="1.0" encoding="UTF-8"?>\n<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
	<mime-type type="application/x-gambas3">\n		<sub-class-of type="application/x-executable"/>
		<comment>Gambas 3 executable</comment>\n		<comment xml:lang="fr">Exécutable Gambas 3</comment>
		<magic priority="50">\n			<match type="string" value="#! /usr/bin/env gbr3" offset="0"/>\n		</magic>
		<glob pattern="*.gambas" />\n	</mime-type>\n</mime-info>' >/tmp/application-x-gambas3.xml

# install filetype and remove temp file
sudo xdg-mime install /tmp/application-x-gambas3.xml
rm /tmp/application-x-gambas3.xml
echo "Now updating mime database..."
sudo update-mime-database /usr/share/mime
echo -ne "done.\napplcation-x-gambas3 filetype install completed."
}


AppName="GambasAppInstallMaker.gambas"
DEPS="gb.image gb.gui gb.settings gb.form.stock gb.jit"


GetPKGR
SelectInstall
GambasFiletype

echo "Install script completed, press return to finish."
read
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas application installer maker

Post by BruceSteers »

Just as note..

It's not quite perfect this app sadly.
There are various components that can be called non-explicitly like gb.form.pcre for example all you need to do is use a "LIKE" or a "MATCH" arg in a string function and the gb.pcre component is auto loaded.. Same with adding an icon to a button will load the gb.form.stock component but the .project settings do not show it. Also if using the gb.gui.qt component the app does not list a gb.qt4 or gb.qt5 because it does not know if the os it's running on has it yet.
So i also need to add a routine that checks if QT is being used should it install qt4 or qt5 (currently just goes for qt5)

My options to ensure an app will work after install are...
account for the hidden components that may not be installed like gb.form.stock and add them anyway.
The installer script the app makes only tries to install non installed stuff so it wouldn't matter and most the components are small downloads anyway.

I've thought about making a drag and drop gambas application configurator type of thing.
Something you could drag a gambas application onto and it would try to run it, and if it fails it would read the error message about the missing component and auto install and re-run till it runs.
(as when an app fails to run from missing a component it fails at that point and does not report any other missing libs till next run)

I'll put some more work into this as like i said it's part of another app i'm making and having a gambas app work for others off the bat is a high priority for me.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Gambas application installer maker

Post by BruceSteers »

So now i also have made this...
Gambas3-Application-Setup

What is it?
It's a bash script that creates a drop-box icon you can drop a gambas app on and it will install all the apps gambas-components on a system without anything gambas on it.
(so it couldn't be a gambas app really)

How it works....
It uses zenity for questions/some messages.
You run the script and it asks if you want to make the drop box on the desktop or in the script dir and makes a launcher icon linked to the script. this enables drag-n-drop. it then checks for the gambas3-runtime and installs it and checks if your system has gtk gtk3 qt4 and qt5 and installs those GUI components. it Also checks the application-gambas3 mime FyleType is set up.

Once that's done you have a new icon you can either double click and point to a gambas application or drop a gambas application on the icon.
I then tries to run the app.
If the running of the app fails returning an error it checks the error message for details about the missing component and installs it.
Then tries again.
Until the app runs okay or it get's an error i have not catered for because i do not know about yet.

I just tried and tested it on a gambas free Fresh Mint (lol FreshMint :) ) and all worked okay on quite a few gambas apps i tried it on :)

Not sure how to use it yet :lol:

Todo:
Make it cater for a bytecode mismatch error as this is another reason an app can fail.
Ie. If the apps been compiled on gambas3.15 but your system has 3.12, I could probably add to the script to download the gambas-dev compilers and recompile the app for the user if the app has the source code present.

incorporate it all into one installer program that will copy the app somewhere / create a menu / icon and make sure it runs with all it's components.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply