Pack­ages Snaps.................................

Mats Tage Ax­els­son shows you how the meth­ods for dis­tribut­ing ap­pli­ca­tions for Linux are chang­ing − and why we should care.

Linux Format - - CONTENTS -

Let’s get go­ing with Snaps – Mats Tage Ax­els­son be­lieves they’re the fu­ture!

Linux users of­ten ar­gue with users of other op­er­at­ing sys­tems about how bril­liant Linux is. Yet one thing that’s al­ways been hard to de­fend is how tricky it is to down­load your favourite ap­pli­ca­tion di­rectly from the de­vel­oper’s web­site and run it. Usu­ally, it’s a de­lib­er­ate choice to have a cen­tral repos­i­tory with well-tested and se­cure soft­ware. How­ever, for desk­top ap­pli­ca­tions, users pre­fer to find the de­vel­oper’s web­site and down­load from there.

Un­til lately, you could only choose to use a dis­tri­bu­tion or com­pile your own. Most reg­u­lar users won’t com­pile their soft­ware pack­ages. For the de­vel­op­ers, main­tain­ing a pack­age for all the dis­tri­bu­tions avail­able is a night­mare. They need to adapt to the li­braries in each dis­tri­bu­tion, in­clud­ing which ver­sion they need to sup­port. If they’re us­ing a new fea­ture in one of their li­braries, they may not be able to con­vince dis­tri­bu­tion main­tain­ers to add it. This sit­u­a­tion es­pe­cially ap­plies to ap­pli­ca­tions with a small user base.

Ubuntu has in­tro­duced snaps as one of many so­lu­tions to ob­tain ap­pli­ca­tion pack­ages that aren’t dis­tro spe­cific and are also avail­able as down­loads. We’ll cover snaps and ap­pim­age in this tu­to­rial, and men­tion Flat­pack and a few oth­ers.


An Ap­pim­age con­tains the ex­e­cutable you want, but that’s not the first ex­e­cutable that runs when you start an Ap­pim­age. The first bi­nary to run is Ap­pRun, which sets up the sys­tem for the ap­pli­ca­tion.

The ap­pim­agekit cre­ates Ap­pRun dur­ing the process of mak­ing the Ap­pIm­age. The re­sult­ing Ap­pRun ex­e­cutable is very sim­i­lar in dif­fer­ent ap­pim­ages. Af­ter all, it only sets the sys­tem up with vari­ables and li­braries. You’re also free to cre­ate the Ap­pRun your­self, but you’d prob­a­bly only do this af­ter you’ve used the ap­pim­agekit a few times.

A good idea for your first few projects is to write your recipe when you cre­ate an ap­pim­age. The recipes are YAML files, one for each Ap­pIm­age. The file con­tains all the in­for­ma­tion to cre­ate the Ap­pIm­age, in­clud­ing a script to down­load and con­fig­ure the pack­age.

A Snap has a sim­i­lar struc­ture, but with a stricter spec­i­fi­ca­tion. The pack­age con­tains a lo­cal root /, /meta and /bin/. The lo­cal root con­tains the source and wrap­per files, / bin con­tains bi­na­ries and /meta con­tains con­fig­u­ra­tion files.

The dif­fer­ence be­tween snaps and Ap­pIm­ages is that snap needs a dae­mon to op­er­ate, while an Ap­pim­age doesn’t. When you down­load a snap, you have to install it be­fore you can use it. That is one task that the snap dae­mon per­forms.

With an Ap­pIm­age, you must have Ap­pRun in the root and /usr di­rec­tory of the im­age cre­ated. It’s not nec­es­sary to in­te­grate your ap­pli­ca­tion into your sys­tem. If you do want it to show up in your favourite desk­top en­vi­ron­ment, then you can choose to use the op­tional ap­pim­age dae­mon. In prac­tice, you must fol­low the stan­dards laid down at www.freedesk­ for your ap­pli­ca­tions to run cor­rectly.

The big dif­fer­ence be­tween the two pack­ag­ing for­mats is that Ap­pIm­age uses an ISO 9660 file, and a Snap uses a squashfs filesys­tem. Fur­ther­more, Snaps and Ap­pIm­age come from dif­fer­ent lines of thought. The most im­por­tant pri­or­ity of the Ap­pIm­age project is to make it easy to dis­trib­ute and use soft­ware di­rectly from the de­vel­oper. In other words, the user and de­vel­oper shouldn’t de­pend on the dis­tri­bu­tion main­tain­ers to move over to newer ver­sions.

There’s a greater em­pha­sis on cor­rect con­fine­ment in the snap de­sign. The sys­tem also re­quires a cen­tral repos­i­tory, called stores. And so when you want to use Snaps, you first need to install the Snaps sys­tem for your dis­tro. The snap sys­tem is a tra­di­tional pack­age for many dis­tri­bu­tions, so in Ubuntu you use apt : $ sudo apt install snap

In Fe­dora you use dnf . $ sudo dnf install snap

Fe­dora started the Flat­pack project, which is com­pet­ing to solve the same prob­lem. So you need to go through a length­ier pro­ce­dure be­fore you can install snap. In other dis­tri­bu­tions, you need to check if they’ve added the snap pack­ages. It’s al­ready na­tive in Arch, De­bian, Fe­dora and the main Ubuntu dis­tri­bu­tions. The most com­mon prob­lem is miss­ing sup­port for the con­fine­ment, and you need to run your snaps in de­vel­op­ment mode.

Once snap is in­stalled the process is very sim­i­lar to us­ing a pack­age man­ager. Be­low is a typ­i­cal flow for get­ting a snap.

We start by find­ing the snap pack­age. $ snap find nextcloud Name Ver­sion De­vel­oper Notes Sum­mary Name Ver­sion De­vel­oper Notes Sum­mary nextcloud-port8080 1.01 arc­tic­sly­fox - Nextcloud Server nextcloud-nex­tant 11.0.0snap3 rmes­can­don - Nextcloud Server + search sup­port nextcloud 11.0.3snap7 nextcloud - Nextcloud Server cash­box-nextcloud 11.0.2snap2 cash­box - Nextcloud Server for­ spreedme 0.29.5snap1 nextcloud - Spreed.ME au­dio/ video calls and con­fer­ences fea­ture for the Nextcloud Snap qown­notes 17.07.6 pbek - Plain-text file notepad with mark­down sup­port and ownCloud in­te­gra­tion solr 0.1 rmes­can­don - Starts up solr as fork­ing dae­mon mdns-host­name 0.0.1 we­like - mDNS minidae­mon to pub­lished host­name.lo­cal As you can see, the com­mand shows all ver­sions avail­able along with re­lated snaps, too.

Once you’ve ver­i­fied that it’s avail­able, install it. $ sudo snap install nextcloud Now, run the com­mand. $ nextcloud Nextcloud is now run­ning and you can con­firm this us­ing sys­tem­ctl: $ sys­tem­ctl sta­tus snap.nextcloud.* To ob­tain more in­for­ma­tion use the info com­mand:

$ snap info nextcloud

A Snap will be ac­tive once it’s in­stalled. For reg­u­lar ap­pli­ca­tions, this isn’t a ma­jor is­sue. How­ever, if we install

nextcloud, as in the above ex­am­ple, then the ser­vice will con­tinue run­ning. When you no longer need the server to run you have two op­tions: dis­able it or re­move it. A ser­vice like this can, of course, be stopped with the sys­tem­ctl com­mands and leave it at that. Here, we wanted to see if it’s bet­ter to use a snap in­stead − and in­deed it is! With a snap, you can list all your snaps and choose whether you want them ac­tive, dis­abled or thrown away. If you use the dis­able func­tion, then the pack­age will still be on the disc with all set­tings in­tact un­til you start it again or re­move it.

The best thing about this ap­proach is that snap will check all func­tions and stop the ser­vice with­out any ad­di­tion­als com­mands. From past ex­pe­ri­ence, we ex­pected to have to stop the ser­vice first and then dis­able it. If you’ve de­cided that

this snap isn’t your thing, you can erase it. All set­tings go with it so make sure you know that you’ve not made changes that you want to bring over to ei­ther a new install or per­haps an­other snap: $ snap re­move nextcloud

The above ac­tions are the most com­mon when you use snaps. If you’ve fol­lowed this tu­to­rial thus­far, you have now done ev­ery­thing needed to ver­ify the nextcloud pack­age. Testers will find this use­ful be­cause all files and con­fig­u­ra­tions are in the snap tree. When you re­move a snap, no files will be left be­hind.

The next sec­tion is our rec­om­mended ap­proach for us­ing Ap­pIm­age. Hang on to your hats!

Down­load the file

Set ex­e­cute per­mis­sions for the file. We have cho­sen to al­low all users. It works even if you add only your­self. $ chmod a+x Down­loads/TheApp.Ap­pIm­age

Next, run the ap­pli­ca­tion. $ Down­loads/TheApp.Ap­pIm­age

That’s it! As you can see, the sys­tem is cre­ated to make us­ing soft­ware sim­ple. The big chal­lenge is for the pro­gram­mers to make the pack­age work in most dis­tri­bu­tions with­out cre­at­ing a bloated down­load. To make things even sim­pler, use the ap­pim­age dae­mon. The dae­mon scans pre­de­fined di­rec­to­ries for Ap­pIm­ages, sets the ex­e­cutable bit and then adds them to your desk­top.

Snap re­quires a store. The de­fault store is the Ubuntu one, but the idea is that any­one can run a store. If you’re in­ter­ested, check out­store. This is a snap store ex­am­ple on Github that will en­able you to

gain some ex­pe­ri­ence in run­ning a store. A quick search on the in­ter­net doesn’t re­veal any stores − yet.

Ap­pIm­age, on the other hand, is de­signed to en­able any­one to cre­ate and dis­trib­ute soft­ware with­out any cen­tral repos­i­tory at all. With that said, there are al­ready over 100 ap­pli­ca­tions on bin­tray for you to down­load.

Liv­ing in Flat­pak land

When us­ing Flat­pak, the in­staller checks de­pen­den­cies and down­loads run­times. Run­times are the li­braries and other bi­na­ries that are nec­es­sary to run the pack­ages. The Flat­pak struc­ture is sim­i­lar to that of Ap­pIm­age, ex­cept that it has a meta­data file for con­fig­u­ra­tion in­for­ma­tion, /files di­rec­tory for source code and ap­pli­ca­tion in­for­ma­tion. The bi­na­ries go in /files/bin and any data that the ap­pli­ca­tion needs to share with the en­vi­ron­ment goes in the /ex­port di­rec­tory.

Flat­pak is more like a pack­age man­ager com­pared to Ap­pIm­age, which should make the Flat­pak pack­ages smaller. With so few ap­pli­ca­tions though, it’s hard to judge right now.

Cre­ation is a snap

We’ll start look­ing how to cre­ate pack­ages, ei­ther as a de­vel­oper or just be­cause you want to try the ap­pli­ca­tion out. First up is snaps. The build tool for snaps is called snapcraft, so install that with your reg­u­lar pack­age man­age­ment wiz­ardry. $ sudo apt install snapcraft

The snapcraft tool will com­pile the pack­ages for you, so the build-es­sen­tial pack­age is re­quired. $ sudo apt install build-es­sen­tial

For the snapcraft tool to do any­thing use­ful, you need a con­fig­u­ra­tion file called snapcraft.yml. The con­tents of this file de­scribes the ap­pli­ca­tion you want to com­pile.

Run­ning the snapcraft tool is sim­ple: there are two dif­fer­ent pro­ce­dures. The sim­plest ap­proach is to just run the com­mand with­out switches in the di­rec­tory where you put your snapcraft.yml file. $ snapcraft

In this case, snapcraft will read the snapcraft.yml file and com­pile the de­fined pack­age. Af­ter this, you install the snap. $ snap install [yourApp.snap] –dan­ger­ous

When the pack­ages be­come big­ger, the pro­ce­dure has a few more op­tional steps. This is be­cause the sys­tem can add li­braries that are un­com­mon. If your ap­pli­ca­tion needs a new li­brary, you can add it as a part of your con­fig­u­ra­tion file. When your pack­age is this big, you have the op­tion to com­pile one part at a time. In fact, snapcraft will de­tect if you al­ready have the lat­est of any part and only re­com­pile the up­dated part when you want to up­grade. You have the op­tion to build a part at a time, use the build com­mand. $ snapcraft build [part]

With­out the part pa­ram­e­ter, snapcraft builds all the parts that need com­pil­ing. You can use this if you want to change only one part. $ snapcraft clean [part] The snapcraft.yml file con­trols it all. The top of the snapcraft.yml file con­tains the de­scrip­tive in­for­ma­tion such as the name, the ver­sion and the de­scrip­tion. The other sec­tions con­trol the be­hav­iour of snapcraft, which in turn con­fig­ures your snap.

The next sec­tion is con­fine­ment, be­cause in a pro­duc­tion snap this value needs to be strict. For se­cu­rity rea­sons, the strict value stops the snap from com­mu­ni­cat­ing with the rest of the sys­tem. While you’re de­vel­op­ing a snap, you need to set the value to de­v­mode or use the switch –dan­ger­ous to make it run out­side of con­fine­ment.

For the snap to work prop­erly in any en­vi­ron­ment you then need to de­fine what it’s per­mit­ted to in­ter­face with. For ex­am­ple, a web browser needs to ac­cess the net­work as a client. To do this, you need to add the net­work pa­ram­e­ter in the file. This pa­ram­e­ter is called a plug when the snap needs a re­source and a slot when the snap pro­vides one.

The other sec­tions are apps and parts. In the apps sec­tion, the name pa­ram­e­ter names the ex­e­cutable and points to the com­mand. Usu­ally, they’ll both be the same, but you may need to start it with bash, python or the like.

Mov­ing on to the parts sec­tion, you need to de­fine what you need to build your code with and where your code is. In

its sim­plest form, the parts di­rec­tive con­tains the name of the app, the plugin and the source.

A sim­ple ex­am­ple here: parts: hello: plugin: au­to­tools source: ./src/hello The plugin will vary, depend­ing on your source code. A ref­er­ence list avail­able at ref­er­ence/plug­ins.

Cre­at­ing an Ap­pIm­age

To make an Ap­pIm­age, it’s likely that you’ll use the build ser­vices avail­able on­line. One ex­am­ple is Travis CI.

Usu­ally, the de­vel­oper will cre­ate ei­ther the recipe file or the di­rec­tory struc­ture. If an ex­ist­ing pack­age doesn’t ex­ist as an Ap­pIm­age, you can cre­ate the di­rec­tory struc­ture your­self.

The di­rec­tory struc­ture stems from the ROX desk­top project. The struc­ture con­tains at least the files and di­rec­to­ries shown be­low. MyApp.Ap­pDir/ MyApp.Ap­pDir/Ap­pRun MyApp.Ap­pDir/myapp.desk­top MyApp.Ap­pDir/myapp.png MyApp.Ap­pDir/usr/bin/myapp MyApp.Ap­pDir/usr/lib/lib­

The key file is Ap­pRun. As men­tioned ear­lier in this ar­ti­cle, it’ll con­fig­ure your pack­age. Ap­pRun is a wrap­per script that sets all en­vi­ron­ment vari­ables at run­time and launches the ap­pli­ca­tion.

The myapp.desk­top file fol­lows the freedesk­top stan­dard. The ap­pim­age dae­mon will find and read this file to in­te­grate the ap­pli­ca­tion into your desk­top en­vi­ron­ment. Look in­side the file to learn the de­tails.

To show how this works, we’ll make an Ap­pIm­age us­ing the Cal­i­bre recipe.

The Cal­i­bre.yml file al­ready ex­ists on, and there’s also a script that reads the recipe file.

Down­load the script with wget. $ wget https://raw.githubuser­con­ Ap­pIm­ages/mas­ter/recipes/meta/Recipe

Set the ex­e­cutable bits. $ chmod a+x Recipe

Make a di­rec­tory for your Ap­pIm­age and cd into it. $ mkdir Cal­i­bre && cd Cal­i­bre

Fi­nally, run the recipe script. $ ../Recipe Cal­i­bre

You may no­tice that we’ve not in­cluded the yml ex­ten­sion, if you do, the script stops early. This script will look for the recipe file, first in your cur­rent di­rec­tory and then turn to and ex­e­cute the recipe as a script. Dur­ing the ex­e­cu­tion, the script will down­load the source code, bi­nary files, and de­pen­den­cies and cre­ate the Ap­pDir.

The script also cre­ates an out di­rec­tory where you’ll find your Ap­pIm­age. Cu­ri­ous read­ers will no doubt in­ves­ti­gate the Ap­pDir un­der Cal­i­bre.

To make an Ap­pIm­age for a de­vel­oper re­quires just a lit­tle bit more work first. If you’re in­ter­ested, read the install doc­u­ment and then ad­just the recipe file to the build sys­tem for the par­tic­u­lar ap­pli­ca­tion. Then run the same script for that ap­pli­ca­tion, and in­crease the num­ber of ap­pli­ca­tions de­liv­ered by Ap­pIm­age. Be­cause the par­tic­u­lar project will be pi­o­neer­ing, you’ll run into a few more is­sues to han­dle, such as hard-coded di­rec­to­ries in the source code.

The ze­roth law

Un­til now, we’ve not men­tioned zeroin­stall. This is an ear­lier project that solved the same prob­lem, but does not seem to have ex­pe­ri­enced the same take-up as snaps. We find this all rather puz­zling be­cause mak­ing your ap­pli­ca­tion ready for zeroin­stall is very sim­ple. You cre­ate a web page in the stan­dard XML for­mat that the mak­ers pre­scribe in their in­struc­tions and then you test. The project is also very ac­tive, and to top it all off there are three ver­sions that sup­port­ing the three big op­er­at­ing sys­tems. You can read more about zeroin­stall in the box ( be­lowleft).

Turn­ing back to snaps, you have se­cure con­fine­ment builtin if you reg­is­ter your ap­pli­ca­tion and set your sig­na­ture. Ap­pim­age doesn’t have this na­tively so for the se­cu­rity con­scious use fire­jail. The pack­age is sim­ple to use just add the ap­pim­age switch. $ fire­jail –ap­pim­age krita-3.1.2-x86_64.ap­pim­age

In­side the fire­jail, the ap­pli­ca­tion can still read your user data, so any files that you’ve put in your home di­rec­tory will be ac­ces­si­ble.

Some read­ers will be won­der­ing why we need snap and Ap­pIm­ages at all. For many peo­ple, the dis­tri­bu­tion sys­tem works fine, and there’s no prob­lem to solve. Yet while the dis­tri­bu­tions are use­ful for keep­ing a sta­ble sys­tem, it also re­quires more peo­ple be­tween de­vel­oper and end-user.

The prob­lems start when you want to try an ap­pli­ca­tion, and the de­vel­oper doesn’t sup­port your dis­tri­bu­tion. What will you do? Chang­ing dis­tri­bu­tion is a big job, and other ap­pli­ca­tions may not work in your new dis­tri­bu­tion. These so­lu­tions makes it eas­ier to test ap­pli­ca­tions and to get hold of un­com­mon soft­ware.

Don’t fight the change, em­brace it.

The snapcraft tour com­mand cre­ates di­rec­to­ries that en­able you to learn the ba­sics. Dur­ing the tour, you cre­ate reg­u­lar snaps as well as web-based soft­ware.

Lin­phone is in­stalled as a flat­pak. When the flat­pak in­stalls, it also in­stalls de­pen­den­cies to the flat­pak sys­tem with­out up­grad­ing the rest of the sys­tem.

Zeroin­stall has both a GUI helper and a com­mand line tool that en­able you to cre­ate your pub­lisher feed file. Pub­lish­ing to the web is a built-in fea­ture.

When you run the recipe script from http://bit. ly/2vYe2pG, all the re­quired files are down­loaded to the Ap­pDir that will be­come part of your Ap­pIm­age.

Newspapers in English

Newspapers from Australia

© PressReader. All rights reserved.