Creating an Installer for PSLab Desktop App
PSLab device is made useful with applications running on two platforms. One is Android and the other one is a desktop application developed using Python frameworks. Desktop application uses half a dozen of dependent libraries and they are required to be installed prior to installing the application itself.
For someone with zero or less knowledge on how to install packages in a Linux environment, this task will be quite difficult. To ease up the process of installing the desktop application in a computer, we can use a script to run specific commands which will install the dependencies and the application.
Dependencies required by PSLab Desktop app
- PyQt 4.7
- Python 2.6, 2.7 or 3.x
- NumPy, Scipy
- pyqt4-dev-tools
- Pyqtgraph
- pyopengl and qt-opengl
- iPython-qtconsole
These dependencies can be made installed using a bash script running with root permission. A bash script will have the file extension “.sh” and a header line;
#!/bin/bash
A bash script needs to be made executable by the user himself. To do this, user needs to type a one line command in the terminal as follows and enter his password;
sudo chmod +x <Name_of_the_script>.sh
The keyword “sudo” interprets as “Super User DO” and the line follows will be executed with root permission. In other words with administrative privileges to modify system settings such as copying content to system folders.
The keyword “chmod” stands for “Change Mode” which will alter the mode of a file. In current context, the file is made executable by adding the executable property to the bash script using “+x” syntax.
Once the script is made executable, it can be executed using;
sudo ./<Name_of_the_script>.sh
An installer can be made attractive by using different colors rather than the plain old text outputs. For this purpose we can use color syntax in bash script. They are represented using ANSI escape codes and following is a list of commonly used colors;
Black 0;30 Dark Gray 1;30
Red 0;31 Light Red 1;31
Green 0;32 Light Green 1;32
Brown/Orange 0;33 Yellow 1;33
Blue 0;34 Light Blue 1;34
Purple 0;35 Light Purple 1;35
Cyan 0;36 Light Cyan 1;36
Light Gray 0;37 White 1;37
As in any programming language, rather than using the same line in many places, we can define variables in a bash script. The syntax will be the variable name followed by an equal sign with the value. There cannot be spaces around the equal sign or it will generate an error.
GREEN='\033[0;32m'
These variables can be accessed using a special syntax as follows;
${GREEN}
Finally we can output a message to the console using the “echo” command
echo -e "${GREEN}Welcome to PSLab Desktop app installer${NOCOLOR}"
Note that the keyword “-e” is used to enable interpretation of the following backslash escapes.
In order to install the packages and libraries, we use two package management tools. One is “apt” which stands for “Advanced Packaging Tool” and the second is “pip” which is used to download python related packages from “Python Package Index”. The following two lines illustrates how the two commands can be accessed.
apt-get install python-pip python-dev build-essential -y
pip install pyqtgraph
The keyword “-y” avoids the confirmation prompt in console to allow installation by pressing “Y” key every time it installs a package from “apt”.
Resources:
- Creating Bash Scripts: https://bash.cyberciti.biz/guide/Hello,_World!_Tutorial
- CHMOD: https://en.wikipedia.org/wiki/Chmod
- Colors in echo output: https://en.wikipedia.org/wiki/ANSI_escape_code
- apt vs pip: askubuntu.com/questions/431780/apt-get-install-vs-pip-install
You must be logged in to post a comment.