Freedombone
Developers Guide
Introduction
Freedombone consists almost entirely of bash scripts, with some html, css and php for the web interface. There are many bash scripts, but they're not very complicated. If you're familiar with the GNU/Linux commandline and can hack a bash script then you can probably add a new app or fix a bug in the system. There are no trendy development frameworks to learn or to get in your way. You might also want to consult the Code of Conduct for guidance upon the overall esprit de corps, and there is a Matrix room at #fbone:matrix.freedombone.net and an XMPP multi-user chat at support@chat.freedombone.net
Source code
If you just want to take a look at the source code then it can be found here or is obtainable on dat://c979feff64b9f69121b9e5659837de6792493b8aa362ab7401dff757cf54c870/
Creating images
Images are an easy way of distributing the software in a manner which avoids problems. These instructions assume that you're running either a Debian or Arch based distro.
sudo apt-get install git build-essential dialog git clone https://code.freedombone.net/bashrc/freedombone cd freedombone git checkout stretch sudo make install
Then install packages needed for building images:
freedombone-image --setup debian
or on an Arch/Parabola system:
freedombone-image --setup parabola
A typical use case to build an 8GB image for a Beaglebone Black is as follows. You can change the size depending upon the capacity of your microSD card.
freedombone-image -t beagleboneblack -s 8G
To build a 64bit Qemu image:
freedombone-image -t qemu-x86_64 -s 8G
Other supported boards are beaglebonegreen, beaglex15, cubieboard2, cubietruck, pcduino3, a20-olinuxino-lime, a20-olinuxino-lime2, a20-olinuxino-micro, banana-pro, i386, amd64, apu and qemu-i386.
If the image build fails with an error such as "Error reading from server. Remote end closed connection" then you can specify a debian package mirror repository manually with:
freedombone-image -t beagleboneblack -s 8G -m http://ftp.de.debian.org/debian
Sometimes the build will fail just because a repo is temporarily unavailable. In that case just trying again may work.
Adding extra apps
Suppose you have some internet application which you want to add to the system. To do this you need to create an app script which tells the system how to install/remove and also backup/restore. The script should be designed to work with the current stable version of Debian.
There's a command which you can use to generate scripts for new apps. Some examples are as follows:
To create a script for a generic PHP plus MySql/MariaDB web app with a couple of extra packages:
freedombone-template --app [name] -e [email] -r [repo url] \ --packages "cowsay libssl-dev" \ -c [commit] --php yes -d mariadb > \ src/freedombone-app-myappname
For a Nodejs app with MySql/MariaDB database:
freedombone-template --app [name] -e [email] -r [repo url] \ -c [commit] --node yes -d mariadb \ --dir /etc/myappname --daemon yes > \ src/freedombone-app-myappname
For a Python app with Postgresql database:
freedombone-template --app [name] -e [email] -r [repo url] \ -c [commit] -d postgresql \ --dir /etc/myappname --daemon yes > \ src/freedombone-app-myappname
For a Python app without any database, communicating between the daemon and the web server on port 1234:
freedombone-template --app [name] -e [email] -r [repo url] \ -c [commit] --dir /etc/myappname \ --daemon yes --portinternal 1234 > \ src/freedombone-app-myappname
For an app without any database which communicates directly on a particular port through the firewall:
freedombone-template --app [name] -e [email] -r [repo url] \ -c [commit] --dir /etc/myappname \ --daemon yes --port 5000 > \ src/freedombone-app-myappname
A generic PHP plus MySql/MariaDB web app which is only available on an onion address:
freedombone-template --app [name] -e [email] -r [repo url] \ -c [commit] --php yes -d mariadb \ --onion yes > \ src/freedombone-app-myappname
For more details see the manpage:
man freedombone-template
The template command won't give you a fully working app, but it will give you a big head start and avoid a lot of potential mistakes. It's highly likely that you'll still need to add extra configuration for your particular app, especially within the install_app function.
When your new script is ready for testing you can install it with:
make install
Then run the administrator control panel and you should see the new app within Add/Remove apps.
Submit your working app to https://code.freedombone.net/bashrc/freedombone/issues, create a pull request or if you don't have an account there you can send patches via email to bob@freedombone.net.
Architecture
Apps
Apps are scripts beginning with src/freedombone-app-. New scripts can be created with the template command described above. Each script contains a number of function interfaces which enable the app to be installed, removed, backed up and for logging to be turned on or off. The interfaces are:
install_appname install_interactive_appname configure_interactive_appname remove_appname upgrade_appname backup_local_appname restore_local_appname backup_remote_appname restore_remote_appname logging_on_appname logging_off_appname add_user_appname remove_user_appname
install_interactive and configure_interactive are only used by the dialog menu interface accessible via ssh.
backup_remote and restore_remote are not currently implemented and are expected to be used by a future distributed network backup system.
Web interface
The web interface consists of a set of html files within webadmin/EN. These use forms to reference some php files within webadmin and those generate files which are then picked up by a systemd daemon running in the background (webadmin.service) which is implemented by src/freedombone-installer.
Typically the daemon detects the presence of a file, extracts the variables from it, maybe does some additional validation and then does whatever it needs to do with those.
The separate daemon also avoids having php code making any direct changes to the underlying system, which could create security risks. The files created by the php scripts are very small and can typically be fully validated.
The user interface is regenerated by the function install_web_admin within src/freedombone-utils-webadmin.
When installed, the web interface is in /var/www/freedombone.local/htdocs/admin. The directory above that is where a json API exists for use with the FreedomBox Android app.
Although it's tempting and easy, avoid adding javascript into the html files. The policy is to keep the web interface free from javascript, so that if you're using noscript or have javascript turned off then the interface can still be used without any loss of functionality.
It is assumed that only the administrator will be accessing the web interface, so dealing with collisions between multiple users making contradicting changes to the same things at the same time isn't necessary.
The web interface operates in a strictly sequential/synchronous mode. So if you try to install multiple apps it puts them into a queue and does the installs one after another. The same applies for app removals.
How translations happen
Translations are stored within webadmin/translations. When you select a language html files are copied from webadmin/EN and then the English strings are searched and replaced. Strings to be translated are indicated within the html files with the parameter translate="yes".
Doing it this way avoids having duplicated versions of the many html files for different languages. See the change_language function within src/freedombone-installer for details of how this process works.
Doing translations
These can be added or edited within the web UI. Navigate to http://freedombone/admin or its onion address, select settings then language. Select the language that you want to translate to then the translate button. In the right hand column you can then manually edit the translated strings. When you are done select the update button.
The format of the translation files is very simple. It's:
English string|Translated string
If you prefer to edit the raw files within your own editor of choice they can be found within the webadmin/translations directory of the repo.
Icons
If you want to change the icons of the web user interface they can be found within the webadmin/images directory of the repo.
Icons used for the mesh desktop can be found within img and img/avatars directories and their filenames begin with icon_.
Customising mesh images
If you want to make your own specially branded version of the mesh images, such as for a particular event, then to change the default desktop backgrounds edit the images within img/backgrounds and to change the available avatars and desktop icons edit the images within img/avatars. Re-create disk images using the instructions shown previously.
If you need particular dconf commands to alter desktop appearance or behavior then see the function mesh_client_startup_applications within src/freedombone-image-customise.