<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Posts on danyspin97's site</title><link>https://danyspin97.org/blog/</link><description>Recent content in Posts on danyspin97's site</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Wed, 23 Jun 2021 15:45:00 +0200</lastBuildDate><atom:link href="https://danyspin97.org/blog/index.xml" rel="self" type="application/rss+xml"/><item><title>Improving Linux Packaging: rinstall</title><link>https://danyspin97.org/blog/improving-linux-packaging-rinstall/</link><pubDate>Wed, 23 Jun 2021 15:45:00 +0200</pubDate><guid>https://danyspin97.org/blog/improving-linux-packaging-rinstall/</guid><description>&lt;p>Let&amp;rsquo;s face it. Packaging software on Linux is an underappreciated job. If they do their job
correctly, almost no one will notice them. But the moment they do a mistake, the users of their
distribution will likely go mad.&lt;/p>
&lt;p>They often work with no standard tool for build and install. They have to
dig into other people source code daily and fix errors regarding build and dependencies.
Likewise, they also have to discuss and teach developers about how distributions and standard
works. Knowing Linux hierarchy, where to place files and a lot of unwritten rules to make systems
work is surely out of the scope for most developers. And I think they have all the rights to skip
this knowledge. They develop software, they don&amp;rsquo;t build systems (but there are exceptions too!).&lt;/p>
&lt;p>However, developers are (almost) always asked to write the installation target for their software,
may it be a shell script or a complex C codebase. Here, tools often don&amp;rsquo;t help the developers,
as they don&amp;rsquo;t properly support or enforce the various standards.
Therefore, package maintainers have to fill the gap themselves. It usually happens in their own
distribution package specification. How many distributions are there? Tons. And this
work is duplicated countless times.&lt;/p>
&lt;p>While developing software written in Rust, I have found a gap in &lt;code>cargo-install&lt;/code>: it doesn&amp;rsquo;t
consider any data or file outside of executables and libraries. In spite of that, applications
usually have many files to install; man pages, documentation, examples, &lt;code>.desktop&lt;/code>
files and icons. What do developers do in this case? They either add a &lt;code>Makefile&lt;/code> or entirely
skip the installation target. This is something that happens not only to Rust projects, but
to many others types.&lt;/p>
&lt;p>I have engineered a tool to fill the gap, &lt;strong>&lt;a href="https://git.sr.ht/~danyspin97/rinstall">rinstall&lt;/a>&lt;/strong>, and this post is about its rationale,
usage and how it could &lt;strong>improve packaging on Linux&lt;/strong> (and other *nix systems too!).&lt;/p>
&lt;h2 id="rinstall">rinstall&lt;/h2>
&lt;p>rinstall is a small (at the time of writing, just ~600 LOC!) helper tool that has two
main objectives:&lt;/p>
&lt;ul>
&lt;li>Help developers define which files their program shall install without knowing all the various
standards, hierarchy and the quirks of writing &lt;em>Makefiles&lt;/em>.&lt;/li>
&lt;li>Remove the duplicated code in the distribution packages definitions that manually use &lt;code>cp&lt;/code> and
&lt;code>install&lt;/code> to install files.&lt;/li>
&lt;/ul>
&lt;p>It doesn&amp;rsquo;t try to replace tools such as &lt;code>meson&lt;/code>, that already wonderfully covers the installation
phase. It doesn&amp;rsquo;t try to replace either &lt;code>CMake&lt;/code> or &lt;code>make&lt;/code> when they are already used for
compiling in C/C++ projects. Although they don&amp;rsquo;t do any enforcing, they are already used,
so it doesn&amp;rsquo;t make a lot of sense to add a new dependency on a new tool.&lt;/p>
&lt;p>I am sure most of you are ready to throw knives at me the moment I said I want to replace
&lt;code>Makefiles&lt;/code> in some contexts. I know what you&amp;rsquo;re feeling, but please hold on and continue reading.
There will be an in-depth comparison and explanation. If you still aren&amp;rsquo;t satisfied by then,
I won&amp;rsquo;t stop you anymore!&lt;/p>
&lt;h3 id="install-directories">Install directories&lt;/h3>
&lt;p>&lt;strong>rinstall&lt;/strong> supports two installation modes out of the box: &lt;strong>system-wide&lt;/strong> and &lt;strong>user&lt;/strong> install.&lt;/p>
&lt;p>The first installs into &lt;code>/usr/local&lt;/code> by default, making the programs available to all system users.
It follows the &lt;em>&lt;a href="https://www.gnu.org/prep/standards/html_node/Directory-Variables.html">Directory Variables&lt;/a>&lt;/em> from the &lt;em>GNU Coding Standard&lt;/em>. Binaries will be installed
into &lt;code>/usr/local/bin&lt;/code>, libraries into &lt;code>/usr/local/lib&lt;/code> and so on. The prefix can be changed by
passing it into the command line, as well as all the other variables.&lt;/p>
&lt;p>The second installs into the &lt;code>HOME&lt;/code> folder of the current user, following the
&lt;em>&lt;a href="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG Base Directory Specification&lt;/a>&lt;/em>. Binaries will be installed into &lt;code>~/.local/bin&lt;/code>,
libraries into &lt;code>~/.local/lib&lt;/code>, and all the other variables will use the various &lt;code>XDG_*&lt;/code> variables
with default fallback.&lt;/p>
&lt;p>It also reads the configuration from &lt;code>/etc/rinstall.yml&lt;/code> when running as root and
&lt;code>.config/rinstall.yml&lt;/code> when running in user mode. If the configuration file exists,
the tool will merge said config with the default one.&lt;/p>
&lt;p>In addition, it also supports a &lt;code>--destdir&lt;/code> argument. Packagers can just call the following
command to perform the installation phase of a program:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># rinstall --destdir mydir --prefix /usr --no-config&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="installyml">&lt;code>install.yml&lt;/code>&lt;/h3>
&lt;p>&lt;strong>rinstall&lt;/strong> resolves around the per-project file &lt;code>install.yml&lt;/code>. This file contains the
list of files to install, divided per category, as well as the name and version of the software.
For example this is the &lt;code>install.yml&lt;/code> for &lt;strong>rinstall&lt;/strong> itself:&lt;/p>
&lt;pre tabindex="0">&lt;code>name: rinstall
version: 0.1
type: rust
exe:
- src: rinstall
docs:
- src: LICENSE.md
- src: README.md
&lt;/code>&lt;/pre>&lt;p>Each outmost key (&lt;code>exe&lt;/code> and &lt;code>docs&lt;/code> in this case) contains a list of sources, abbreviated &lt;code>src&lt;/code>,
and optionally the destination, abbreviated &lt;code>dst&lt;/code>. &lt;strong>rinstall&lt;/strong> will install the source into either
the folder or file that destination points to, using the respective folder the for key used.
It supports many keys and common cases, allowing to the developers to write
as little as possible. In this case, its output would be:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># rinstall&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;target/release/rinstall&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/bin/rinstall&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;LICENSE.md&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/doc/rinstall-0.1/LICENSE.md&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;README.md&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/doc/rinstall-0.1/README.md&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>One of the projects that I stumbled upon which would benefit from using &lt;strong>rinstall&lt;/strong> is the
widely used terminal emulator &lt;em>&lt;a href="https://github.com/alacritty/alacritty">Alacritty&lt;/a>&lt;/em>. In addition to its static executable (Rust did it
again!), there is the man page, the example configuration, the &lt;code>.desktop&lt;/code> file and its logo.
However, it lacks a &lt;code>Makefile&lt;/code> and so the packagers (as well as the users) are required to
manually install these files. The Arch Linux &lt;a href="https://github.com/archlinux/svntogit-community/blob/packages/alacritty/trunk/PKGBUILD#L32">alacritty package&lt;/a>
contains the following instructions:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl"> desktop-file-install -m &lt;span class="m">644&lt;/span> --dir &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/applications/&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;extra/linux/Alacritty.desktop&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m755 &lt;span class="s2">&amp;#34;target/release/alacritty&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/bin/alacritty&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/alacritty.man&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/man/man1/alacritty.1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/linux/io.alacritty.Alacritty.appdata.xml&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/appdata/io.alacritty.Alacritty.appdata.xml&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;alacritty.yml&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/doc/alacritty/example/alacritty.yml&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/completions/alacritty.bash&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/bash-completion/completions/alacritty&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/completions/_alacritty&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/zsh/site-functions/_alacritty&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/completions/alacritty.fish&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/fish/vendor_completions.d/alacritty.fish&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> install -D -m644 &lt;span class="s2">&amp;#34;extra/logo/alacritty-term.svg&amp;#34;&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="nv">$pkgdir&lt;/span>&lt;span class="s2">/usr/share/pixmaps/Alacritty.svg&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Its &lt;code>install.yml&lt;/code> would be:&lt;/p>
&lt;pre tabindex="0">&lt;code>name: alacritty
version: 0.8.0
type: rust
exe:
- src: alacritty
man:
1:
- extra/alacritty.man
completions:
- bash: extra/completions/alacritty.bash
- fish: extra/completions/alacritty.fish
- zsh: extra/completions/_alacritty
data:
- src: extra/logo/alacritty-term.svg
dst: icons/hicolor/scalable/apps/Alacritty.svg
docs:
- src: alacritty.yml
dst: example/
appdata:
- src: extra/linux/io.alacritty.Alacritty.appdata.xml
desktop-files:
- src: extra/linux/Alacritty.desktop
&lt;/code>&lt;/pre>&lt;p>And this would be the output from &lt;strong>rinstall&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># rinstall&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;target/release/alacritty&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/bin/alacritty&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/logo/alacritty-term.svg&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/icons/hicolor/scalable/apps/Alacritty.svg&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/alacritty.man&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/man/man1/alacritty.1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;alacritty.yml&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/doc/alacritty-0.8.0/example/alacritty.yml&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/linux/Alacritty.desktop&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/applications/Alacritty.desktop&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/linux/io.alacritty.Alacritty.appdata.xml&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/appdata/io.alacritty.Alacritty.appdata.xml&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/completions/alacritty.bash&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/bash-completion/completions/alacritty.bash&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/completions/alacritty.fish&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/usr/share/fish/vendor_completions.d/alacritty.fish&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Installing &lt;span class="s2">&amp;#34;extra/completions/_alacritty&amp;#34;&lt;/span> to &lt;span class="s2">&amp;#34;/usr/local/share/zsh/site-functions/_alacritty&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The original Arch Linux package contains 9 hardcoded install instructions that could be
replaced by 1 single line of a call to &lt;strong>rinstall&lt;/strong>. That&amp;rsquo;s 8 lines less. According to &lt;a href="https://repology.org">repology&lt;/a>,
alacritty is packaged for more than 30 different distributions. That&amp;rsquo;s 240 lines less gained
by improving a single package! Yea, the improvement might actually be minor for other packages,
but it&amp;rsquo;s still considerable, counting the thousand of packages out there!&lt;/p>
&lt;h2 id="makefiles-comparison">Makefiles comparison&lt;/h2>
&lt;p>I am sure many are asking why not add a &lt;code>Makefile&lt;/code> for Alacritty instead? That&amp;rsquo;s a great question.
In my opinion, these are the various reasons:&lt;/p>
&lt;ul>
&lt;li>its syntax is complicated and not easy to learn. Learning it as a requirement to install a simple
shell script seems overkill to me.&lt;/li>
&lt;li>it is made to track dependencies between sources and objects and correctly compile software.&lt;/li>
&lt;li>not only &lt;a href="https://www.gnu.org/prep/standards/html_node/Directory-Variables.html">Directory Variables&lt;/a> standard is not enforced, the developer has to write support for it
by himself. Asking the developer to learn an entire standard and the quirks of the
&lt;a href="https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard#:~:text=The%20Filesystem%20Hierarchy%20Standard%20(FHS,released%20on%203%20June%202015.">Filesystem Hierarchy Standard&lt;/a> seems again overkill.&lt;/li>
&lt;/ul>
&lt;p>While I was discussing &lt;strong>rinstall&lt;/strong> with a developer, he sent me &lt;a href="https://github.com/dylanaraps/fff/blob/master/Makefile">this&lt;/a>
&lt;code>Makefile&lt;/code> to show me that they are really simple to write and that they support &lt;code>MANDIR&lt;/code>
and &lt;code>DOCDIR&lt;/code> without issues. Let&amp;rsquo;s review its content:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl"> PREFIX ?&lt;span class="o">=&lt;/span> /usr
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> MANDIR ?&lt;span class="o">=&lt;/span> &lt;span class="k">$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/share/man
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> DOCDIR ?&lt;span class="o">=&lt;/span> &lt;span class="k">$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/share/doc/fff
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nf">all&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @echo Run &lt;span class="se">\&amp;#39;&lt;/span>make install&lt;span class="se">\&amp;#39;&lt;/span> to install fff.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nf">install&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @mkdir -p &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/bin
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @mkdir -p &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>MANDIR&lt;span class="k">)&lt;/span>/man1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @mkdir -p &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>DOCDIR&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p fff &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/bin/fff
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p fff.1 &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>MANDIR&lt;span class="k">)&lt;/span>/man1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p README.md &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>DOCDIR&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @chmod &lt;span class="m">755&lt;/span> &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/bin/fff
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nf">uninstall&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @rm -rf &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>PREFIX&lt;span class="k">)&lt;/span>/bin/fff
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @rm -rf &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>MANDIR&lt;span class="k">)&lt;/span>/man1/fff.1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @rm -rf &lt;span class="k">$(&lt;/span>DESTDIR&lt;span class="k">)$(&lt;/span>DOCDIR&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>But, ironically, he sent me a Makefile with an error in it. Did you spot it?
I am sure that somebody did. For the rest, don&amp;rsquo;t mind, it&amp;rsquo;s actually a little (but crucial!)
detail: the default &lt;code>PREFIX&lt;/code> is &lt;code>/usr&lt;/code> instead of &lt;code>/usr/local&lt;/code>. Not only this is wrong
according to the standard, but it opens the user to subtle breakage. The user could run &lt;code>make install&lt;/code> as root and expect to have the newly installed files into &lt;code>/usr/local&lt;/code>. He would then
to discover afterwards that it has silently installed into &lt;code>/usr&lt;/code>. Only the package manager
should install into &lt;code>/usr&lt;/code>, as it tracks all the files there. He may have
overwritten packages installed by the package manager and have potentially broken the system!&lt;/p>
&lt;p>The equivalent &lt;code>install.yml&lt;/code> is:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">fff&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0.1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">custom&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">exe&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">src&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">fff&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">man&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">1&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="l">fff.1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">docs&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">src&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">README.md&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This was pretty a pretty subtle error to spot. More often the error will be easier to catch but
just as bad, such as a missing &lt;code>DESTDIR&lt;/code>. I think it&amp;rsquo;s not the developers mistake, as it is not fair
to ask them to write such fragile files following a standard that they might not even know that
well.&lt;/p>
&lt;h2 id="source-based-distributions">Source based distributions&lt;/h2>
&lt;p>&lt;strong>rinstall&lt;/strong> has been written in Rust. It is a language I have been learning recently and
that I fun to write into. It is also safe and fast, so I didn&amp;rsquo;t give a second thought to use it
here. However, there have been an excellent critic regarding &lt;strong>rinstall&lt;/strong> by a Gentoo maintainer:
does it mean that Rust toolchain will be needed by Gentoo stage3 when performing the base
installation?&lt;/p>
&lt;p>&lt;strong>rinstall&lt;/strong> aims at projects that are not already using a build system capable of installing
software. In other words, I don&amp;rsquo;t want to replace Makefiles when they are already used
for compiling sources. This already exclude most of the software that needs to be compiled
in a stage3 or when bootstrapping. Moreover, having an &lt;code>install.yml&lt;/code> does not enforce anyone to use
&lt;strong>rinstall&lt;/strong>; the files could still be installed manually. In alternative, there will be a
release of &lt;strong>rinstall&lt;/strong> available for anyone to grab; this will allow users to just download
the static executable of &lt;strong>rinstall&lt;/strong> and use it.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>
&lt;img src="https://imgs.xkcd.com/comics/standards_2x.png" alt="">
&lt;/p>
&lt;p>This might as well be as introducing a new &amp;ldquo;standard&amp;rdquo; way to install files into the system.
However, I feel like an improvement in that regard is possible and that adding a new standard
is the only way to do so.&lt;/p>
&lt;p>&lt;strong>rinstall&lt;/strong> has been written in just a week and is actually missing some interesting use cases,
such as installing software from the release tarball. This is something that I am looking
forward to adding in the near future.&lt;/p>
&lt;p>I want to thank everyone that has provided feedback on both &lt;strong>rinstall&lt;/strong> and this post.&lt;/p></description></item><item><title>Replacing Openssl, Part 1: wolfSSL</title><link>https://danyspin97.org/blog/replacing-openssl-part-1-wolfssl/</link><pubDate>Wed, 06 Jan 2021 16:15:00 +0100</pubDate><guid>https://danyspin97.org/blog/replacing-openssl-part-1-wolfssl/</guid><description>&lt;p>This post highlight my experiment of replacing OpenSSL cryptographic library
with its embedded competitor: &lt;code>wolfssl&lt;/code>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Prerequites&lt;/strong>&lt;/em>: &lt;em>Basic knowledge about C/C++ programming&lt;/em>.&lt;/p>
&lt;h2 id="a-bit-of-background-about-openssl">A bit of background about OpenSSL&lt;/h2>
&lt;p>OpenSSL is one of the most crucial libraries on a Unix system: it performs
cryptographic functions and it provides &lt;em>Transport Layer Security&lt;/em> (&lt;em>TLS&lt;/em>) and &lt;em>Secure Sockets Layer&lt;/em> (&lt;em>SSL&lt;/em>) protocols to applications.&lt;/p>
&lt;p>According to the &lt;em>Arch Linux&lt;/em> &lt;a href="https://archlinux.org/packages/core/x86_64/openssl/">OpenSSL package&lt;/a>, &lt;strong>355&lt;/strong> packages, out of the
&lt;em>11523&lt;/em> available, depend on it. You can find it installed on any Unix system
(and on Windows too!).&lt;/p>
&lt;p>It started in 1998 as a fork of &lt;a href="https://en.wikipedia.org/wiki/SSLeay">SSLeay&lt;/a> and it has been in development since.
Two full-time developers work on it, as well as many volunteers.&lt;/p>
&lt;p>Fast forward to 2014: a &lt;em>&lt;a href="https://en.wikipedia.org/wiki/Common_Vulnerabilities_and_Exposures">CVE&lt;/a>&lt;/em> had been issued regarding a high risk
vulnerability found in OpenSSL. It has been given the name &lt;strong>&lt;a href="https://heartbleed.com/">Heartbleed&lt;/a>&lt;/strong>,
because it has been found in the &lt;em>TLS&lt;/em>/&lt;em>DTLS&lt;/em> heartbeat extension (&lt;a href="https://tools.ietf.org/html/rfc6520">RFC6520&lt;/a>).
This vulnerability allowed attackers to steal sensitive data, such as secret
keys, user names and passwords.&lt;/p>
&lt;p>All the community turned to the OpenSSL project, weighting its implementation
and security policy. Heartbleed have been promptly fixed, but there could be new
vulnerabilities in the future, if security was not properly prioritized during
development.&lt;/p>
&lt;p>At this point, OpenBSD&amp;rsquo;s folks forked OpenSSL and started a new project:
&lt;a href="https://www.libressl.org/">LibreSSL&lt;/a>. It primary goals were to &lt;strong>modernize the codebase and to improve
its security&lt;/strong>. This new project hasn&amp;rsquo;t been adopted by big distributions such
Ubuntu and Arch Linux; instead smaller distributions (at that time) replaced
OpenSSL with LibreSSL on their default configuration, such as Alpine and Void.&lt;/p>
&lt;p>In the last years, LibreSSL have seen a decline in its usage. Alpine switched
back to OpenSSL (&lt;a href="https://lists.alpinelinux.org/~alpine/devel/%3C20181011171746.4c01f758%40ncopa-desktop.copa.dup.pw%3E">link to the thread&lt;/a>). Many people and distributions are
considering doing the same, since OpenSSL got the improvement that LibreSSL
aimed for. And it&amp;rsquo;s still the &lt;em>de facto standard&lt;/em> cryptographic library on Unix.&lt;/p>
&lt;h2 id="why-replacing-openssl-now">Why replacing OpenSSL now?&lt;/h2>
&lt;p>OpenSSL works fine, there is no denying that. Every software has &lt;em>out of the box
support for it&lt;/em> so it costs no effort in term of additional mainteinance.
However, there are &lt;strong>newer and lighter TLS and SSL implementations&lt;/strong>, which many
folks might prefer over the heavy OpenSSL&amp;rsquo;s one. I, too, prefer lightweight
libraries.&lt;/p>
&lt;p>I am uninstalling LibreSSL on my systems, therefore this might be the perfect
time to experiment with something different. I have found an interesting (and
well done!) library called &lt;em>&lt;strong>&lt;a href="https://wolfssl.com">wolfSSL&lt;/a>&lt;/strong>&lt;/em> that claims to have an &lt;em>OpenSSL
compatibility layer&lt;/em>. It also claims to be 20 times smaller than OpenSSL.&lt;/p>
&lt;h2 id="installation">Installation&lt;/h2>
&lt;p>&lt;strong>wolfSSL&lt;/strong> is a small C library; It uses &lt;em>autotools&lt;/em> to build and &lt;strong>CMake&lt;/strong>
support is being added (sigh!). Upon running &lt;code>configure&lt;/code>, I am overwhelmed by
the quantity of compile options available.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/wolf-ssl-configure.jpg" alt="">
&lt;figcaption>some of the wolfSSL configure options&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>Fortunately, there is one comfy option which I&amp;rsquo;ve used
when compiling wolfSSL: &lt;code>--enable-all&lt;/code>. It enables all options, including
the OpenSSL compatibility layer and leaves out the &lt;em>SSL 3&lt;/em> protocol.&lt;/p>
&lt;p>Upon completing the build and installation (which takes a couple of
minutes), a library &lt;code>libwolfssl.so&lt;/code> will be installed into &lt;code>/usr/lib&lt;/code>, as
well as a pkgconfig file (&lt;code>wolfssl.pc&lt;/code>) and all the headers.&lt;/p>
&lt;h2 id="out-of-the-box-support">Out of the box support&lt;/h2>
&lt;p>Key applications provide support for different SSL implementations other than
OpenSSL. For example &lt;em>curl&lt;/em> supports &lt;em>mbedTLS&lt;/em>, &lt;em>BearSSL&lt;/em> and our &lt;strong>wolfSSL&lt;/strong>.
To compile &lt;em>curl&lt;/em> using wolfSSL, we just need to add &lt;code>--with-ssl=wolfssl&lt;/code> and
we&amp;rsquo;re done. I am aware of only two packages that have out of the box support
for wolfSSL and they are &lt;em>curl&lt;/em> and &lt;em>&lt;a href="https://gitlab.com/gnuwget/wget2">wget2&lt;/a>&lt;/em> (not the legacy version!).&lt;/p>
&lt;h2 id="openssl-compatibility">OpenSSL compatibility&lt;/h2>
&lt;p>&lt;code>--enable-all&lt;/code> configure option enabled the OpenSSL compatibility layer.
To use this layer, according to the &lt;a href="https://www.wolfssl.com/docs/wolfssl-manual/ch13/">documentation&lt;/a>, we need to link the wolfssl
library manually by adding &lt;code>-lwolfssl&lt;/code> as link argument. We also need to
include the path &lt;code>/usr/include/wolfssl&lt;/code> so that the OpenSSL headers in
&lt;code>/usr/include/wolfssl/openssl&lt;/code> will be picked up.&lt;/p>
&lt;p>This way both wolfSSL and OpenSSL can coexist on the same system and the latter
can be replaced on a per project basis. However, that&amp;rsquo;s not what we want since
want to replace OpenSSL at a system level.&lt;/p>
&lt;p>Adding the link flag to each package on the system or patching one by one
is not an option as it would take too much time. Let&amp;rsquo;s instead apply some
workarounds.&lt;/p>
&lt;p>First, we create a symlink for the headers:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ sudo ln -sf /usr/include/wolfssl/openssl /usr/include/openssl
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Then we create a symlink for each library. OpenSSL provides the following
libraries:&lt;/p>
&lt;ul>
&lt;li>&lt;code>libssl.so&lt;/code>&lt;/li>
&lt;li>&lt;code>libcrypto.so&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>So we can run:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ sudo ln -sf /usr/lib/libwolfssl.so /usr/lib/libssl.so
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ sudo ln -sf /usr/lib/libwolfssl.so /usr/lib/libcrypto.so
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="fixing-pkg-config">Fixing pkg-config&lt;/h3>
&lt;p>Some software rely on pkg-config for checking OpenSSL dependency since
it provides the following pkg-config files:&lt;/p>
&lt;ul>
&lt;li>&lt;code>libssl.pc&lt;/code>&lt;/li>
&lt;li>&lt;code>libcrypto.pc&lt;/code>&lt;/li>
&lt;li>&lt;code>openssl.pc&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>My system doesn&amp;rsquo;t currently have either OpenSSL or LibreSSL installed, so any
attempt to include OpenSSL by using pkg-config will fail. We can fix this by
adding a pkg-config file in &lt;code>/usr/lib/pkgconfig/openssl.pc&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>prefix=/usr/x86_64-pc-linux-musl
includedir=${prefix}/include/wolfssl
Name: openssl
Description: wolfssl C library.
Version: 4.6.0
Requires: wolfssl
Cflags: -I${includedir}
&lt;/code>&lt;/pre>&lt;p>Our pkg-config file will include the correct directory containing the OpenSSL
headers. It will also import cflags and link flags from the wolfssl pkg-config.
Let&amp;rsquo;s try if it works as intended:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ pkg-config --cflags --libs openssl
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">-I/usr/x86_64-pc-linux-musl/include/wolfssl -lwolfssl
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Yes! Now we just need create symlinks the other two pkg-config files:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ sudo ln -sf /usr/lib/pkgconfig/openssl.pc /usr/lib/pkgconfig/libssl.pc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ sudo ln -sf /usr/lib/pkgconfig/openssl.pc /usr/lib/pkgconfig/libcrypto.pc
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now we&amp;rsquo;re ready to compile system packages.&lt;/p>
&lt;h2 id="compiling-system-packages">Compiling system packages&lt;/h2>
&lt;p>Before actually going further into the various compile results, there are few
general changes that I&amp;rsquo;ve done:&lt;/p>
&lt;ol>
&lt;li>Include the default &lt;code>/usr/include/wolfssl/option.h&lt;/code> provided in
&lt;code>/usr/include/wolfssl/wolfcrypt/setting.h&lt;/code>. This way we will have a bunch of
defines already included that enable many wolfSSL features.&lt;/li>
&lt;li>Remove some defines from &lt;code>option.h&lt;/code> that disable old OpenSSL features, like
old SSL names. While I understand that these features are plainly old (or even
deprecated), projects will still use them as long as they haven&amp;rsquo;t been
removed upstream.&lt;/li>
&lt;li>Define &lt;code>OPENSSL_NO_WHIRPOOL&lt;/code> in the same header as above, since this feature
ins&amp;rsquo;t implemented in wolfSSL. There are other &lt;code>OPENSSL_NO_*&lt;/code> defines there for
unimplemented features, but this one was missing.&lt;/li>
&lt;/ol>
&lt;h3 id="wget">wget&lt;/h3>
&lt;p>&lt;em>&lt;a href="https://www.gnu.org/software/wget/">wget&lt;/a>&lt;/em>, which comes installed on any Unix system, is the first software we&amp;rsquo;ll
try building with wolfSSL and its OpenSSL compatibility layer.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/wget-error-1.jpg" alt="">
&lt;figcaption>wget compile error&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>wget complains about two undeclared identifiers:&lt;/p>
&lt;ul>
&lt;li>&lt;code>CONF_MFLAGS_DEFAULT_SECTION&lt;/code>&lt;/li>
&lt;li>&lt;code>CONF_MFLAGS_IGNORE_MISSING_FILE&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>We can fix this by adding the defines from the OpenSSL file &lt;code>openssl/conf.h&lt;/code>
to &lt;code>/usr/include/wolfssl/option.h&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-c" data-lang="c">&lt;span class="line">&lt;span class="cl">&lt;span class="cp"># define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp"># define CONF_MFLAGS_DEFAULT_SECTION 0x20
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/wget-error-2.jpg" alt="">
&lt;figcaption>wget link-time errors about missing symbols&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>We arrived at link-time, that&amp;rsquo;s huge! However, there are 8 undefined symbols:
6 symbols about unimplemented features in wolfSSL, such as &lt;code>i2d_x509_PUBKEY&lt;/code>
and &lt;code>a2i_IPADDRESS&lt;/code>; 2 symbols regarding wolfSSL functions. The latter could
probably be fixed by adding the proper compile time option to wolfSSL, like
&lt;code>--enable-sslv3&lt;/code>.&lt;/p>
&lt;h3 id="rhash">rhash&lt;/h3>
&lt;p>rhash is an utility that calculates and verifies message digests, such as
&lt;em>SHA256&lt;/em> and &lt;em>MD5&lt;/em>. It is required by CMake, so we can consider it an essential
package. Compiling rhash led to many errors. Let&amp;rsquo;s look in depth at some of
them.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/rhash-error-1.jpg" alt="">
&lt;figcaption>rhash compile error about RIPEMD160_CTX&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>&lt;em>rhash&lt;/em> uses &lt;code>RIPEMD160_CTX&lt;/code> which is not implemented by wolfSSL.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/rhash-error-2.jpg" alt="">
&lt;figcaption>rhash compile error about WOLFSSL_MD5_CTX&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>This time, rhash access a member of &lt;code>MD5_CTX&lt;/code> (which wolfSSL has replaced by
&lt;code>WOLFSSL_MD5_CTX&lt;/code>) using &lt;code>offsetof&lt;/code>. The original &lt;code>MD5_CTX&lt;/code> struct looks like
this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-c" data-lang="c">&lt;span class="line">&lt;span class="cl">&lt;span class="k">typedef&lt;/span> &lt;span class="k">struct&lt;/span> &lt;span class="n">MD5state_st&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">MD5_LONG&lt;/span> &lt;span class="n">A&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">B&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">C&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">D&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">MD5_LONG&lt;/span> &lt;span class="n">Nl&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Nh&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">MD5_LONG&lt;/span> &lt;span class="n">data&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">MD5_LBLOCK&lt;/span>&lt;span class="p">];&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">unsigned&lt;/span> &lt;span class="kt">int&lt;/span> &lt;span class="n">num&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span> &lt;span class="n">MD5_CTX&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>WOLFSSL_MD5_CTX&lt;/code> instead looks like this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-c" data-lang="c">&lt;span class="line">&lt;span class="cl">&lt;span class="k">typedef&lt;/span> &lt;span class="k">struct&lt;/span> &lt;span class="n">WOLFSSL_MD5_CTX&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="cm">/* big enough to hold wolfcrypt md5, but check on init */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">#ifdef STM32_HASH
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">&lt;/span> &lt;span class="kt">void&lt;/span>&lt;span class="o">*&lt;/span> &lt;span class="n">holder&lt;/span>&lt;span class="p">[(&lt;/span>&lt;span class="mi">112&lt;/span> &lt;span class="o">+&lt;/span> &lt;span class="n">WC_ASYNC_DEV_SIZE&lt;/span> &lt;span class="o">+&lt;/span> &lt;span class="k">sizeof&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">STM32_HASH_Context&lt;/span>&lt;span class="p">))&lt;/span> &lt;span class="o">/&lt;/span> &lt;span class="k">sizeof&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)];&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">#else
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">&lt;/span> &lt;span class="kt">void&lt;/span>&lt;span class="o">*&lt;/span> &lt;span class="n">holder&lt;/span>&lt;span class="p">[(&lt;/span>&lt;span class="mi">112&lt;/span> &lt;span class="o">+&lt;/span> &lt;span class="n">WC_ASYNC_DEV_SIZE&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">/&lt;/span> &lt;span class="k">sizeof&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kt">void&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">)];&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">#endif
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">&lt;/span>&lt;span class="p">}&lt;/span> &lt;span class="n">WOLFSSL_MD5_CTX&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>I think that this incosistency between OpenSSL and wolfSSL structs &lt;em>will&lt;/em>
happen again with different data types.&lt;/p>
&lt;h3 id="libssh2">libssh2&lt;/h3>
&lt;p>From the official &lt;a href="https://www.libssh2.org/">libssh2&lt;/a> site:&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>libssh2 a client-side C library implementing the SSH2 protocol&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;p>curl has a hard dependency on libssh2, so we can consider it another essential
package.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/libssh2-error-1.jpg" alt="">
&lt;figcaption>libssh2 build errors&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>This time there are only 2 errors, both about unimplemented features:
&lt;code>EVP_bf_cbc&lt;/code> and &lt;code>EVP_cast5_cbc&lt;/code>. The man pages are the best source of
information about OpenSSL functions; we can browse them by running:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ man EVP
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ man EVP_bf_cbc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ man EVP_cast5_cbc
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Let&amp;rsquo;s split the names and study each part:&lt;/p>
&lt;ul>
&lt;li>&lt;code>EVP&lt;/code> is a high-level interface to cryptographic functions&lt;/li>
&lt;li>&lt;code>bf&lt;/code> and &lt;code>cast5&lt;/code> are the name of the algorithms, &lt;em>&lt;a href="https://en.wikipedia.org/wiki/Blowfish_(cipher)">blowfish&lt;/a>&lt;/em> and &lt;em>&lt;a href="https://en.wikipedia.org/wiki/CAST-128">CAST&lt;/a>&lt;/em>
respectively.&lt;/li>
&lt;li>&lt;code>cbc&lt;/code>, &lt;em>&lt;a href="https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#:~:text=Cipher%20block%20chaining%20(CBC),-CBC&amp;amp;text=In%20CBC%20mode%2C%20each%20block,used%20in%20the%20first%20block.">Cipher Block Chaining&lt;/a>&lt;/em>, is a mode of operation that tells OpenSSL
to operate on each block seperately from the others.&lt;/li>
&lt;/ul>
&lt;p>Operating cryptographic functions in &lt;em>CBC&lt;/em> mode isn&amp;rsquo;t really safe nor the
two algorithms above are really popular, so I understand why wolfSSL developers
might have prioritized other things over implementing the two functions above.&lt;/p>
&lt;h3 id="ffmpeg">ffmpeg&lt;/h3>
&lt;p>&lt;em>&lt;a href="https://ffmpeg.org/">ffmpeg&lt;/a>&lt;/em> is a powerful library and a collection of utilities for handling
images, audio and videos. It is required by &lt;em>Firefox&lt;/em>, &lt;em>Chromium&lt;/em>, &lt;em>mpv&lt;/em> and
another hundred and a half software (at least). We surely don&amp;rsquo;t want a system
without this library.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/replacing-openssl-part-1-wolfssl/ffmpeg-error.jpg" alt="">
&lt;figcaption>ffmpeg build error&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>This time there is only one error (but others may still pop up later while
building!). The function &lt;code>BN_sub_word&lt;/code> is missing. According to the man pages,
it is the arithmetic function that perform subtractions on big integers.
This seems pretty straightforward to add in wolfSSL.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>I&amp;rsquo;ve tried building different essential software and none of them succeeded
using wolfSSL and its OpenSSL compatibility layer. However, most of them had
small errors that can probably be fixed in a day or two. That&amp;rsquo;s a shame because
wolfSSL is really close to replace OpenSSL at a distro level, and yet so distant
since it&amp;rsquo;s not its priority. Basing on what I&amp;rsquo;ve seen and the documentation,
the OpenSSL compatibility layer is best used on a per-project basis, where
you can fix your code or replace missing features with modern ones (or
even better, you can pay them to implement the features you need).&lt;/p></description></item><item><title>Colorize your CLI</title><link>https://danyspin97.org/blog/colorize-your-cli/</link><pubDate>Sun, 26 Jul 2020 15:30:00 +0100</pubDate><guid>https://danyspin97.org/blog/colorize-your-cli/</guid><description>&lt;p>&lt;em>&lt;strong>Prerequisites&lt;/strong>&lt;/em>: &lt;em>basic understanding of CLI and of common programs&lt;/em>.&lt;/p>
&lt;p>The &lt;em>&lt;a href="https://en.wikipedia.org/wiki/Command-line_interface">Command Line Interface&lt;/a>&lt;/em> (abbreviated &lt;code>CLI&lt;/code> for the rest of the post) is
the swiss knife of many developers and sysadmins out there. Unix systems provide
a settings layer that can be rapidly accessed using some CLI utilities.&lt;/p>
&lt;p>And that&amp;rsquo;s just the tip of the iceberg. The CLI allows us to do almost
everything without leaving the comfort of the keyboard. From browsing files and directories (using &lt;a href="https://github.com/jarun/nnn">nnn&lt;/a> or &lt;a href="https://ranger.github.io/">ranger&lt;/a>) to reading and sending emails (using
&lt;em>&lt;a href="https://aerc-mail.org/">aerc&lt;/a>&lt;/em>).&lt;/p>
&lt;p>However, most programs we use:&lt;/p>
&lt;ul>
&lt;li>disable colors by default, sticking to the same default since their initial
release. E.g.: &lt;strong>ls&lt;/strong> and &lt;strong>grep&lt;/strong> accept a &lt;code>--color&lt;/code> argument for enabling colored output, &lt;em>or&lt;/em>&lt;/li>
&lt;li>do not implement colors at all, e.g., &lt;strong>df&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>There are a lot of references on the web regarding this topic, like &lt;a href="https://wiki.archlinux.org/index.php/Color_output_in_console">Color
output in console&lt;/a> page in the &lt;em>Arch Linux&lt;/em> wiki and various Stack Overflow
&lt;a href="https://unix.stackexchange.com/questions/148/colorizing-your-terminal-and-shell-environment">questions&lt;/a>.
They propose multiple solutions that sometimes overlap with each other. One
must go through all the documentation, choose carefully and follow the
installation procedure, and this can become tedious in a short amount of time.&lt;/p>
&lt;p>In this post, we will &lt;strong>setup a colourised&lt;/strong> &lt;code>CLI&lt;/code> &lt;strong>using the programs
described&lt;/strong> above. This will be a comprehensive guide and there will be (almost)
no need to read any documentation.&lt;/p>
&lt;p>Please note that this is based on my personal setup, based on my personal
preferences. Feel free to skip/change anything you dislike, as it won&amp;rsquo;t impact
the rest of the guide.&lt;/p>
&lt;h2 id="starship">Starship&lt;/h2>
&lt;p>This is what the bash prompt looks like out of the box:&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/bash-prompt.png" alt="">
&lt;/p>
&lt;p>The first step into our colored journey is to making this prompt both more
meaningful and better to look at.&lt;/p>
&lt;p>There are a lot of prompt plugins out there. However, most of them work only
in a single shell or require the installation of a framework like &lt;code>Oh-My-&amp;lt;shell&amp;gt;&lt;/code>. What I have instead chosen is a shell agnostic prompt:
&lt;a href="https://starship.rs/">&lt;strong>starship&lt;/strong>&lt;/a>.&lt;/p>
&lt;p>&lt;strong>starship&lt;/strong> is a fast (really fast!) prompt written in Rust that works in all
shells (including exotic shells such as Ion).&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/starship-prompt.png" alt="">
&lt;/p>
&lt;p>Let&amp;rsquo;s have a look at our new prompt inside a git repository:&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/starship-git.png" alt="">
&lt;/p>
&lt;/br>
&lt;p>&lt;strong>starship&lt;/strong> is available in the following
&lt;a href="https://repology.org/project/starship/versions">distributions&lt;/a>.
If your distribution isn&amp;rsquo;t listed, you can run:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ curl -fsSL https://starship.rs/install.sh | bash
&lt;/code>&lt;/pre>&lt;p>To enable it in &lt;code>bash&lt;/code>, add the following to the end of &lt;code>~/.bashrc&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">eval&lt;/span> &lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="k">$(&lt;/span>starship init bash&lt;span class="k">)&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For enabling it in different shells, like &lt;code>zsh&lt;/code> or &lt;code>fish&lt;/code>, follow the
&lt;a href="https://starship.rs/guide/#%F0%9F%9A%80-installation">getting started guide&lt;/a>
on the official site.&lt;/p>
&lt;h2 id="generic-colourizer">Generic Colourizer&lt;/h2>
&lt;p>Let&amp;rsquo;s take as example a well known and widely used program: &lt;code>df&lt;/code>.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/df-plain.png" alt="">
&lt;/p>
&lt;p>As you can see, it&amp;rsquo;s clear but plain and somehow hard to follow. Let&amp;rsquo;s use
&lt;a href="https://github.com/garabik/grc">&lt;strong>Generic Colourizer&lt;/strong>&lt;/a> to improve its output:&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/df-grc.png" alt="">
&lt;/p>
&lt;p>Now it seems like a total different program!&lt;/p>
&lt;p>As we have just seen, &lt;strong>Generic colourizer&lt;/strong> is a wrapper that uses regex to
add colors and modifiers (&lt;strong>bold&lt;/strong>, &lt;em>italic&lt;/em>) to a program&amp;rsquo;s output.
Among the supported programs there are &lt;code>id&lt;/code>, &lt;code>env&lt;/code>, &lt;code>sysctl&lt;/code> and &lt;code>mount&lt;/code>.&lt;/p>
&lt;p>You can install it using the package manager, as it is available in almost every
&lt;a href="https://repology.org/project/grc/versions">distribution&lt;/a>.&lt;/p>
&lt;p>To enable it in &lt;code>bash&lt;/code>, add the following at the end of your &lt;code>~/.bashrc&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>[[ -s &amp;#34;/etc/profile.d/grc.bashrc&amp;#34; ]] &amp;amp;&amp;amp; source /etc/profile.d/grc.bashrc
&lt;/code>&lt;/pre>&lt;p>To enable it in &lt;code>zsh&lt;/code> or &lt;code>fish&lt;/code>, respectively source &lt;code>/etc/grc.zsh&lt;/code> or
&lt;code>/etc/grc.fish&lt;/code>.&lt;/p>
&lt;p>These configuration files will add aliases to the supported programs. I.e.,
next time you run &lt;code>df&lt;/code>, the shell will automatically run &lt;code>grc df&lt;/code>.&lt;/p>
&lt;h2 id="ls">ls&lt;/h2>
&lt;p>&lt;code>ls&lt;/code> command is one of the commands that by default do not use colors, although
they are avaiable by using &lt;code>--color&lt;/code> argument.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/ls.png" alt="">
&lt;/p>
&lt;p>Simply add an alias in your config. For &lt;code>bash&lt;/code> users, add the following in
your &lt;code>~/.bashrc&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">alias&lt;/span> &lt;span class="nv">ls&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;ls --color=auto&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="grep">grep&lt;/h2>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/grep.png" alt="">
&lt;/p>
&lt;p>As for ls, add an alias to &lt;code>grep --color=auto&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code># ~/.bashrc
alias grep=&amp;#39;grep --color=auto&amp;#39;
&lt;/code>&lt;/pre>&lt;h2 id="diff">diff&lt;/h2>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/diff.png" alt="">
&lt;/p>
&lt;p>As for ls, add an alias to &lt;code>diff --color=auto&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code># ~/.bashrc
alias diff=&amp;#39;diff --color=auto&amp;#39;
&lt;/code>&lt;/pre>&lt;h2 id="man">man&lt;/h2>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/colored-man.png" alt="">
&lt;/p>
&lt;p>To add colors to &lt;code>man&lt;/code>, we need to add colors to &lt;code>less&lt;/code>. In &lt;code>bash&lt;/code>, this can be
achieved by creating a file &lt;code>~/.config/less/termcap&lt;/code> with the following content:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_mb&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput bold&lt;span class="p">;&lt;/span> tput setaf 2&lt;span class="k">)&lt;/span> &lt;span class="c1"># green&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_md&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput bold&lt;span class="p">;&lt;/span> tput setaf 6&lt;span class="k">)&lt;/span> &lt;span class="c1"># cyan&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_me&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput sgr0&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_so&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput bold&lt;span class="p">;&lt;/span> tput setaf 3&lt;span class="p">;&lt;/span> tput setab 4&lt;span class="k">)&lt;/span> &lt;span class="c1"># yellow on blue&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_se&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput rmso&lt;span class="p">;&lt;/span> tput sgr0&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_us&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput smul&lt;span class="p">;&lt;/span> tput bold&lt;span class="p">;&lt;/span> tput setaf 7&lt;span class="k">)&lt;/span> &lt;span class="c1"># white&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_ue&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput rmul&lt;span class="p">;&lt;/span> tput sgr0&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_mr&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput rev&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_mh&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput dim&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_ZN&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput ssubm&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_ZV&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput rsubm&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_ZO&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput ssupm&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS_TERMCAP_ZW&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="k">$(&lt;/span>tput rsupm&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">GROFF_NO_SGR&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="m">1&lt;/span> &lt;span class="c1"># For Konsole and Gnome-terminal&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>And then in your &lt;code>.bashrc&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Get color support for &amp;#39;less&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESS&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;--RAW-CONTROL-CHARS&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Use colors for less, man, etc.&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">[[&lt;/span> -f ~/.config/less/termcap &lt;span class="o">]]&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> . ~/.config/less/termcap
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If you are using &lt;code>fish&lt;/code>, add the following to your &lt;code>~/.config/fish/config.fish&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_md &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[01;31m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_me &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[0m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_se &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[0m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_so &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[01;44;33m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_ue &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[0m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS_TERMCAP_us &lt;span class="o">(&lt;/span>&lt;span class="nb">printf&lt;/span> &lt;span class="s2">&amp;#34;\e[01;32m&amp;#34;&lt;/span>&lt;span class="o">)&lt;/span>In
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">set&lt;/span> -xU LESS &lt;span class="s2">&amp;#34;--RAW-CONTROL-CHARS&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="highlight">highlight&lt;/h2>
&lt;p>When reading a file using &lt;code>less&lt;/code>, the output is the plain file, as we were
reading the file through &lt;code>cat&lt;/code>.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/less.png" alt="">
&lt;/p>
&lt;p>This can be improved by by passing the file through
&lt;a href="http://www.andre-simon.de/doku/highlight/highlight.php">&lt;strong>highlight&lt;/strong>&lt;/a>.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/highlight.png" alt="">
&lt;/p>
&lt;p>We now have &lt;strong>syntax highlighting&lt;/strong>!&lt;/p>
&lt;p>&lt;code>highlight&lt;/code> can be found in almost all &lt;a href="https://repology.org/project/highlight/versions">distributions&lt;/a>. After
installing it using your package manager, add the following to your &lt;code>~/.bashrc&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">LESSOPEN&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;| /usr/bin/highlight %s --out-format xterm256 --force&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>By adding &lt;code>--line-numbers&lt;/code>, highlight will also show line numbers.
You can also customize its style by adding &lt;code>--style &amp;lt;style&amp;gt;&lt;/code>; for the
screenshot, the &lt;code>molokai&lt;/code> theme has been used. Please read the
&lt;a href="http://www.andre-simon.de/doku/highlight/highlight.php">documentation&lt;/a>
for further customizations.&lt;/p>
&lt;h2 id="bonus-for-bash-users-blesh">Bonus for bash users: ble.sh&lt;/h2>
&lt;p>&lt;code>bash&lt;/code>, contrary to its alternatives &lt;code>zsh&lt;/code> and &lt;code>fish&lt;/code>, &lt;strong>does not have a
powerful line editing&lt;/strong>. By default the command you write won&amp;rsquo;t be highlighted
and the completion won&amp;rsquo;t be shown.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/bash-no-blesh-1.png" alt="">
&lt;img src="https://danyspin97.org/img/colorize-your-cli/bash-no-blesh-2.png" alt="">
&lt;/p>
&lt;p>&lt;a href="https://github.com/akinomyoga/ble.sh">&lt;strong>Bash Line Editor&lt;/strong>&lt;/a> (also called
&lt;code>ble.sh&lt;/code>) is a flexible plugin that makes bash closer to the other two shells.&lt;/p>
&lt;p>Let&amp;rsquo;s have a look at the exact two situations above and the difference &lt;code>ble.sh&lt;/code>
does.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/colorize-your-cli/bash-ble-1.png" alt="">
&lt;img src="https://danyspin97.org/img/colorize-your-cli/bash-ble-2.png" alt="">
&lt;/p>
&lt;p>To install &lt;code>ble.sh&lt;/code> run the following commands:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">$ &lt;span class="nb">cd&lt;/span> /tmp
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ git clone --recursive https://github.com/akinomyoga/ble.sh.git
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ &lt;span class="nb">cd&lt;/span> ble.sh
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ make
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>ble.sh&lt;/code> will be installed inside &lt;code>~/.local/share/blesh&lt;/code>.&lt;/p>
&lt;p>Now add the following lines at the top of your &lt;code>~/.bashrc&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-sh" data-lang="sh">&lt;span class="line">&lt;span class="cl">&lt;span class="o">[[&lt;/span> &lt;span class="nv">$-&lt;/span> &lt;span class="o">==&lt;/span> *i* &lt;span class="o">]]&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> &lt;span class="nb">source&lt;/span> ~/.local/share/blesh/ble.sh --noattach
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>And the following lines at the end of the same file:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="o">((&lt;/span>_ble_bash&lt;span class="o">))&lt;/span> &lt;span class="o">&amp;amp;&amp;amp;&lt;/span> ble-attach
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>After setting up the above programs/aliases you will have a different
experience when using your CLI.&lt;/p>
&lt;p>In this post we have mostly used &lt;strong>common command line programs&lt;/strong>, although
&lt;em>modern alternatives exist&lt;/em>, e.g., &lt;a href="https://github.com/BurntSushi/ripgrep">ripgrep&lt;/a> as alternative to &lt;code>grep&lt;/code>. Those
will be probably covered in another post.&lt;/p>
&lt;p>Did you like the configuration presented through this post? Do you have other
way of adding colors to your CLI? &lt;em>Comment below and let me know&lt;/em>!&lt;/p></description></item><item><title>tt#dev2: C++ rewrite</title><link>https://danyspin97.org/blog/tt-dev2-cpp-rewrite/</link><pubDate>Sun, 24 May 2020 16:30:00 +0200</pubDate><guid>https://danyspin97.org/blog/tt-dev2-cpp-rewrite/</guid><description>&lt;p>Second update on &lt;a href="https://github.com/danyspin97/tt">tt&lt;/a> development. You can find the first &lt;a href="https://danyspin97.org/blog/tt-development-update-1/">here&lt;/a>.&lt;/p>
&lt;p>The last months with D programming language has been good. Except for the language compiler. There are three different D compilers out there, which are themselves written in D. How do you compile them without a D compiler?&lt;br>
You use an already &lt;strong>compiled compiler executable&lt;/strong> (sorry for the pun) for your &lt;em>system/architecture&lt;/em>. musl is not supported however, so this created a lot of problems for me.&lt;/p>
&lt;p>I gave up to Dlang because I don&amp;rsquo;t feel comfortable asking users to go all that
I went through for bootstrapping a D compiler on a &lt;em>unsupported system&lt;/em>.
tt has been &lt;strong>converted to C++&lt;/strong>. Which took time indeed, but wasn&amp;rsquo;t a painful
process after learning how to apply tt design in C++.&lt;/p>
&lt;h2 id="c-rewrite">C++ rewrite&lt;/h2>
&lt;p>What I am about to write in this post is related to:&lt;/p>
&lt;ul>
&lt;li>The &lt;strong>rewrite&lt;/strong> that gave me the possibility to improve the low-level parser implementation and change some detail of the service format.&lt;/li>
&lt;li>The new language choosen that opened up some new challenges, implementation
differences and optimizations possibilities.&lt;/li>
&lt;/ul>
&lt;h2 id="service-format-update">Service format update&lt;/h2>
&lt;p>Arrays are now enclosed by square brackets (&lt;code>[]&lt;/code>) to avoid ambiguity between an array and a code value. Array and code can now be found in the same section.&lt;/p>
&lt;pre tabindex="0">&lt;code>[options]
depends = [ myval ]
&lt;/code>&lt;/pre>&lt;p>Quotes around values have been removed to simplify the parser implementation:&lt;/p>
&lt;pre tabindex="0">&lt;code>[main]
name = mount-fstab
type = oneshot
&lt;/code>&lt;/pre>&lt;p>However the quotes are still required in the &lt;code>[config]&lt;/code> section to emphasize
that key/value pairs in this section will be written into the environment. This
is important because the environment keys are stricter than usual: only
&lt;code>[A-ZA-z0-9_]&lt;/code> is supported and the first character cannot be a number.
Another advantage is that here trailing spaces can be spotted at a first glance,
as they might be a problem with some service/user configuration.&lt;/p>
&lt;pre tabindex="0">&lt;code>[config]
CMDARGS=&amp;#34;--debug&amp;#34;
&lt;/code>&lt;/pre>&lt;h2 id="c17">C++17&lt;/h2>
&lt;p>C++ is a language that have been heavily changed (and improved) in the latest
standard. C++17 standard adds many useful features in its standard library,
such as &lt;code>std::variant&lt;/code>, &lt;code>std::optional&lt;/code> and &lt;code>std::filesystem&lt;/code>. Since &lt;em>tt&lt;/em> is a
new codebase and &lt;strong>C++17 support is considered complete&lt;/strong> in the latest releases
of both &lt;em>GCC&lt;/em> and &lt;em>Clang&lt;/em>, it seems a good idea to use these features.&lt;/p>
&lt;h3 id="stdoptional">std::optional&lt;/h3>
&lt;p>From &lt;a href="https://en.cppreference.com/w/cpp/utility/optional">cppreference&lt;/a>:&lt;/p>
&lt;blockquote>
&lt;p>The class template std::optional manages an optional contained value, i.e. a value that may or may not be present.&lt;/p>
&lt;/blockquote>
&lt;p>Let&amp;rsquo;s see its usage from &lt;code>tt/data/script.hpp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="k">namespace&lt;/span> &lt;span class="n">tt&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">Script&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Methods
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="c1">// ...
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="k">private&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Type&lt;/span> &lt;span class="n">type_&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">string&lt;/span> &lt;span class="n">execute_&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">optional&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">string&lt;/span>&lt;span class="o">&amp;gt;&lt;/span> &lt;span class="n">user_&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">optional&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">string&lt;/span>&lt;span class="o">&amp;gt;&lt;/span> &lt;span class="n">group_&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span> &lt;span class="c1">// namespace tt
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The class &lt;code>Script&lt;/code> &lt;strong>may optionally contain&lt;/strong> a defined &lt;code>user&lt;/code> or &lt;code>group&lt;/code>.
&lt;code>std::optional&lt;/code> wrap up this feature nicely. We may check and get its value by
doing:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user_&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">cout&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">user_&lt;/span>&lt;span class="o">-&amp;gt;&lt;/span>&lt;span class="n">get&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">endl&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="stdfilesystempath">std::filesystem::path&lt;/h3>
&lt;p>From &lt;a href="https://en.cppreference.com/w/cpp/filesystem/path">cppreference&lt;/a>:&lt;/p>
&lt;blockquote>
&lt;p>Objects of type path represent paths on a filesystem.&lt;/p>
&lt;/blockquote>
&lt;p>This class is used to handle services paths and extensions. From
&lt;code>src/data/service_impl.cpp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="kt">void&lt;/span> &lt;span class="n">tt&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">ServiceImpl&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">ValidatePath&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="k">const&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">filesystem&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">path&lt;/span> &lt;span class="n">file&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="p">());&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">file&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">stem&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">!=&lt;/span> &lt;span class="n">name&lt;/span>&lt;span class="p">())&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">throw&lt;/span> &lt;span class="nf">ServiceNameDoNotMatchFileExecption&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This method check that the name of the service is the same as the name of the
file without extension.&lt;/p>
&lt;h3 id="stdvariant">std::variant&lt;/h3>
&lt;p>From &lt;a href="https://en.cppreference.com/w/cpp/utility/variant">cppreference&lt;/a>:&lt;/p>
&lt;blockquote>
&lt;p>The class template std::variant represents a type-safe union.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>std::variant&lt;/code> is used in tt to store either a &lt;code>Bundle&lt;/code>, a &lt;code>Longrun&lt;/code> or a
&lt;code>Oneshot&lt;/code> services, which are all instances of the base service file,
&lt;code>ServiceImpl&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="k">using&lt;/span> &lt;span class="n">Service&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">variant&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">Bundle&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Longrun&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Oneshot&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Instead of storing a &lt;code>std::vector&lt;/code> of pointers to &lt;code>ServiceImpl&lt;/code>, the
&lt;code>std::variant&lt;/code> can be stored. This change of the data structures might lead to
&lt;strong>better&lt;/strong> &lt;a href="https://gameprogrammingpatterns.com/data-locality.html">&lt;strong>data
locality&lt;/strong>&lt;/a>
and therefore &lt;strong>better performance&lt;/strong>. This is important especially when we
iterate over this vector multiple time; the &lt;code>DependencyGraph&lt;/code> class may need to
iterate repeatedly over all the services enabled and is the component that will
most benefit from using &lt;code>std::variant&lt;/code>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Notes&lt;/strong>&lt;/em>: &lt;em>The &lt;code>DependencyGraph&lt;/code> class will be explained in depth in the
next update&lt;/em>.&lt;/p>
&lt;h3 id="stdvisit">std::visit&lt;/h3>
&lt;p>From &lt;a href="https://en.cppreference.com/w/cpp/utility/variant/visit">cppreference&lt;/a>:&lt;/p>
&lt;blockquote>
&lt;p>Applies the visitor vis to the variants vars.&lt;/p>
&lt;/blockquote>
&lt;p>The perfect companion for &lt;code>std::variant&lt;/code> is &lt;code>std::visit&lt;/code> that let us use &lt;strong>the
visitor patter over this container&lt;/strong>.&lt;/p>
&lt;p>Two examples of its usage in the tt codebase. From
&lt;code>src/dependency_graph/dependency_graph.cpp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl"> &lt;span class="k">auto&lt;/span> &lt;span class="n">get_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[](&lt;/span>&lt;span class="k">auto&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">service&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="n">service&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">();&lt;/span> &lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">const&lt;/span> &lt;span class="k">auto&lt;/span> &lt;span class="n">name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">visit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">get_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">service&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Here we use a closure to get the name of the service. &lt;code>ServiceImpl&lt;/code> has
a public &lt;code>string name();&lt;/code> method so all the three classes contained in the
&lt;code>std::variant&lt;/code> have it.&lt;/p>
&lt;p>From &lt;code>include/tt/parser/service/dependency_reader&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">DependencyReader&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">public&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">vector&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">string&lt;/span>&lt;span class="o">&amp;gt;&lt;/span> &lt;span class="n">dependencies&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="k">return&lt;/span> &lt;span class="n">dependencies_&lt;/span>&lt;span class="p">;&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">void&lt;/span> &lt;span class="nf">operator&lt;/span>&lt;span class="p">()(&lt;/span>&lt;span class="k">const&lt;/span> &lt;span class="n">Bundle&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">bundle&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">void&lt;/span> &lt;span class="nf">operator&lt;/span>&lt;span class="p">()(&lt;/span>&lt;span class="k">const&lt;/span> &lt;span class="n">Longrun&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">longrun&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">void&lt;/span> &lt;span class="nf">operator&lt;/span>&lt;span class="p">()(&lt;/span>&lt;span class="k">const&lt;/span> &lt;span class="n">Oneshot&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">oneshot&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">private&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">vector&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">string&lt;/span>&lt;span class="o">&amp;gt;&lt;/span> &lt;span class="n">dependencies_&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>From &lt;code>src/parser/service/services_parser.cpp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl"> &lt;span class="n">tt&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">DependencyReader&lt;/span> &lt;span class="n">dep_reader&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">visit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">dep_reader&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">service&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In this example, the object &lt;code>dep_reader&lt;/code> is used to visit the &lt;code>std::variant&lt;/code>.
An object is used because it will be used later to access the dependencies read
from the service.&lt;/p>
&lt;h2 id="external-libraries">External libraries&lt;/h2>
&lt;p>The &lt;strong>C++ standard library has different features compared to the Dlang one&lt;/strong>.
Specifically, these are the features that I have lost from the switch:&lt;/p>
&lt;ul>
&lt;li>Good command line arguments parser&lt;/li>
&lt;li>JSON serialization&lt;/li>
&lt;li>Logging&lt;/li>
&lt;li>String formatting&lt;/li>
&lt;li>Unit testing&lt;/li>
&lt;/ul>
&lt;p>None of the above functionalities are trivial to implement, so I have to resort
on either &lt;strong>include libraries into tt codebase&lt;/strong> or &lt;strong>link to external
libraries&lt;/strong>.&lt;/p>
&lt;h3 id="tayweargs">Taywe/args&lt;/h3>
&lt;p>For parsing command line arguments I have chosen &lt;a href="">Taywe/args&lt;/a> header-only
library. I need a parser that is able to declare subcommands and assign
specific options to them. I have tried many cli arguments parsers and I have
found out that most of them declare a static parser object; then this object
can be reused that in different classes/sources.
&lt;em>Taywe/args&lt;/em> lets you instead &lt;strong>configure the subcommand called by the user at runtime&lt;/strong>, which is really similar to what was done in Dlang.&lt;/p>
&lt;p>From file &lt;code>main.cpp&lt;/code> (simplified code):&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="kt">int&lt;/span> &lt;span class="nf">main&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kt">int&lt;/span> &lt;span class="n">argc&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kt">char&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="n">argv&lt;/span>&lt;span class="p">[])&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">args&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">ArgumentParser&lt;/span> &lt;span class="n">parser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;tt init/rc manager.&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">args&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">Command&lt;/span> &lt;span class="n">tt_parse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">parser&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s">&amp;#34;parse&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s">&amp;#34;Parse one or more services for testing purposes.&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">tt&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">ParseCommand&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">Dispatch&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">try&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">parser&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">ParseCLI&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">argc&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">argv&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">catch&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">args&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">Help&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">std&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">cout&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">parser&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">catch&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">args&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">Error&lt;/span> &lt;span class="o">&amp;amp;&lt;/span>&lt;span class="n">e&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">cerr&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">e&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">what&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">endl&lt;/span> &lt;span class="o">&amp;lt;&amp;lt;&lt;/span> &lt;span class="n">parser&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>tt::ParseCommand::Dispatch&lt;/code> will be called when &lt;code>parse&lt;/code> subcommand has been
requested by the user. This method will take a &lt;code>args::Subparser&amp;amp;&lt;/code> argument
that will configure all options specific to the subcommand and reparse all
the cli argumnts left.&lt;/p>
&lt;h3 id="catch2">Catch2&lt;/h3>
&lt;p>&lt;a href="https://github.com/catchorg/Catch2">Catch2&lt;/a> is a powerful unit-tests framework
that has a wide adoption among C++ Open Source projects. The only disadvantage
is that the testing isn&amp;rsquo;t internal to the class but it is instead declared in
a separate source file. This is not strictly related to this awesome library
but to the language itself. For this reason, all the unit tests on private
methods have been dropped.&lt;/p>
&lt;p>From &lt;code>test/parsr/lin/section_line_parser.cpp&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-cpp" data-lang="cpp">&lt;span class="line">&lt;span class="cl">&lt;span class="n">TEST_CASE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;SectionLineParser&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">SECTION&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;parse valid section&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">auto&lt;/span> &lt;span class="n">parser&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">tt&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">SectionLineParser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;[foo]&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">REQUIRE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">parser&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">IsLineValid&lt;/span>&lt;span class="p">());&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">SECTION&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;parse invalid section&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">auto&lt;/span> &lt;span class="n">parser&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">tt&lt;/span>&lt;span class="o">::&lt;/span>&lt;span class="n">SectionLineParser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;foo&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">REQUIRE&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">!&lt;/span>&lt;span class="n">parser&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">IsLineValid&lt;/span>&lt;span class="p">());&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="other-libraries">Other libraries&lt;/h2>
&lt;p>The above libraries have been already integrated into the codebase. For the
other missing features I have been considering other libraries such as
&lt;a href="https://github.com/fmtlib/fmt">fmt&lt;/a> and
&lt;a href="https://github.com/gabime/spdlog">spdlog&lt;/a>. However, they will be introduced
in next updates as they have been integrated and used properly.&lt;/p>
&lt;h2 id="static-analysis-and-tools">Static analysis and tools&lt;/h2>
&lt;p>C++ is a widely adopted language, so there are many tools to ease its
development. The rewrite ensured a better meson support (yay!) and the
possibility to run static analysis tools.&lt;/p>
&lt;p>Among the static analysis tools used locally there are
&lt;a href="https://clang.llvm.org/extra/clang-tidy/">&lt;em>clang-tidy&lt;/em>&lt;/a> and
&lt;a href="https://github.com/oclint/oclint">&lt;em>oclint&lt;/em>&lt;/a>. They showed a lot of improvements
for the codebase and some logic error too. &lt;em>oclint&lt;/em> also check &lt;strong>path complexity&lt;/strong>,
&lt;strong>method complexity&lt;/strong> and &lt;strong>file complexity&lt;/strong>, warning you about things that
should be refactored. In addition, some static analizer run remotely thanks to
&lt;a href="https://lgtm.com/">LGTM&lt;/a>, &lt;a href="https://www.codefactor.io/">CodeFactory&lt;/a> and
&lt;a href="https://www.codacy.com/">Codacy&lt;/a>.&lt;/p>
&lt;p>However, &lt;strong>coverage is not measured any more&lt;/strong> due to various errors on &lt;em>CodeCov&lt;/em>.
I have also considered &lt;a href="https://coveralls.io/">Coveralls&lt;/a>, but generating the
coverage from meson isn&amp;rsquo;t straightforward either. I am planning to readd this
in the future.&lt;/p>
&lt;p>C++ suffers from
&lt;a href="https://en.cppreference.com/w/cpp/language/ub">Undefined Behaviour&lt;/a>,
especially when the program is compiled with (aggressive) optimizations enabled.
&lt;em>tt&lt;/em> should be able to run even when compiled with aggressive optimizations, so
I am closely following the static analizers&amp;rsquo; warnings and I have enabled the
&lt;em>undefined behaviour sanitizer&lt;/em> when running the test in the &lt;em>CI&lt;/em> (thanks meson
for being awesome).&lt;/p></description></item><item><title>tt: Development update #1</title><link>https://danyspin97.org/blog/tt-development-update-1/</link><pubDate>Tue, 10 Mar 2020 19:30:00 +0100</pubDate><guid>https://danyspin97.org/blog/tt-development-update-1/</guid><description>&lt;p>Devember as long finished, but not all the projects started during the challenge did the same. This is the case for &lt;em>&lt;strong>&lt;a href="https://github.com/danyspin97/tt">tt&lt;/a>&lt;/strong>&lt;/em>, the init/rc manager that &lt;em>strives to replace systemd&lt;/em>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Notes&lt;/strong>&lt;/em>: &lt;em>If you do not know what tt is, I really invite you to read the previous two posts(&lt;a href="https://danyspin97.org/blog/devember-2019-rewriting-66/">link1&lt;/a>, &lt;a href="https://danyspin97.org/blog/devember-2019-first-ten-days/">link2&lt;/a>) on the matter, as this one is a continuation. Nevertheless, it is not a requirement for reading this post&lt;/em>.&lt;/p>
&lt;h2 id="starting-point">Starting point&lt;/h2>
&lt;p>In my last update I have written about using &lt;a href="https://github.com/madmurphy/libconfini/">libconfini&lt;/a> to parse an environment file with a simple key/value format. This file is read at runtime by services and will be used for configuration.&lt;/p>
&lt;p>Example file:&lt;/p>
&lt;pre tabindex="0">&lt;code>FOO=&amp;#34;BAR&amp;#34;
&lt;/code>&lt;/pre>&lt;p>The above example follows the &lt;a href="https://en.wikipedia.org/wiki/INI_file">INI file&lt;/a> specification and libconfini was suited as a parser.&lt;/p>
&lt;h2 id="service-format">Service format&lt;/h2>
&lt;p>I started developing the next part: the service file parser. To do so, the format needed to be defined first.&lt;/p>
&lt;p>What is tt under the hood? Put it simple, it is a wrapper around s6-rc: it takes one or more services files and convert into &lt;a href="https://skarnet.org/software/s6/servicedir.html">s6 service directories&lt;/a>; tt service file should mostly follow s6 directory structure. obarun (66 creator) has defined such a &lt;a href="https://web.obarun.org/software/66/frontend.html">format&lt;/a> before me, so let’s have a look at it.&lt;/p>
&lt;p>&lt;code>mount-fstab&lt;/code> file from &lt;a href="https://gitlab.exherbo.org/exherbo-misc/66-exherbo/-/tree/master">66-exherbo&lt;/a>:&lt;/p>
&lt;pre tabindex="0">&lt;code>[main]
@type = oneshot
@name = mount-fstab
@description = &amp;#34;Parse and mount all the devices listed in /etc/fstab&amp;#34;
@user = ( root )
@depends = ( fsck mount-rwfs )
[start]
@build = auto
@execute = (
foreground { s6-echo -- &amp;#34;Starting oneshot: mount-fstab&amp;#34; }
foreground { mount --all }
s6-echo -- &amp;#34;Done oneshot: mount-fstab&amp;#34;
)
&lt;/code>&lt;/pre>&lt;p>The file is straigthforward to read if you are used to s6 service directory. There is a &lt;code>[main]&lt;/code> section that defines basic service information and &lt;code>[start]&lt;/code> section for this oneshot.&lt;/p>
&lt;p>I do not like the keys starting with the hat character (&lt;code>@&lt;/code>) but overall it is a good start. &lt;strong>tt service format has been defined &lt;a href="https://github.com/DanySpin97/tt/issues/2">here&lt;/a>&lt;/strong> and it is somehow similar.&lt;/p>
&lt;p>&lt;code>mount-fstab&lt;/code> written in tt format:&lt;/p>
&lt;pre tabindex="0">&lt;code>[main]
name = mount-fstab
polish_name = Mount partitions
description = &amp;#34;Parse and mount all the devices listed in /etc/fstab&amp;#34;
type = oneshot
[start]
build = auto
execute = (
foreground { s6-echo -- “Starting oneshot: mount-fstab” }
foreground { mount --all }
s6-echo -- “Done oneshot: mount-fstab”
)
[options]
depends = ( fsck mount-rwfs )
&lt;/code>&lt;/pre>&lt;p>&lt;em>&lt;strong>Notes&lt;/strong>&lt;/em>: &lt;em>A lot of changes and new keys are already been either introduced or &lt;a href="https://github.com/DanySpin97/tt/issues/9">proposed&lt;/a> to enhance tt format. 66 format has just been the inspiration and the start but tt is&lt;/em> &lt;em>&lt;strong>not&lt;/strong>&lt;/em> &lt;em>a mere copy&lt;/em>.&lt;/p>
&lt;h2 id="discarding-libconfini">Discarding libconfini&lt;/h2>
&lt;p>tt service respects the INI format &lt;strong>except for the &lt;code>execute&lt;/code> key&lt;/strong>, which contains a multiline string with no &lt;em>escape character&lt;/em>. This is not supported by INI parser such as libconfini.&lt;/p>
&lt;p>libconfini only supports multiline strings when the newline is escaped. From its &lt;a href="https://github.com/madmurphy/libconfini/blob/master/examples/ini_files/self_explaining.conf#L40">example&lt;/a>:&lt;/p>
&lt;pre tabindex="0">&lt;code>multi-line = this is\
a multi-line value!
&lt;/code>&lt;/pre>&lt;p>The most important parts of a service file are its scripts which could be one or more per file and each spans at least a few lines. Personally, I consider the requirement of an escape character at the end of every line too much tedious. After all I will mantain many services myself and I want it to be as easy as possible, withouth this big drawback. Imagine having the parser tell you &amp;ldquo;&lt;em>look, you forgot to add an escape line, now go back and search for it&lt;/em>&amp;rdquo; now and then.&lt;/p>
&lt;p>This is the reason I had to &lt;strong>discard libconfini as the parsing library&lt;/strong>.&lt;/p>
&lt;p>I considered other format like TOML, which supports the following:&lt;/p>
&lt;pre tabindex="0">&lt;code>multi-line = &amp;#34;&amp;#34;&amp;#34;
multiline value
spanning two lines&amp;#34;&amp;#34;&amp;#34;
&lt;/code>&lt;/pre>&lt;p>However, I wasn’t satisfied with its syntax. In the end I choosed to write a &lt;em>custom parser&lt;/em>.&lt;/p>
&lt;h2 id="valid-values">Valid values&lt;/h2>
&lt;h3 id="parsing-code">Parsing code&lt;/h3>
&lt;p>The file is divided in sections, and &lt;em>each service type has different sections&lt;/em>. Each section contains key/value pairs (with or without the quoted value) and code.&lt;/p>
&lt;p>Some strictness is required when parsing code, otherwise we could interpret code as token of the service format. Consider the following code:&lt;/p>
&lt;pre tabindex="0">&lt;code>execute=( x=$(cat /etc/fstab)
echo $x
)
&lt;/code>&lt;/pre>&lt;p>The parser could misleadingly &lt;strong>treat the last parenthesis as the closing token&lt;/strong> of the &lt;code>execute&lt;/code> key, and the next line would be considered &lt;em>invalid&lt;/em>. If the parser counts opened parenthesis, then this will somehow work.
However, only unquoted parenthesis should be counted, and the quoted ones should not be considered. This exponentially increase the parser complexity and opens up to tons of bugs and not-trivial edge cases.&lt;/p>
&lt;p>If we only consider the following two examples everything become easy and reliable to parse:&lt;/p>
&lt;pre tabindex="0">&lt;code>execute = &amp;#34;/usr/bin/foo -d&amp;#34;
execute = (
x=$(cat /etc/fstab)
echo $x
)
&lt;/code>&lt;/pre>&lt;p>The first one will be parsed as a one-line key/value pair; the latter will be treated as a multiline code, with no possible case of the code itself being treated as a token.&lt;/p>
&lt;h3 id="multiple-values">Multiple values&lt;/h3>
&lt;p>By writing a custom parser, tt format has also gained the possibility to give keys with multiple values their own &lt;em>rules&lt;/em>. Let’s take for example dependencies declaring:&lt;/p>
&lt;pre tabindex="0">&lt;code>depends = ( foo bar )
depends = (
foo bar )
depends = ( foo
bar
)
&lt;/code>&lt;/pre>&lt;p>Each of the previous examples is valid in tt. This increases the different type of keys to three: &lt;em>key/value pairs&lt;/em>, &lt;em>code values&lt;/em> and &lt;em>&lt;strong>multiple values spanning in multiple lines&lt;/strong>&lt;/em>.&lt;/p>
&lt;p>Code parser and multiple values’ parser are &lt;strong>ambigous&lt;/strong>, so the section can &lt;strong>allow only one of these two types&lt;/strong>. This is intended as it’s easier to remember the similar sintax instead of using different tokens. There is possibility of this syntax changing in the future if a section must have all three different kinds.&lt;/p>
&lt;h2 id="engineering-the-parser">Engineering the parser&lt;/h2>
&lt;p>&lt;img src='https://g.gravizo.com/svg?
@startuml;
abstract ServiceDirector;
abstract OptionsBuilder;
interface SectionBuilder;
ServiceParser -- ServiceDirector;
ServiceParser -- ParserFactory;
ParserFactory -- BundleDirector;
ParserFactory -- LongrunDirector;
ParserFactory -- OneshotDirector;
ServiceDirector &lt;-- BundleDirector;
ServiceDirector &lt;-- LongrunDirector;
ServiceDirector &lt;-- OneshotDirector;
ServiceDirector -- SectionBuilder;
SectionBuilder &lt;|-- MainSectionBuilder;
SectionBuilder &lt;|-- EnvironmentBuilder;
SectionBuilder &lt;|-- ScriptBuilder;
ScriptBuilder &lt;|-- LoggerScriptBuilder;
SectionBuilder &lt;|-- OptionsBuilder;
OptionsBuilder &lt;|-- BundleOptionsBuilder;
OptionsBuilder &lt;|-- LongrunOptionsBuilder;
OptionsBuilder &lt;|-- OneshotOptionsBuilder;
@enduml;
'>&lt;/p>
&lt;p>The UML diagram above shows the class design that parse a &lt;strong>single service file&lt;/strong>. Implementation details have been left out for the scope of this post; Implementation details such as the class &lt;code>SystemServicesParser&lt;/code> which gets a file location from a service name and the entire &lt;code>libtt.parser.line&lt;/code>/&lt;code>libtt.parser.word&lt;/code> modules that are used to parse the various bits of each line.&lt;/p>
&lt;p>The &lt;code>ServiceParser&lt;/code> load the lines of the file in memory and parses its first section (which must be a &lt;code>[main]&lt;/code> section) and gets its type. Then the &lt;code>ParserFactory&lt;/code> returns a &lt;code>ServiceDirector&lt;/code> class based on the type parsed.&lt;/p>
&lt;p>The &lt;code>ServiceDirector&lt;/code> derived classes &lt;strong>map each section to the respective&lt;/strong> &lt;code>SectionBuilder&lt;/code>. When a new section is found, its builder is instantiated, along with an empty data class or a pointer to it. For example a &lt;code>Script&lt;/code> pointer is passed to &lt;code>ScriptBuilder&lt;/code>; the latter receive its lines from the &lt;code>Director&lt;/code> and then proceed to parse them. When it has finished, a properly &lt;em>configured and instatiated&lt;/em> &lt;code>Script&lt;/code> is &lt;em>assigned to the pointer&lt;/em>.&lt;/p>
&lt;p>At the end of the parsing, the &lt;code>ServiceDirector&lt;/code> devired classes &lt;strong>instantiate their service using the data that builders have filled&lt;/strong>.&lt;/p>
&lt;p>Validation checks are performed in the data itself, except for &lt;em>volatile data&lt;/em>; in other words data that is parsed from the service file but do not translate 1:1 into the various tt data classes. To elaborate with an example: the logger script can be manually defined to specify a custom location, but this data isn’t then saved into the &lt;code>LoggerScript&lt;/code> class. It is instead used to generate the execute script and then it is discarded. This is one of the few cases where the validation check is performed into the builder itself.&lt;/p>
&lt;p>This is my first attempt at writing a custom parser, and I am satisfied with the current result. This design I have choosen makes it easy to re use components (&lt;code>EnvironmentBuilder&lt;/code> will be used to parse environment files) and it is easy to test.&lt;/p>
&lt;h2 id="parser-cli">Parser CLI&lt;/h2>
&lt;p>The parser is functional and parse complete services. It has a 75% unittest coverage so many bugs have been already been spotted and many else will be caught in a short time.&lt;/p>
&lt;p>For testing purpose I have added the possibility to &lt;strong>try the parser using tt CLI&lt;/strong>.
Let’s first build tt. A working installation of &lt;em>ldc2&lt;/em> (LLVM D compiler) and &lt;em>mesonbuild&lt;/em> are required; they can be installed using the package manager of your distribution.&lt;/p>
&lt;pre tabindex="0">&lt;code>$ git clone https://github.com/danyspin97/tt
$ meson build &amp;amp;&amp;amp; cd build &amp;amp;&amp;amp; ninja
$ ./src/tt/tt parse -f ../examples/mount-fstab
&lt;/code>&lt;/pre>&lt;h3 id="performance">Performance&lt;/h3>
&lt;p>Working systems tend to have more than 50 services available. It is therefore critical that the parsing takes as few CPU cycles as possible.&lt;/p>
&lt;p>Estimating the time needed using the POSIX utility &lt;code>time&lt;/code> shows us the following:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ time ./src/tt/tt parse -q -f ../examples/mount-fstab
real 0m0.020s
user 0m0.017s
sys 0m0.003s
&lt;/code>&lt;/pre>&lt;p>Considering all the overhead of instantiating a lot of classes, this is quite good. Using different threads with each parsing a different service, it will avoid an exponentially time increase when many services need to be parsed.&lt;/p>
&lt;h3 id="binary-size">Binary Size&lt;/h3>
&lt;p>tt strive to be minimal, so its library and executable should be really small. At the time of writing the stripped library weighs &lt;code>1.4M&lt;/code> and the stripped executable &lt;code>292k&lt;/code>; I am satisfied with these values, because, even if D is a compiled language, it still is a high level one.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>Thanks for reading this post and for following tt development. Top priority for tt is not to be running in the least time, but to be solid and well-tested, avoiding the rush and the technical debt that follows.&lt;/p>
&lt;p>&lt;em>Special thanks to &lt;a href="https://github.com/Cogitri">&lt;strong>@Cogitri&lt;/strong>&lt;/a> for all its contributions to the CLI and improving libtt code quality, as well for all his insights on the format and issues. Thanks also for the new contributor &lt;a href="https://github.com/pac85">&lt;strong>@pac85&lt;/strong>&lt;/a> which has worked on tt service serialation module (more on this in the next updates!)&lt;/em>.&lt;/p>
&lt;p>tt development also happens in the #tt &lt;a href="https://freenode.net/">freenode&lt;/a> channel. Feel free to join!&lt;/p></description></item><item><title>Modern CLI Applications: Part 1</title><link>https://danyspin97.org/blog/modern-cli-applications-part-1/</link><pubDate>Wed, 08 Jan 2020 16:20:00 +0100</pubDate><guid>https://danyspin97.org/blog/modern-cli-applications-part-1/</guid><description>&lt;p>Following the &lt;a href="https://danyspin97.org/blog/colorize-your-cli/">post&lt;/a> about colorizing the CLI,
this time you will discover some interesting CLI application to enhance your
workflow. For each app you will see its usage in real world examples and
a comparison with the other applications. This showcase will be split over
different posts with 4 applications each.&lt;/p>
&lt;p>Ready? Let&amp;rsquo;s begin the journey!&lt;/p>
&lt;p>&lt;em>&lt;strong>Prerequisites:&lt;/strong>&lt;/em> &lt;em>Basic knowledge about Unix command line and its
applications&lt;/em>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Notes:&lt;/strong>&lt;/em> &lt;em>For each software listed here, a link to its
&lt;a href="https://repology.org">repology&lt;/a> page will be attached; this way you can
check if it has been packaged for your distribution of choice and use the
system package manager to install it&lt;/em>.&lt;/p>
&lt;h2 id="exa">exa&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Homepage:&lt;/td>
&lt;td>&lt;a href="https://the.exa.website/">https://the.exa.website/&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repository:&lt;/td>
&lt;td>&lt;a href="https://github.com/ogham/exa">https://github.com/ogham/exa&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Written in:&lt;/td>
&lt;td>&lt;em>Rust&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repology:&lt;/td>
&lt;td>&lt;a href="https://repology.org/project/exa/">https://repology.org/project/exa/&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Dependencies:&lt;/td>
&lt;td>&lt;em>libgit2&lt;/em> (optional)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>ls&lt;/code> is the most used application while interacting with the CLI. For this
reason the first application is its modern alternative: &lt;code>exa&lt;/code>.&lt;/p>
&lt;p>The invocation is the same as &lt;code>ls&lt;/code>:&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/exa-1.png" alt="">
&lt;figcaption>Exa invocation with no arguments&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>Yay, exa printed out some colors. However, ls can do the same when using
&lt;code>--colors=auto&lt;/code>. Let&amp;rsquo;s try some advanced option.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/exa-2.png" alt="">
&lt;figcaption>exa invoked with advanced options&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>The options used above are self-documenting, but if you want to know more about
them, just call the help page of exa ( &lt;code>exa --help&lt;/code> ).&lt;/p>
&lt;p>You can personalize further how exa looks by adding more arguments.
For example this is my personal preference:&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/exa-3.png" alt="">
&lt;figcaption>exa invoked with my personal options&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;h3 id="shortcut">Shortcut&lt;/h3>
&lt;p>Wrapping up all the features highlighted above, here it is a function to use
as &lt;code>ls&lt;/code> alternative (here it is mapped to &lt;code>l&lt;/code> but feel free to map it
according to your preference):&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ &lt;span class="nb">alias&lt;/span> &lt;span class="nv">l&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;exa --icons --all --git --git-ignore --group-directories-first&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>You can notice that &lt;code>--long&lt;/code> have been removed, so that it can be added when you need call &lt;code>l&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ l --long
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>You can also use its abbreviated form &lt;code>-l&lt;/code> or add another alias &lt;code>ll&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ &lt;span class="nb">alias&lt;/span> &lt;span class="nv">ll&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;l --long&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="delta">delta&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Repository:&lt;/td>
&lt;td>&lt;a href="https://github.com/dandavison/delta">https://github.com/dandavison/delta&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Written in:&lt;/td>
&lt;td>&lt;em>Rust&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repology:&lt;/td>
&lt;td>&lt;a href="https://repology.org/project/git-delta/versions">https://repology.org/project/git-delta/versions&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Dependencies:&lt;/td>
&lt;td>&lt;em>libgit2&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The next application is a git diff viewer: &lt;code>delta&lt;/code>.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/delta-1.png" alt="">
&lt;figcaption>git diff output&lt;/figcaption>
&lt;/figure>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/delta-2.png" alt="">
&lt;figcaption>delta output&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>Delta takes git output, formats it in a stylish way and add syntax
highlighting. It supports many git commands like the following (and more):&lt;/p>
&lt;ul>
&lt;li>&lt;code>git diff&lt;/code>&lt;/li>
&lt;li>&lt;code>git show&lt;/code>&lt;/li>
&lt;li>&lt;code>git log -p&lt;/code>&lt;/li>
&lt;li>&lt;code>git stash show -p&lt;/code>&lt;/li>
&lt;li>&lt;code>git reflog -p&lt;/code>&lt;/li>
&lt;li>&lt;code>git add -p&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>To add &lt;code>delta&lt;/code> to &lt;code>git&lt;/code>, add the following to your &lt;code>~/.gitconfig&lt;/code> file:&lt;/p>
&lt;pre tabindex="0">&lt;code>[core]
pager = delta
[interactive]
diffFilter = delta --color-only
&lt;/code>&lt;/pre>&lt;h3 id="themes">Themes&lt;/h3>
&lt;p>&lt;code>delta&lt;/code> supports many themes; you can see the complete list by running:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ delta --list-syntax-themes
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>After you have found one that you like or that pairs well with your terminal
theme, add it to the config (&lt;code>~/.gitconfig&lt;/code>):&lt;/p>
&lt;pre tabindex="0">&lt;code>[delta]
syntax-theme = Monokai Extended
&lt;/code>&lt;/pre>&lt;p>Plus and minus color have to be chosen manually. Here I use the ones for
the Monokai theme (in &lt;code>delta&lt;/code> section as used above):&lt;/p>
&lt;pre tabindex="0">&lt;code> plus-color = &amp;#34;#ff6188&amp;#34;
minus-color = &amp;#34;#a9dc76&amp;#34;
&lt;/code>&lt;/pre>&lt;h3 id="side-by-side">Side by side&lt;/h3>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/delta-3.png" alt="">
&lt;figcaption>delta with side-by-side option enabled&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>To enable side by side comparison, add the following to &lt;code>~/.gitconfig&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>[delta]
side-by-side = true
&lt;/code>&lt;/pre>&lt;h3 id="bonus-color-moved">Bonus: color-moved&lt;/h3>
&lt;p>Recent versions of git (&amp;gt;= v2.17, April 2018) supports new &lt;code>--color-moved&lt;/code>
argument that will highlight lines that have been moved with a different
style than the one used with added/removed lines. &lt;code>delta&lt;/code> will automatically
decect when this feature has been enabled, and modify its output accordingly.
All you have to do is enable &lt;code>--color-moved&lt;/code> in git by default, by adding the
following to your &lt;code>~/.gitconfig&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>[diff]
colorMoved = default
&lt;/code>&lt;/pre>&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/delta-4.png" alt="">
&lt;figcaption>delta when colorMoved has been enabled in git&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>You can also customize the colors by adding:&lt;/p>
&lt;pre tabindex="0">&lt;code>[color &amp;#34;diff&amp;#34;]
oldMoved = &amp;#34;#ab9df2&amp;#34;
newMoved = &amp;#34;#ffd866&amp;#34;
&lt;/code>&lt;/pre>&lt;p>&lt;em>&lt;strong>Notes:&lt;/strong>&lt;/em> &lt;em>&lt;code>delta&lt;/code> detect &lt;code>color-moved&lt;/code> usage by reading raw colors from
git output. If it causes problem, disable this feauture in &lt;code>delta&lt;/code>&lt;/em>.&lt;/p>
&lt;pre tabindex="0">&lt;code>[delta]
inspect-raw-lines = false
&lt;/code>&lt;/pre>&lt;h2 id="dog">dog&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Homepage:&lt;/td>
&lt;td>&lt;a href="https://dns.lookup.dog/">https://dns.lookup.dog/&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repository:&lt;/td>
&lt;td>&lt;a href="https://github.com/ogham/dog">https://github.com/ogham/dog&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Written in:&lt;/td>
&lt;td>&lt;em>Rust&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repology:&lt;/td>
&lt;td>&lt;a href="https://repology.org/project/dog-dns/versions">https://repology.org/project/dog-dns/versions&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Dependencies:&lt;/td>
&lt;td>&lt;em>OpenSSL&lt;/em> (optional)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>How many of you use &lt;code>dig&lt;/code> to perform a DNS query from the terminal? And how
many of you use the newer &lt;code>drill&lt;/code> to do the same? This application is aimed
for you both!&lt;/p>
&lt;p>&lt;code>dog&lt;/code> is &lt;strong>a modern DNS client for the CLI&lt;/strong>, written by the developer of &lt;code>exa&lt;/code>.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/dog-1.png" alt="">
&lt;figcaption>dog output for example.com domain&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>It includes some cool features like emitting the output as JSON or printing
the time spent for the request.&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/dog-2.png" alt="">
&lt;figcaption>jq pretty printing dog&amp;#39;s JSON output&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/dog-3.png" alt="">
&lt;figcaption>dog printing the time spent for the request&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>It also let you choose which protocol to use between the following:&lt;/p>
&lt;ul>
&lt;li>&lt;em>DNS over UDP (default)&lt;/em>&lt;/li>
&lt;li>&lt;em>DNS over TCP&lt;/em>&lt;/li>
&lt;li>&lt;em>DNS-over-TLS&lt;/em>&lt;/li>
&lt;li>&lt;em>DNS-over-HTTPS&lt;/em>&lt;/li>
&lt;/ul>
&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/dog-4.png" alt="">
&lt;figcaption>dog printing the time spent for the request using DNS over TCP&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;h2 id="mandown">mandown&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Repository:&lt;/td>
&lt;td>&lt;a href="https://github.com/Titor8115/mandown">https://github.com/Titor8115/mandown&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Written in:&lt;/td>
&lt;td>&lt;em>C&lt;/em>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repology:&lt;/td>
&lt;td>&lt;a href="https://repology.org/project/mandown/versions">https://repology.org/project/mandown/versions&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Dependencies:&lt;/td>
&lt;td>&lt;em>ncurses&lt;/em>, &lt;em>libxml2&lt;/em>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>How many times have you came across a Markdown and had to read it as plain text?
The syntax is easy and looks good &lt;em>when rendered&lt;/em>. However, using projects like
&lt;a href="https://github.com/shime/livedown">livedown&lt;/a> just to read a 100 line Markdown file is overkill.&lt;/p>
&lt;p>&lt;code>Mandown&lt;/code> is &lt;strong>a Markdown pager for the command line&lt;/strong>.&lt;/p>
&lt;p>Let&amp;rsquo;s create a simple Markdown file to test mandown with. It will be called
&lt;code>HelloWorld.md&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-md" data-lang="md">&lt;span class="line">&lt;span class="cl">&lt;span class="gu">## Hello world!
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">I am &lt;span class="ge">_fairly_&lt;/span> simple &lt;span class="gs">**Markdown**&lt;/span> file.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">- [ ]&lt;/span> todo1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">- [x]&lt;/span> todo2
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### Credits
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Thanks to everyone reading this post :). ]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now we can use mandown to render it:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ mdn HelloWorld.md
&lt;/code>&lt;/pre>&lt;p>
&lt;figure>
&lt;img src="https://danyspin97.org/img/modern-cli-applications-1/mandown-1.png" alt="">
&lt;figcaption>mandown rendering HelloWorld.md&lt;/figcaption>
&lt;/figure>
&lt;/p>
&lt;p>As of version 1.0.1 (&lt;em>16 July 2020&lt;/em>), mandown support for the majority of
HTML tags is in development. It will work best on Markdown only files, for now.&lt;/p>
&lt;h2 id="conclusions">Conclusions&lt;/h2>
&lt;p>That&amp;rsquo;s all for this post. Did you already know any of the application
highlighted above? Do you know another alternative or application you want
to see in the next posts? Comment below!&lt;/p></description></item><item><title>Devember 2019: First ten days</title><link>https://danyspin97.org/blog/devember-2019-first-ten-days/</link><pubDate>Thu, 12 Dec 2019 23:00:00 +0100</pubDate><guid>https://danyspin97.org/blog/devember-2019-first-ten-days/</guid><description>&lt;p>After 10 long days, I’m ready to share my new journey with Dlang.&lt;/p>
&lt;h2 id="build-system">Build system&lt;/h2>
&lt;p>D documentation was really interesting and the language seemed promising.
But I needed to start somewhere and I’ve chosen to start by creating the
boilerplate files and building them; after all I want to create a &lt;strong>shared
library&lt;/strong> (&lt;em>libtt&lt;/em>) and an &lt;strong>executable linked to it&lt;/strong> (&lt;em>tt&lt;/em>). This is straightforward in C/C++ but I have no idea about D.&lt;/p>
&lt;p>Looking at the build systems with D support, there are &lt;strong>dub&lt;/strong>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>, dlang package manager shipped
alongside the compiler, and &lt;strong>meson&lt;/strong>&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup>, which has seen a huge increase in adoption over the last year, despite not having reached its 1.0 release.&lt;/p>
&lt;p>I have chosen meson, because I am already familiar and support my use case
really well. The problem was that D support for meson is really lacking and the
language itself has rarely used at a system level. I had to
discover and use some &lt;em>“hacks”&lt;/em> to properly &lt;strong>build&lt;/strong> and obtain a &lt;strong>working executable&lt;/strong>.
And this took most of my time during these first days.&lt;/p>
&lt;p>I will work more during the next weeks to improve both meson and the D compilers,
but it will require a lot of time.&lt;/p>
&lt;h2 id="parsing">Parsing&lt;/h2>
&lt;p>Back at the fun part of this Devember; one of the first thing to develop is
the &lt;strong>environment file&lt;/strong> and &lt;strong>service parser&lt;/strong>.&lt;/p>
&lt;p>For the environment file, that allows the service to be &lt;em>configurable&lt;/em>, and
the service files themself, I need a parsing library. After some search, I’ve come
across on a new one called &lt;strong>libconfini&lt;/strong>&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>. It is really &lt;strong>minimal&lt;/strong> and &lt;strong>well
documented&lt;/strong>. Now I just have to call its method from D.&lt;/p>
&lt;p>&lt;em>“Interfacing with C”&lt;/em>&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup> documentation refers to the deimos project:
d sources generated from C headers, which &lt;strong>allow D programs to use C libraries&lt;/strong>.
Creating a wrapper is straightforward thanks to &lt;strong>dstep&lt;/strong>&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup>, and the result works
out of the box flawlessy. You can see d sources to use libconfini in
&lt;strong>libconfini-d&lt;/strong>&lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>&lt;strong>Note&lt;/strong>: &lt;em>There is another way to use C libraries from D which is dpp[^10], a wrapper over the dmd compiler.&lt;/em>&lt;/p>
&lt;p>An example environment file is:&lt;/p>
&lt;pre tabindex="0">&lt;code>VERBOSITY=1
STAGE2=/etc/tt/stage2
&lt;/code>&lt;/pre>&lt;p>libconfini parsing works by defining a &lt;code>IniFormat&lt;/code>, describing what is allowed and
what not, the characters used for delimiting keys from values, and other
configuration flags. Here I have created a function to get the &lt;code>IniFormat&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-d" data-lang="d">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">confini&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">IniFormat&lt;/span> &lt;span class="nf">get_env_format&lt;/span>&lt;span class="o">()&lt;/span> &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">IniFormat&lt;/span> &lt;span class="n">env_format&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">delimiter_symbol&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">IniDelimiters&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">INI_EQUALS&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">case_sensitive&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">semicolon_marker&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">IniCommentMarker&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">INI_IGNORE&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">hash_marker&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">IniCommentMarker&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">INI_IGNORE&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">multiline_nodes&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">IniMultiline&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">INI_NO_MULTILINE&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">section_paths&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">IniSectionPaths&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">INI_NO_SECTIONS&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">no_single_quotes&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">no_double_quotes&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">no_spaces_in_names&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">env_format&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="na">implicit_is_not_empty&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="mi">1&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">env_format&lt;/span>&lt;span class="o">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Note&lt;/strong>: &lt;em>To discover more about the IniFormat and libconfini, browse its online docs&lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup> or its man pages.&lt;/em>&lt;/p>
&lt;p>To parse a file, the function &lt;code>load_ini_path&lt;/code> is used:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-c" data-lang="c">&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">int&lt;/span> &lt;span class="nf">load_ini_path&lt;/span> &lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">const&lt;/span> &lt;span class="kt">char&lt;/span> &lt;span class="o">*&lt;/span> &lt;span class="n">path&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">IniFormat&lt;/span> &lt;span class="n">format&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">IniStatsHandler&lt;/span> &lt;span class="n">f_init&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">IniDispHandler&lt;/span> &lt;span class="n">f_foreach&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kt">void&lt;/span> &lt;span class="o">*&lt;/span> &lt;span class="n">user_data&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>where &lt;code>path&lt;/code> is the path of the file, &lt;code>format&lt;/code> contains the parsing rules,
&lt;code>f_foreach&lt;/code> is a callback function that actually process the parsed key/value
pairs and &lt;code>user_data&lt;/code> is some data that is kept over the parsing.
&lt;code>f_init&lt;/code> won’t be used so let’s skip it for now.&lt;/p>
&lt;p>The problem here is that we have to pass as &lt;code>f_foreach&lt;/code> &lt;strong>a D function as a C callback&lt;/strong>, so we have to match the signature (in
D) &lt;code>extern (C) const int function(IniDispatch *, void*)&lt;/code>.&lt;/p>
&lt;p>I’ve tried using a closure and adding the tag &lt;code>extern (C)&lt;/code>, but despite my
efforts, it doesn’t work. An idea appears in my mind: what if I &lt;strong>add an alias to
this signature&lt;/strong>?&lt;/p>
&lt;pre tabindex="0">&lt;code>extern (C) alias IniCallback =
const int function(IniDispatch* dispatch, void* v_null);
&lt;/code>&lt;/pre>&lt;p>It acually compiles. Now let’s add a function that return this exact signature:&lt;/p>
&lt;pre tabindex="0">&lt;code>extern (C) IniCallback get_env_parse_callback() {
return (IniDispatch* dispatch, void* env_p) {
return 0;
};
}
&lt;/code>&lt;/pre>&lt;p>And then call &lt;code>load_ini_path&lt;/code> from our testing main:&lt;/p>
&lt;pre tabindex="0">&lt;code>import std.stdio : writeln ;
import std.string : toStringz ;
int main() {
if (load_ini_path(
toStringz(&amp;#34;/path/to/my/env&amp;#34;),
get_env_format(),
null,
get_env_parse_callback(),
null)) {
writeln(&amp;#34;Something went wrong&amp;#34;);
return 1;
}
return 0;
}
&lt;/code>&lt;/pre>&lt;p>And it works! We have been able to use the parsing library libconfini from
D code. And withouth too much of works, the result is pritty much readable.&lt;/p>
&lt;p>&lt;strong>Note&lt;/strong>: &lt;em>We use the method &lt;code>char* toStringz(string)&lt;/code> to convert a D string
into a C string.&lt;/em>&lt;/p>
&lt;p>This parsed line that we have in &lt;code>f_foreach&lt;/code> should be processed and saved
somewhere so that we can later load its values into a service environment.
The suited data structure is an &lt;strong>associative array&lt;/strong> which is also really simple to
use in D:&lt;/p>
&lt;pre tabindex="0">&lt;code>string[string] myass;
&lt;/code>&lt;/pre>&lt;p>Thouth this array can’t be directly passed to &lt;code>void* user_data&lt;/code> (I’ve done way many tests, and the cast from &lt;code>void*&lt;/code> to &lt;code>string[string]&lt;/code> always fail). So the
easiest work around is to to create a struct containing the associative array:&lt;/p>
&lt;pre tabindex="0">&lt;code>struct EnvWrapper {
string[string] hash;
}
&lt;/code>&lt;/pre>&lt;p>Now our &lt;code>main&lt;/code> become like this:&lt;/p>
&lt;pre tabindex="0">&lt;code>int main() {
EnvWrapper env;
if (load_ini_path(
toStringz(path),
get_env_format(),
null,
get_env_parse_callback(),
&amp;amp;env)) {
writeln(&amp;#34;Something went wrong&amp;#34;);
return 1;
}
return 0;
}
&lt;/code>&lt;/pre>&lt;p>And our callback:&lt;/p>
&lt;pre tabindex="0">&lt;code>extern (C) IniCallback get_env_parse_callback() {
return (IniDispatch* dispatch, void* env_p) {
ini_unquote(dispatch.data, dispatch.format);
ini_string_parse(dispatch.value, dispatch.format);
auto env = cast(EnvWrapper*)env_p;
auto key = to!string(dispatch.data);
auto val = to!string(dispatch.value);
env.hash[key] = val;
return 0;
};
}
&lt;/code>&lt;/pre>&lt;p>The functions &lt;code>ini_unquote&lt;/code> and &lt;code>ini_string_parse&lt;/code> are used to sanitize (i.e.
removing escaping chars) and removing the quotes according to the format.&lt;/p>
&lt;p>This time the conversion is the other way, from C strings to D strings using
&lt;code>to!string&lt;/code>.&lt;/p>
&lt;h3 id="conclusion">Conclusion&lt;/h3>
&lt;p>I have much fun writing this piece of code, way less fun writing the
files for the build system. I hope that this can be improved because it’s really
a shame to have such unexpressed potential.&lt;/p>
&lt;p>On the next days I’ll write the good for the service parser too, and actually
experiment with the &lt;strong>service dependencies checker&lt;/strong>, which I think will be one of
the critical parts.&lt;/p>
&lt;p>&lt;em>Stay tuned!&lt;/em>&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://github.com/dlang/dub">https://github.com/dlang/dub&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://mesonbuild.com">https://mesonbuild.com&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://github.com/madmurphy/libconfini/">https://github.com/madmurphy/libconfini/&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://dlang.org/spec/interfaceToC.html">https://dlang.org/spec/interfaceToC.html&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://github.com/jacob-carlborg/dstep">https://github.com/jacob-carlborg/dstep&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://github.com/danyspin97/libconfini-d">https://github.com/danyspin97/libconfini-d&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="https://madmurphy.github.io/libconfini/html/index.html">https://madmurphy.github.io/libconfini/html/index.html&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Devember 2019: Rewriting 66</title><link>https://danyspin97.org/blog/devember-2019-rewriting-66/</link><pubDate>Mon, 25 Nov 2019 15:15:00 +0100</pubDate><guid>https://danyspin97.org/blog/devember-2019-rewriting-66/</guid><description>&lt;p>&lt;strong>Prerequisites&lt;/strong>: &lt;em>Basic knowledge of a Unix system architecture; init diversity initiative.&lt;/em>&lt;/p>
&lt;p>&lt;em>Devember&lt;/em>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> it&amp;rsquo;s coming and for this year (which is also my first year
participating) I&amp;rsquo;ve chosen something really close to me: the init and service
manager (&lt;em>called init/rc for the rest of the post&lt;/em>). Specifically I&amp;rsquo;ve chosen to
&lt;strong>rewrite 66 from scratch&lt;/strong>.&lt;/p>
&lt;p>&lt;strong>Notes&lt;/strong>: &lt;em>In the following paragraphs there is an explanation of what led me
to rewrite 66. I was planning to explain this from some time and I&amp;rsquo;ve taken to
opportunity to do so now. If you are only interested in the program itself and
what I&amp;rsquo;ll do in this Devember, skip to &lt;a href="#tt">development&lt;/a>.&lt;/em>&lt;/p>
&lt;h2 id="why">Why?&lt;/h2>
&lt;p>Regardless of whatever “sytemd sucks”&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup>&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup> or not, I want to have an
alternative to it. I want to be able to have at least some choiches for what
runs on my system, especially when we talk about critic programs such as &lt;strong>PID
1&lt;/strong> and the service manager.&lt;/p>
&lt;p>The alternatives currently availables (&lt;em>OpenRC&lt;/em>, &lt;em>runit&lt;/em>) do not offer the
advantages of &lt;em>systemd&lt;/em> or have some big disadvantage that do not make their use
straightforward. This does not involve the design (which have been already
covered in deep by &lt;em>skarnet&lt;/em> here&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>) but only usability. Yup, I am really
picky regarding the programs to use.&lt;/p>
&lt;h2 id="s6s6-rc">s6/s6-rc&lt;/h2>
&lt;p>At the start of the 2018 I&amp;rsquo;ve learnt about s6 suite&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup> and s6-rc&lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>. I wanted
to try them on my newly installed &lt;em>Exherbo Linux&lt;/em> system, so I have adapted the
example services to run on my machine. Thanks to the help of the &lt;strong>#s6&lt;/strong>
official IRC channel the system finally run s6/s6-rc and it was &lt;em>great&lt;/em>; at boot
it started all the services asynchronously and showed a working tty in the blink
of an eye.&lt;/p>
&lt;p>I&amp;rsquo;ve liked it so much that I stared contributing to the integration of s6 into
exherbo. It consisted in &lt;strong>s6-rc services for the various packages and a sane
set of starting scripts&lt;/strong> to have a working system (called &lt;em>s6-exherbo&lt;/em>&lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup>).
My small VPS I configured at the time even got s6 on it.&lt;/p>
&lt;p>With the time passing I&amp;rsquo;ve found the &lt;strong>service writing and administration&lt;/strong> to
be really &lt;strong>time consuming&lt;/strong>. And that&amp;rsquo;s because it has not a user friendly
interface, thus it was not made for what me (and some other users) were using
it. And here it comes &lt;em>s6-frontend&lt;/em>, the user interface not written yet. Skarnet
has recently confirmed that he will write it in the 2021 so it won&amp;rsquo;t be ready
any time soon.&lt;/p>
&lt;h2 id="66">66&lt;/h2>
&lt;p>Exherbo was not the only distribution adopting s6 and and among the other ones
there was &lt;strong>obarun&lt;/strong>&lt;sup id="fnref:8">&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref">8&lt;/a>&lt;/sup>, developed by the omonimus creator as a fork of Arch
Linux. He, too, wrote a lot of wrapper scripts to ease the use of the s6 suite,
but in the end he resorted to writing his own frontend, called &lt;strong>66&lt;/strong>&lt;sup id="fnref:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>.
Obarun (&lt;em>the distribution&lt;/em>) was converted for 66 as soon as a working release got out.&lt;/p>
&lt;p>On the other hand there was me who became an early adopter the moment I looked
at the documentation&lt;sup id="fnref1:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>: &lt;strong>it simply resolves almost all my issues of s6/s6-rc&lt;/strong> without any major disadvantage. It is &lt;strong>easy to use&lt;/strong>, &lt;strong>powerful&lt;/strong> and &lt;strong>extensible&lt;/strong>.&lt;/p>
&lt;p>So far, s6-exherbo got immediately forked into &lt;em>66-exherbo&lt;/em>&lt;sup id="fnref:10">&lt;a href="#fn:10" class="footnote-ref" role="doc-noteref">10&lt;/a>&lt;/sup> and the old services converted to the new frontend format. Devuan too got his own
&lt;em>66-devuan&lt;/em>&lt;sup id="fnref:11">&lt;a href="#fn:11" class="footnote-ref" role="doc-noteref">11&lt;/a>&lt;/sup>, which took me more than it should have had. If you are curious
about the reason, 66&amp;rsquo;s developer did not want to support FHS&lt;sup id="fnref:12">&lt;a href="#fn:12" class="footnote-ref" role="doc-noteref">12&lt;/a>&lt;/sup> in his general
set of starting scripts, because he did not like this standard. In the end he
accepted my patches and &lt;strong>Devuan booted using 66&lt;/strong>.&lt;/p>
&lt;p>Service enabling on Exherbo with system version of 66 suffered from a bug
(&lt;em>Hello SIGSEGV, long time no see&lt;/em>) and it was unusable; to make the matter
worse, the bug could not be reproduced with a local copy. The developer had
something else on his schedule (writing a new command-line arguments parser,
apparently) and did not want to fix the bug. “&lt;strong>I can fix it myself&lt;/strong>”, I
thought: &lt;em>I was wrong&lt;/em>.&lt;/p>
&lt;p>66 codebase consists of &lt;strong>16000 lines with little to no comments&lt;/strong>, and it makes
heavy use of skalibs&lt;sup id="fnref:13">&lt;a href="#fn:13" class="footnote-ref" role="doc-noteref">13&lt;/a>&lt;/sup> and oblibs&lt;sup id="fnref:14">&lt;a href="#fn:14" class="footnote-ref" role="doc-noteref">14&lt;/a>&lt;/sup> libraries, greatly lowering the
readability (I&amp;rsquo;d like to say it is written in &lt;em>skarnet&amp;rsquo;s C&lt;/em>). Downgrade wasn&amp;rsquo;t
an option neither due to a breaking change in services and the various services
in Exherbo already got updated. I could not find the bug, I could not enable new
services and the developer did not care to fix this fatal bug. Devuan too was
failing to build 66. &lt;strong>There was enough reasons for me to fork the project&lt;/strong> and
improve it, adding unit testing and have better code quality.&lt;/p>
&lt;p>Now that I had the possibility, I could also &lt;strong>rewrite it from scratch&lt;/strong>, picking different choiches from the start and &lt;em>avoiding the legacy code&lt;/em>.&lt;/p>
&lt;p>&lt;strong>Note&lt;/strong>: &lt;em>I really like 66 project but it simply isn’t what I am searching for.
I wish the best to obarun with both 66 and his distribution, for which he have
worked years trying to offer a valid systemd and Arch Linux alternative&lt;/em>.&lt;/p>
&lt;h2 id="tt">tt&lt;/h2>
&lt;p>&lt;strong>tt&lt;/strong> (which should have been 77 or t7 but I don&amp;rsquo;t like numbers in binaries
names, if not strictly necessaries) is a wrapper, or better, &lt;strong>a frontend to
s6/s6-rc&lt;/strong>.&lt;/p>
&lt;p>A bit about its development:&lt;/p>
&lt;dl>
&lt;dt>Written in &lt;strong>D&lt;/strong>&lt;/dt>
&lt;dd>
&lt;p>The suited languages for such a project are &lt;code>C&lt;/code>, &lt;code>C++&lt;/code>, &lt;code>Rust&lt;/code> and &lt;code>D&lt;/code>. &lt;em>C&lt;/em> is
the fastest if used correctly; but it&amp;rsquo;s really hard to get right and requires
developers to rewrite a lot of stuff (or use libs like glib or skalibs). &lt;em>C++&lt;/em>
is hard and share some problem with &lt;em>C&lt;/em>, I prefer to not use if I have a
choiche. &lt;em>Rust&lt;/em> has a microdependency ecosystem and it is hard to use C
libraries as well as exposing C bindings. On the other hand, &lt;em>D&lt;/em> seems suited
for such a project: it is &lt;strong>safer than C&lt;/strong>, &lt;strong>has a GC&lt;/strong>, and it is relatively
&lt;strong>fast to write&lt;/strong>, while keeping a good performance and high flexibility.&lt;/p>
&lt;/dd>
&lt;dt>Use C or C++ libs&lt;/dt>
&lt;dd>
&lt;p>D community is not very active, so many libraries have been abandoned and the
maintained ones could still have the same ending in the future. To avoid such a
possibility, &lt;strong>I have chosen to only use C/C++ libraries&lt;/strong> (way more &lt;em>tested&lt;/em>
and &lt;em>actively maintained&lt;/em>), since Dlang makes them easy to use.&lt;/p>
&lt;/dd>
&lt;dt>Provide external C bindings&lt;/dt>
&lt;dd>
&lt;p>tt will have a library and a command-line interface. In the long-term there
could be additional command lines interfaces, plugins or GUI programs to
administrate the system from; it is important for me to &lt;strong>expose a C interface
so that any language could be used&lt;/strong> (after all almost every language permits
to call C functions).&lt;/p>
&lt;/dd>
&lt;dt>Try to not reinvent the wheel&lt;/dt>
&lt;dd>
&lt;p>To get a working service manager as soon as possible, &lt;strong>complex tasks will be
achieved using external libraries&lt;/strong> (like parsing the &lt;em>services files&lt;/em>).
Reinventing the wheel is good for learning purposes, but increase the
development and testing time too much for my tastes. Therefore I will try to
keep it to a minimum.&lt;/p>
&lt;/dd>
&lt;dt>Features&lt;/dt>
&lt;dd>
&lt;p>These are 66&lt;sup id="fnref2:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>’s features, which &lt;strong>tt&lt;/strong> will keep closely to.&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;blockquote>
&lt;ul>
&lt;li>Frontend service files declaration.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;ul>
&lt;li>Backup a complete set of services.&lt;/li>
&lt;li>Easy creation of a scandir.&lt;/li>
&lt;li>Nested supervision tree.&lt;/li>
&lt;li>Instance service file creation.&lt;/li>
&lt;li>Multiple directories service file declaration(packager,sysadmin,user).&lt;/li>
&lt;li>Easy change of service configuration.&lt;/li>
&lt;li>Automatic logger creation.&lt;/li>
&lt;/ul>
&lt;dl>
&lt;dt>Sane defaults&lt;/dt>
&lt;dd>
&lt;p>The most important thing is to &lt;strong>make the pc boot, whatever the conditions&lt;/strong>.
The users and the distribution maintainers should do the least work possible.
Providing sane defaults and sane fallback helps in this matter. For example
&lt;code>stage1&lt;/code> should work regardless if the initramfs has been used or not (and &lt;em>this
didn’t happen in 66 until recently&lt;/em>).&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;p>About the libaries used, I have to try them so I’ll problably post more details in the next weeks.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://devember.org/">https://devember.org/&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://skarnet.org/software/systemd.html">https://skarnet.org/software/systemd.html&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://suckless.org/sucks/systemd/">https://suckless.org/sucks/systemd/&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://skarnet.org/software/s6/why.html">https://skarnet.org/software/s6/why.html&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://skarnet.org/software/s6/">https://skarnet.org/software/s6/&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://skarnet.org/software/s6-rc/">https://skarnet.org/software/s6-rc/&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="https://gitlab.exherbo.org/exherbo-misc/s6-exherbo">https://gitlab.exherbo.org/exherbo-misc/s6-exherbo&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:8">
&lt;p>&lt;a href="https://web.obarun.org/">https://web.obarun.org/&lt;/a>&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:9">
&lt;p>&lt;a href="https://web.obarun.org/software/66/">https://web.obarun.org/software/66/&lt;/a>&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref2:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:10">
&lt;p>&lt;a href="https://gitlab.exherbo.org/exherbo-misc/66-exherbo">https://gitlab.exherbo.org/exherbo-misc/66-exherbo&lt;/a>&amp;#160;&lt;a href="#fnref:10" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:11">
&lt;p>&lt;a href="https://git.devuan.org/66-devuan">https://git.devuan.org/66-devuan&lt;/a>&amp;#160;&lt;a href="#fnref:11" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:12">
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard">https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard&lt;/a>&amp;#160;&lt;a href="#fnref:12" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:13">
&lt;p>&lt;a href="https://skarnet.org/software/skalibs/">https://skarnet.org/software/skalibs/&lt;/a>&amp;#160;&lt;a href="#fnref:13" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:14">
&lt;p>&lt;a href="https://framagit.org/obarun/oblibs">https://framagit.org/obarun/oblibs&lt;/a>&amp;#160;&lt;a href="#fnref:14" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Security and privacy on UNIX desktop</title><link>https://danyspin97.org/blog/security-and-privacy-on-unix-desktop/</link><pubDate>Tue, 13 Aug 2019 16:30:00 +0200</pubDate><guid>https://danyspin97.org/blog/security-and-privacy-on-unix-desktop/</guid><description>&lt;p>Security and privacy are two important factors of the IT field. A lot of effort
has been made to ensure safe surfing on the net, whatever we are connected to
our home router, the university network or even worse the airport public
network. And other effort have been made to avoid malicious sites.&lt;/p>
&lt;p>Yet, systems don&amp;rsquo;t offer privacy and security out of the box.
This post will guide you to the installation of some tools that will improve
your security, privacy and performance on a UNIX system.&lt;/p>
&lt;h2 id="hblock-1">hblock &lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>The first thing suggested in every post about security and privacy is to
install web browser extensions to block ads and malicous sites.&lt;/p>
&lt;p>What if instead we could block requests at a system level? We can map every
site we want to avoid with the address &lt;code>0.0.0.0&lt;/code> in &lt;code>/etc/hosts&lt;/code>: every time
the browser or &lt;em>any&lt;/em> application on the system request one of these sites, the
above address will be used, aborting the connection.&lt;/p>
&lt;dl>
&lt;dt>Little explanation about how this works:&lt;/dt>
&lt;dd>
&lt;p>The domain names, such as &lt;code>www.example.com&lt;/code>, have to be translated into
internet addresses and it&amp;rsquo;s the nameserver (or &lt;strong>DNS&lt;/strong> server) responsability
to do so. &lt;code>/etc/hosts&lt;/code> is a file that maps domains to addresses without calling
the nameserver: adding &lt;code>8.8.8.8 dns.google.com&lt;/code> will map &lt;code>dns.google.com&lt;/code> to
the address &lt;code>8.8.8.8&lt;/code>.&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;p>So far, so good. But do we have to add every site by hand? &lt;code>hblock&lt;/code> is a little
script that will do so for us. It collect malicious sites from different sources
&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> and write them to &lt;code>/etc/hosts&lt;/code>.&lt;/p>
&lt;p>To install, run make install as root inside the repository:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ git clone https://github.com/hectorm/hblock.git
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ &lt;span class="nb">cd&lt;/span> hblock
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ sudo make install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now, to run the program just call &lt;code>hblock&lt;/code>.&lt;/p>
&lt;p>If your system is powered by systemd, you can enable &lt;code>hblock&lt;/code> timer so that
&lt;code>/etc/hosts&lt;/code> will be updated daily.&lt;/p>
&lt;p>Its site &lt;sup id="fnref1:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> also have auto-generated files for different programs (including
one that will be introduced later in this post) if you don&amp;rsquo;t want to download
and install the script.&lt;/p>
&lt;h2 id="stubby-6">stubby &lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>The nameserver itself is a source of attack and privacy leaks. The DNS
protocol, which has been originally specified in 1983 &lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>, transmit domain
name queries in clear text. It also means that everyone can snoop this data
and collect information about &lt;em>which&lt;/em> sites you have visited. Also, queries are
not verified. For more information, checkout “&lt;em>Why is DNS a privacy concern?&lt;/em> ”
&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>DNSSEC &lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup> is the solution to make DNS more secure but it does not improve
privacy and is not enabled by default.&lt;/p>
&lt;p>Further attempts have been made and are still in progress to improve DNS.
The most important ones &lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup> are:&lt;/p>
&lt;ul>
&lt;li>dnscrypt-proxy &lt;sup id="fnref:8">&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref">8&lt;/a>&lt;/sup>&lt;/li>
&lt;li>DNS Over TLS (&lt;em>DoT&lt;/em>)&lt;/li>
&lt;li>DNS Over HTTPS (&lt;em>DoH&lt;/em>)&lt;/li>
&lt;/ul>
&lt;p>In this post, we will use &lt;em>DoT&lt;/em> as it is a standardized protocol with working
implementations &lt;sup id="fnref:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup> and Stubby, a stub resolver.&lt;/p>
&lt;p>Install stubby using the package manager. The default configuration will be
installed into &lt;code>/etc/stubby/stubby.yml&lt;/code> and it contains sane values; the only
thing we need to change is the port stubby listens to:&lt;/p>
&lt;pre tabindex="0">&lt;code>listen_addresses:
- 127.0.0.1@53000
- 0::1@53000
&lt;/code>&lt;/pre>&lt;p>Make sure that &lt;code>listen_addresses&lt;/code> config matches the above snippet.&lt;/p>
&lt;p>The nameserver used are hard-coded into the config; to enable/disable them,
comment the relevant lines.&lt;/p>
&lt;p>Run stubby using systemd service or the service manager installed currently
installed on your system.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ systemctl &lt;span class="nb">enable&lt;/span> stubby
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ systemctl start stubby
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>At this point we have a stub resolver listening on localhost, port 53000.
However, each query can take from 200ms to 500ms to be resolved, whereas DNS in
clear text usually takes only ~50ms. That&amp;rsquo;s a huge slowdown; in the next
section we will partially avoid all this overhead by using &lt;code>dnsmasq&lt;/code>, a local
server used to cache DNS queries.&lt;/p>
&lt;p>&lt;strong>Note:&lt;/strong> &lt;em>One caveat of stubby currently is the RAM usage, which can go up to
200MB.&lt;/em>&lt;/p>
&lt;h2 id="dnsmasq-10">dnsmasq &lt;sup id="fnref1:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>dnsmasq is both a DHCP and a DNS server; we will only enable the DNS server
capability so that it can be used as a local cache server.&lt;/p>
&lt;p>Ensure that the configuration located at &lt;code>/etc/dnsmasq.conf&lt;/code> contains the
following values:&lt;/p>
&lt;pre tabindex="0">&lt;code># Do not forward plain names
domain-needed
# Do not forward invalid address spaces
bogus-priv
# Do not use /etc/resolv file
no-resolv
# Point the nameserver to stubby
server=::1#53000
server=127.0.0.1#53000
# Listen only on the loopback address
listen-address=::1,127.0.0.1
# Disable DHCP server capabilities
no-dhcp-interface
# Increase the cache size
cache-size=1000
&lt;/code>&lt;/pre>&lt;p>Start dnsmasq with systemd or any other service manager:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ systemctl &lt;span class="nb">enable&lt;/span> dnsmasq
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">$ systemctl start dnsmasq
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now, to make the system use dnsmasq, the file &lt;code>/etc/resolv.conf&lt;/code> (which
contains the list of the nameserver addresses currently known) must be
exactly as this:&lt;/p>
&lt;pre tabindex="0">&lt;code>nameserver 127.0.0.1
&lt;/code>&lt;/pre>&lt;p>&lt;em>&lt;strong>Note:&lt;/strong>&lt;/em> &lt;em>If no port is specified, as in the above snippet, the default port
53 will be used&lt;/em>.&lt;/p>
&lt;p>However, some network managers (like &lt;em>NetworkManager&lt;/em>) rewrite
&lt;code>/etc/resolv.conf&lt;/code>, overwriting our choice to use dnsmasq. In this case
&lt;em>openresolve&lt;/em> &lt;sup id="fnref:10">&lt;a href="#fn:10" class="footnote-ref" role="doc-noteref">10&lt;/a>&lt;/sup> must be used: write the following into the file
&lt;code>/etc/resolvconf.conf&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code># Use the local name server
name_servers=&amp;#34;::1 127.0.0.1&amp;#34;
&lt;/code>&lt;/pre>&lt;p>and then run:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ sudo resolvconf -u
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>How does this work? dnsmasq will be used as the default nameserver, dispatching
every DNS query to stubby. Every query resolved will be cached locally, so that
the next time dnsmasq will already have the response. The time to translate
a specific domain name to an internet address (&lt;em>IP&lt;/em>) will be high for the first
query (when stubby actually ask a remote nameserver) and instant for the
later ones.&lt;/p>
&lt;p>To test if it is working as intended run &lt;code>drill&lt;/code> (usually contained in a
&lt;code>ldns-utils&lt;/code> package if it is not already installed):&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ drill exherbo.org
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> -&amp;gt;&amp;gt;HEADER&lt;span class="s">&amp;lt;&amp;lt;- opco&lt;/span>de: QUERY, rcode: NOERROR, id: xxxxx
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> flags: qr rd ra &lt;span class="p">;&lt;/span> QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: &lt;span class="m">0&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> QUESTION SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> exherbo.org. IN A
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> ANSWER SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">exherbo.org. 360 IN A 185.38.172.64
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> AUTHORITY SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> ADDITIONAL SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> Query time: &lt;span class="m">321&lt;/span> msec
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> EDNS: version 0&lt;span class="p">;&lt;/span> flags: &lt;span class="p">;&lt;/span> udp: &lt;span class="m">4096&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> SERVER: 127.0.0.1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> WHEN: Sun Aug &lt;span class="m">11&lt;/span> 18:25:59 &lt;span class="m">2019&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> MSG SIZE rcvd: &lt;span class="m">67&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;code>SERVER&lt;/code> used is indeed dnsmasq (listening on &lt;code>localhost&lt;/code> or &lt;code>127.0.0.1&lt;/code>)
and stubby is being used accordingly to the high value of the query time.&lt;/p>
&lt;p>Let&amp;rsquo;s call it again to test dnsmasq cache:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">$ drill exherbo.org
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> -&amp;gt;&amp;gt;HEADER&lt;span class="s">&amp;lt;&amp;lt;- opco&lt;/span>de: QUERY, rcode: NOERROR, id: &lt;span class="m">23991&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> flags: qr rd ra &lt;span class="p">;&lt;/span> QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: &lt;span class="m">0&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> QUESTION SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> exherbo.org. IN A
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> ANSWER SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">exherbo.org. 340 IN A 185.38.172.64
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> AUTHORITY SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> ADDITIONAL SECTION:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> Query time: &lt;span class="m">0&lt;/span> msec
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> SERVER: 127.0.0.1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> WHEN: Sun Aug &lt;span class="m">11&lt;/span> 18:26:20 &lt;span class="m">2019&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">;;&lt;/span> MSG SIZE rcvd: &lt;span class="m">45&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>As you can see, the query time this time is 0 millisecond; the cache is indeed
working!&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>For this post is all, folks! If you know any software or suggestion you would
like to see in this guide, just write me an email or send a Pull Request to
this repository &lt;sup id="fnref:11">&lt;a href="#fn:11" class="footnote-ref" role="doc-noteref">11&lt;/a>&lt;/sup>!&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://hblock.molinero.dev/">https://hblock.molinero.dev/&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://github.com/hectorm/hblock#sources">https://github.com/hectorm/hblock#sources&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Daemon+-+Stubby">https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Daemon+-+Stubby&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/Domain_Name_System#cite_note-19">https://en.wikipedia.org/wiki/Domain_Name_System#cite_note-19&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+-+The+Problem">https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+-+The+Problem&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://www.dnssec.net/">https://www.dnssec.net/&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+-+The+Solutions">https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+-+The+Solutions&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:8">
&lt;p>&lt;a href="https://dnscrypt.info/">https://dnscrypt.info/&lt;/a>&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:9">
&lt;p>&lt;a href="http://www.thekelleys.org.uk/dnsmasq/doc.html">http://www.thekelleys.org.uk/dnsmasq/doc.html&lt;/a>&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:10">
&lt;p>&lt;a href="https://wiki.archlinux.org/index.php/Openresolv">https://wiki.archlinux.org/index.php/Openresolv&lt;/a>&amp;#160;&lt;a href="#fnref:10" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:11">
&lt;p>&lt;a href="https://github.com/danyspin97/danyspin97-site">https://github.com/danyspin97/danyspin97-site&lt;/a>&amp;#160;&lt;a href="#fnref:11" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Web Browsers and Privacy in 2019</title><link>https://danyspin97.org/blog/web-browsers-and-privacy-in-2019/</link><pubDate>Thu, 24 Jan 2019 21:50:07 +0100</pubDate><guid>https://danyspin97.org/blog/web-browsers-and-privacy-in-2019/</guid><description>&lt;p>An important piece in everyday life is the &lt;strong>browser&lt;/strong>, considering the new trend of storing data and accessing applications in the &lt;em>cloud&lt;/em>.&lt;/p>
&lt;p>Among the browsers landscape, the choice is actually finite because developing and maintaining one is &lt;em>expensive&lt;/em>. But, which browser should you choose? One that offers &lt;strong>speed&lt;/strong> or one that is &lt;strong>secure&lt;/strong>? Does it respect your &lt;strong>privacy&lt;/strong>?&lt;/p>
&lt;p>In the current post, we will showcase browsers with a user-friendly GUI which both &lt;em>novices&lt;/em> and &lt;em>experts&lt;/em> can use. Firefox and Google Chrome will be highlighted as well as their forks and brand new browsers; attenction is paid to the consumer privacy.&lt;/p>
&lt;p>&lt;em>&lt;strong>Prerequisistes&lt;/strong>&lt;/em>: &lt;em>None. Both beginners and advanced users can enjoy this post; it tries to explain every technology that is needed to discuss the various browsers&lt;/em> and their differences.&lt;/p>
&lt;p>
&lt;img src="https://upload.wikimedia.org/wikipedia/commons/e/e1/StatCounter-browser-ww-monthly-201707-201707-map.png" alt="">
&lt;em>Browser Market Share Worldwide 2017&lt;/em>&lt;/p>
&lt;h2 id="google-chrome-1">Google Chrome &lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>&lt;em>Google Chrome&lt;/em> has been the most used browsers in the last year with a wide gap from the other alternatives. Why? Because rendering a page is really fast and it is integrated with Google services.&lt;/p>
&lt;p>But it’s a Google application, you can’t expect that it will respect your privacy; settings don’t help either. And it isn’t an open soure browser.&lt;/p>
&lt;h3 id="chromium-2">Chromium &lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>The rendering engine (the part that reads the HTML page and prints the formatted output) of Google Chrome is called &lt;em>Chromium&lt;/em> and is also distributed as a separate browser. It’s basically Google Chrome minus &lt;em>some&lt;/em> extensions and plugins. Privacy is a little better but it’s still &lt;em>Googlish&lt;/em>.&lt;/p>
&lt;h4 id="iridium-32">Iridium &lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>&lt;/h4>
&lt;p>Here we are at the first privacy-aware browser: &lt;em>Iridium&lt;/em>, a fork of Chromium, private and secure by default. The project has been released recently, but it seems already &lt;strong>abandoned&lt;/strong>: the latest commit to its codebase is dated in November 2018. No fixes or security update since then.&lt;/p>
&lt;h4 id="ungoogled-chromium-3">ungoogled-chromium &lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>&lt;/h4>
&lt;p>&lt;em>ungoogled-chromium&lt;/em>, is a fork of chromium with privacy improvements where Google traces have been removed. It is a &lt;strong>drop-in replacement&lt;/strong> so you can download the browser and start using the same interface you’re used to.&lt;/p>
&lt;p>&lt;em>Download!&lt;/em>&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup>&lt;/p>
&lt;h2 id="mozilla-firefox-5">Mozilla Firefox &lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>Another pillar of privacy-aware browsers is &lt;em>Mozilla Firefox&lt;/em>. It is fast (especially with the new Quantum engine&lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup>) and easy to use. The only problem is that Mozilla often makes &lt;strong>opinionated choices&lt;/strong> &lt;sup id="fnref:8">&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref">8&lt;/a>&lt;/sup>&lt;sup id="fnref:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>. But Firefox is open source and it would be a huge loss to waste its code; this is why we will overview some of its forks.&lt;/p>
&lt;p>It’s important to state that Firefox isn’t privacy-aware by default, but the opt-out and relevant settings are just few clicks away, and all the sneaky extensions enabled by default (like Mr. Robot extensions&lt;sup id="fnref1:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup>) can be disabled.&lt;/p>
&lt;p>If you still want to use Firefox, follow PrivacyToolsIO guide&lt;sup id="fnref:10">&lt;a href="#fn:10" class="footnote-ref" role="doc-noteref">10&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>&lt;em>Download!&lt;/em>&lt;sup id="fnref1:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>&lt;/p>
&lt;h3 id="basilisk-12">Basilisk &lt;sup id="fnref:11">&lt;a href="#fn:11" class="footnote-ref" role="doc-noteref">11&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>
&lt;img src="https://www.basilisk-browser.org/bas-logo-300w.png" alt="">
&lt;/p>
&lt;p>&lt;em>Basilisk&lt;/em> is a Firefox fork made right before the Quantum update&lt;sup id="fnref1:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup> to demonstrate the Unified XUL Platform&lt;sup id="fnref:12">&lt;a href="#fn:12" class="footnote-ref" role="doc-noteref">12&lt;/a>&lt;/sup>&lt;sup id="fnref:13">&lt;a href="#fn:13" class="footnote-ref" role="doc-noteref">13&lt;/a>&lt;/sup>. But what is XUL&lt;sup id="fnref:14">&lt;a href="#fn:14" class="footnote-ref" role="doc-noteref">14&lt;/a>&lt;/sup>&lt;sup id="fnref:15">&lt;a href="#fn:15" class="footnote-ref" role="doc-noteref">15&lt;/a>&lt;/sup> and why should you care about?&lt;/p>
&lt;blockquote>
&lt;p>XUL (XML User Interface Language) is Mozilla&amp;rsquo;s XML-based language for building user interfaces of applications like Firefox.&lt;/p>
&lt;/blockquote>
&lt;p>It is a subset of XML made for creating add ons that change Firefox user interface; Mozilla deprecated XUL-based add ons at the end of the 2017&lt;sup id="fnref:16">&lt;a href="#fn:16" class="footnote-ref" role="doc-noteref">16&lt;/a>&lt;/sup>. Basilisk developers still believe in a future of this technology and want to improve it.&lt;/p>
&lt;p>The rendering engine it’s called &lt;em>Goanna&lt;/em>&lt;sup id="fnref:17">&lt;a href="#fn:17" class="footnote-ref" role="doc-noteref">17&lt;/a>&lt;/sup> and it’s a fork from an old version of Firefox (v25) that have diverged significantly over the years.&lt;/p>
&lt;p>The project seems interesting, but after a bit of digging, I’ve found this issue&lt;sup id="fnref:18">&lt;a href="#fn:18" class="footnote-ref" role="doc-noteref">18&lt;/a>&lt;/sup> in the OpenBSD work in progress ports tree. Basilisk developers (they also develop Pale Moon&lt;sup id="fnref:19">&lt;a href="#fn:19" class="footnote-ref" role="doc-noteref">19&lt;/a>&lt;/sup>) opened it to make the port comply with the licence, and the terms used are not polite at all. Package and ports maintainers are often volunteers so there is no point in making such an approach for whatever reason. Because of this, Basilisk developers don’t seem to &lt;strong>deserve the users’ trust&lt;/strong>, I suggest to use some more trustworthy project instead.&lt;/p>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>&lt;/em>: &lt;em>A OpenBSD port is a set of files (Makefiles) that describes where to fetch the source of a software and how to compile/install it. The pre-compiled binaries offered by OpenBSD are built using the ports&lt;/em>.&lt;/p>
&lt;h3 id="gnu-icecat-9">GNU Icecat &lt;sup id="fnref:20">&lt;a href="#fn:20" class="footnote-ref" role="doc-noteref">20&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>
&lt;img src="https://www.gnu.org/software/gnuzilla/icecat-128.png" alt="">
&lt;/p>
&lt;p>&lt;em>Icecat&lt;/em> browser targets people who care about their privacy but &lt;strong>code freedom&lt;/strong> too. It is based on Firefox ESR (Extended Support Release) and consists in a set of patches that remove all non-free code and enhance privacy.&lt;/p>
&lt;p>Some security extensions like LibreJS&lt;sup id="fnref:21">&lt;a href="#fn:21" class="footnote-ref" role="doc-noteref">21&lt;/a>&lt;/sup> and Searxes’ Third-party Request Blocker&lt;sup id="fnref:22">&lt;a href="#fn:22" class="footnote-ref" role="doc-noteref">22&lt;/a>&lt;/sup> are shipped with Icecat but they can be disabled with a click in the homepage, restoring the usual surfing experience (these two extensions break many sites).&lt;/p>
&lt;p>In a fancy GNU style, Icecat allows a limited set of extensions, the free ones; indeed Stallman wouldn’t approve non-free extensions!&lt;/p>
&lt;p>Download version &lt;em>60.3.0&lt;/em>!&lt;sup id="fnref:23">&lt;a href="#fn:23" class="footnote-ref" role="doc-noteref">23&lt;/a>&lt;/sup> (File: icecat-60.3.0.en-US.gnulinux-x86_64.tar.bz2)&lt;/p>
&lt;h3 id="librefox-24">Librefox &lt;sup id="fnref:24">&lt;a href="#fn:24" class="footnote-ref" role="doc-noteref">24&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>
&lt;img src="https://raw.githubusercontent.com/intika/Librefox/master/capture.png" alt="">
&lt;/p>
&lt;p>As strange as it sounds, &lt;em>Librefox&lt;/em> is not a fork. It instead consists in a bunch of configuration files applied to vanilla Firefox. Privacy extensions and sane settings are shipped with it, unneeded features are removed (like crash reporter and updater). An optional Dark theme&lt;sup id="fnref:25">&lt;a href="#fn:25" class="footnote-ref" role="doc-noteref">25&lt;/a>&lt;/sup> crafted by Librefox team is available.&lt;/p>
&lt;p>The first version of Librefox has been relased in November 2018, so it’s a pretty new and interesting project. As of January 2019, Librefox distributes the configurations files that need to be &lt;strong>applied manually&lt;/strong> to vanilla Firefox, by unpacking them in the installation directory. Developers stated that a complete build is planned&lt;sup id="fnref:26">&lt;a href="#fn:26" class="footnote-ref" role="doc-noteref">26&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>&lt;em>Download!&lt;/em>&lt;sup id="fnref:27">&lt;a href="#fn:27" class="footnote-ref" role="doc-noteref">27&lt;/a>&lt;/sup>&lt;/p>
&lt;h3 id="pale-moon-23">Pale Moon &lt;sup id="fnref:28">&lt;a href="#fn:28" class="footnote-ref" role="doc-noteref">28&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>&lt;em>Pale Moon&lt;/em> is a fork of Firefox dated back in the 2009. It supports XUL and offers the old Firefox UI. The rendering engine is the same of Basilisk so they are almost the same in terms of speed.&lt;/p>
&lt;p>For &lt;strong>reason stated above&lt;/strong> about its developers, I suggest using other more trustworthy alternatives.&lt;/p>
&lt;h3 id="waterfox-27">Waterfox &lt;sup id="fnref:29">&lt;a href="#fn:29" class="footnote-ref" role="doc-noteref">29&lt;/a>&lt;/sup>&lt;/h3>
&lt;p>&lt;em>Waterfox&lt;/em>’s philosophy is close to Librefox, but dates back in the 2011; it has a dedicated website with all the relative informations and the full build download.&lt;/p>
&lt;p>It allows the installation of every plugin (unlike Icecat) but its &lt;strong>version lags behind&lt;/strong>: at the time of writing the last release is 56.2.6, while Firefox latest stable release is 64.0.2.&lt;/p>
&lt;p>&lt;em>Download!&lt;/em>&lt;sup id="fnref:30">&lt;a href="#fn:30" class="footnote-ref" role="doc-noteref">30&lt;/a>&lt;/sup>&lt;/p>
&lt;h2 id="dooble-38">Dooble &lt;sup id="fnref:31">&lt;a href="#fn:31" class="footnote-ref" role="doc-noteref">31&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>
&lt;img src="https://textbrowser.github.io/dooble/images/dooble.png" alt="">
&lt;/p>
&lt;p>&lt;em>Dooble&lt;/em> is a Qt browser written with privacy in mind that uses QtWebEngine (Chromium integration in Qt libraries).&lt;/p>
&lt;p>&lt;em>Download!&lt;/em>&lt;sup id="fnref:32">&lt;a href="#fn:32" class="footnote-ref" role="doc-noteref">32&lt;/a>&lt;/sup>&lt;/p>
&lt;h2 id="falkon-31">Falkon &lt;sup id="fnref:33">&lt;a href="#fn:33" class="footnote-ref" role="doc-noteref">33&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>
&lt;img src="https://www.falkon.org/images/screenshot.png" alt="">
&lt;/p>
&lt;p>&lt;em>Falkon&lt;/em>, which changed name in the latest release, is the former &lt;em>Qupzilla&lt;/em>, a Qt based browser made by KDE; it uses QtWebEngine.&lt;/p>
&lt;p>&lt;em>Download!&lt;/em> &lt;sup id="fnref1:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>&lt;/p>
&lt;h2 id="gnome-web-29">GNOME Web &lt;sup id="fnref:34">&lt;a href="#fn:34" class="footnote-ref" role="doc-noteref">34&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>
&lt;img src="https://wiki.gnome.org/Apps/Web?action=AttachFile&amp;amp;do=get&amp;amp;target=epiphany-3-24.jpg" alt="">
&lt;/p>
&lt;p>&lt;em>GNOME Web&lt;/em>, formerly known as &lt;em>Ephiphany&lt;/em>, is the browser of choice for GNOME desktop and Elementary OS. It features a clean interface (which pair perfectly with the above desktops) and uses Webkit&lt;sup id="fnref:35">&lt;a href="#fn:35" class="footnote-ref" role="doc-noteref">35&lt;/a>&lt;/sup> (Apple open-source browser engine). The latter is also its biggest flaw: &lt;strong>Webkit is slower&lt;/strong> than its competitors (both Firefox browser engine and Chromium).&lt;/p>
&lt;p>Another worth mentioning feature is the desktop integration with GNOME:&lt;/p>
&lt;p>
&lt;img src="https://wiki.gnome.org/Apps/Web?action=AttachFile&amp;amp;do=get&amp;amp;target=epiphany-web-apps.jpg" alt="">
&lt;/p>
&lt;p>&lt;em>Install it from your distro repository!&lt;/em>&lt;/p>
&lt;h2 id="konqueror-35">Konqueror &lt;sup id="fnref:36">&lt;a href="#fn:36" class="footnote-ref" role="doc-noteref">36&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>
&lt;img src="https://docs.kde.org/trunk5/en/applications/konqueror/konqorg.png" alt="">
&lt;/p>
&lt;p>Another Qt browser that’s developed by the KDE team. Its peculiarity is its support for both QtWebEngine engine and KHtml&lt;sup id="fnref:37">&lt;a href="#fn:37" class="footnote-ref" role="doc-noteref">37&lt;/a>&lt;/sup> engine. Right-click and then choose “&lt;em>Render with KHtml&lt;/em>” or “&lt;em>Render with WebEngine&lt;/em>”, this is all it takes to switch between the rendering engines.&lt;/p>
&lt;p>The &lt;em>KHtml&lt;/em> browser engine was choosed by Apple as starting point for its WebKit, but it’s currently &lt;strong>unusable&lt;/strong> because of inability to render Html5 properly.&lt;/p>
&lt;p>&lt;em>Install it from your distro repository!&lt;/em>&lt;/p>
&lt;h2 id="midori-37">Midori &lt;sup id="fnref:38">&lt;a href="#fn:38" class="footnote-ref" role="doc-noteref">38&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>
&lt;img src="https://upload.wikimedia.org/wikipedia/commons/9/95/Midori_Screenshot.png" alt="">
&lt;/p>
&lt;p>&lt;em>Midori&lt;/em> is a lightweight browser, originally developed for the XFCE desktop (indeed its UI reminds this desktop); it uses WebKit.&lt;/p>
&lt;h2 id="ram-usage">RAM usage&lt;/h2>
&lt;p>
&lt;img src="http://i.imgur.com/v2RiPUU.jpg" alt="">
&lt;em>Google literally eating RAM&lt;/em>&lt;/p>
&lt;p>In term of system resources, browsers have made &lt;strong>huge improvments&lt;/strong> in the last years, especially Firefox. If we ordered browsers in terms of RAM usage (from highest to lowest), it would be: Google Chrome, Firefox and then all the others.&lt;/p>
&lt;p>QtWebEngine, even though it is based on Chromium, doens’t &lt;em>consume the same amount of RAM&lt;/em>; considering that browsers using this engine also have a lightweight GUI, they are perfect for low-end machines. Along with WebKit browers as well.&lt;/p>
&lt;h2 id="notes-about-add-ons">Notes about add ons&lt;/h2>
&lt;p>Firefox has recently deprecated support for its extensions API to support the Chrome extensions API; as a result, Chrome and Firefox (including their forks) &lt;strong>share the extension format&lt;/strong>. This is not true for all the other browsers listed in this post: each one supports its own format and has its own add ons (usually not more than 10).&lt;/p>
&lt;h3 id="bonus-privacy-aware-addons-17">Bonus: Privacy-aware addons &lt;sup id="fnref:39">&lt;a href="#fn:39" class="footnote-ref" role="doc-noteref">39&lt;/a>&lt;/sup>&lt;/h3>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://www.google.com/chrome/">https://www.google.com/chrome/&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://www.chromium.org/">https://www.chromium.org/&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://www.falkon.org/download/">https://www.falkon.org/download/&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://github.com/Eloston/ungoogled-chromium">https://github.com/Eloston/ungoogled-chromium&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://github.com/Eloston/ungoogled-chromium#downloads">https://github.com/Eloston/ungoogled-chromium#downloads&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://www.mozilla.org/en-US/firefox/new/">https://www.mozilla.org/en-US/firefox/new/&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="https://blog.mozilla.org/blog/2017/11/14/introducing-firefox-quantum/">https://blog.mozilla.org/blog/2017/11/14/introducing-firefox-quantum/&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:8">
&lt;p>&lt;a href="https://www.reddit.com/r/privacytoolsIO/comments/abfgj5/mozilla_responds_to_bookingcom_snippet_concerns/">https://www.reddit.com/r/privacytoolsIO/comments/abfgj5/mozilla_responds_to_bookingcom_snippet_concerns/&lt;/a>&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:9">
&lt;p>&lt;a href="https://www.ghacks.net/2017/12/16/firefox-looking-glass-extension-what-it-is/">https://www.ghacks.net/2017/12/16/firefox-looking-glass-extension-what-it-is/&lt;/a>&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:10">
&lt;p>&lt;a href="https://www.privacytools.io/#about_config">https://www.privacytools.io/#about_config&lt;/a>&amp;#160;&lt;a href="#fnref:10" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:11">
&lt;p>&lt;a href="https://www.basilisk-browser.org/">https://www.basilisk-browser.org/&lt;/a>&amp;#160;&lt;a href="#fnref:11" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:12">
&lt;p>&lt;a href="https://github.com/MoonchildProductions/UXP">https://github.com/MoonchildProductions/UXP&lt;/a>&amp;#160;&lt;a href="#fnref:12" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:13">
&lt;p>&lt;a href="http://thereisonlyxul.org/">http://thereisonlyxul.org/&lt;/a>&amp;#160;&lt;a href="#fnref:13" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:14">
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/XUL">https://en.wikipedia.org/wiki/XUL&lt;/a>&amp;#160;&lt;a href="#fnref:14" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:15">
&lt;p>&lt;a href="https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL">https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL&lt;/a>&amp;#160;&lt;a href="#fnref:15" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:16">
&lt;p>&lt;a href="https://tech.slashdot.org/story/17/02/17/1635216/mozilla-will-deprecate-xul-add-ons-before-the-end-of-2017">https://tech.slashdot.org/story/17/02/17/1635216/mozilla-will-deprecate-xul-add-ons-before-the-end-of-2017&lt;/a>&amp;#160;&lt;a href="#fnref:16" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:17">
&lt;p>&lt;a href="http://www.moonchildproductions.info/goanna.shtml">http://www.moonchildproductions.info/goanna.shtml&lt;/a>&amp;#160;&lt;a href="#fnref:17" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:18">
&lt;p>&lt;a href="https://github.com/jasperla/openbsd-wip/issues/86">https://github.com/jasperla/openbsd-wip/issues/86&lt;/a>&amp;#160;&lt;a href="#fnref:18" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:19">
&lt;p>&lt;a href="http://danyspin97.org/blog/web-browsers-and-privacy-in-2019/#pale-moon">http://danyspin97.org/blog/web-browsers-and-privacy-in-2019/#pale-moon&lt;/a>&amp;#160;&lt;a href="#fnref:19" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:20">
&lt;p>&lt;a href="https://www.gnu.org/software/gnuzilla/">https://www.gnu.org/software/gnuzilla/&lt;/a>&amp;#160;&lt;a href="#fnref:20" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:21">
&lt;p>&lt;a href="https://www.gnu.org/software/librejs/">https://www.gnu.org/software/librejs/&lt;/a>&amp;#160;&lt;a href="#fnref:21" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:22">
&lt;p>&lt;a href="https://searxes.danwin1210.me/">https://searxes.danwin1210.me/&lt;/a>&amp;#160;&lt;a href="#fnref:22" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:23">
&lt;p>&lt;a href="http://ftp.gnu.org/gnu/gnuzilla/60.3.0/">http://ftp.gnu.org/gnu/gnuzilla/60.3.0/&lt;/a>&amp;#160;&lt;a href="#fnref:23" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:24">
&lt;p>&lt;a href="https://librefox.org/">https://librefox.org/&lt;/a>&amp;#160;&lt;a href="#fnref:24" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:25">
&lt;p>&lt;a href="https://github.com/intika/Librefox#librefox-addons">https://github.com/intika/Librefox#librefox-addons&lt;/a>&amp;#160;&lt;a href="#fnref:25" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:26">
&lt;p>&lt;a href="https://github.com/intika/Librefox/issues/55">https://github.com/intika/Librefox/issues/55&lt;/a>&amp;#160;&lt;a href="#fnref:26" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:27">
&lt;p>&lt;a href="https://github.com/intika/Librefox/releases">https://github.com/intika/Librefox/releases&lt;/a>&amp;#160;&lt;a href="#fnref:27" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:28">
&lt;p>&lt;a href="https://www.palemoon.org/">https://www.palemoon.org/&lt;/a>&amp;#160;&lt;a href="#fnref:28" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:29">
&lt;p>&lt;a href="https://www.waterfoxproject.org/">https://www.waterfoxproject.org/&lt;/a>&amp;#160;&lt;a href="#fnref:29" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:30">
&lt;p>&lt;a href="https://www.waterfoxproject.org/en-US/waterfox/new/?scene=1">https://www.waterfoxproject.org/en-US/waterfox/new/?scene=1&lt;/a>&amp;#160;&lt;a href="#fnref:30" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:31">
&lt;p>&lt;a href="https://textbrowser.github.io/dooble/">https://textbrowser.github.io/dooble/&lt;/a>&amp;#160;&lt;a href="#fnref:31" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:32">
&lt;p>&lt;a href="https://github.com/textbrowser/dooble/releases">https://github.com/textbrowser/dooble/releases&lt;/a>&amp;#160;&lt;a href="#fnref:32" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:33">
&lt;p>&lt;a href="https://www.falkon.org">https://www.falkon.org&lt;/a>&amp;#160;&lt;a href="#fnref:33" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:34">
&lt;p>&lt;a href="https://wiki.gnome.org/Apps/Web/">https://wiki.gnome.org/Apps/Web/&lt;/a>&amp;#160;&lt;a href="#fnref:34" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:35">
&lt;p>&lt;a href="https://webkit.org/">https://webkit.org/&lt;/a>&amp;#160;&lt;a href="#fnref:35" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:36">
&lt;p>&lt;a href="https://konqueror.org/features/browser.php">https://konqueror.org/features/browser.php&lt;/a>&amp;#160;&lt;a href="#fnref:36" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:37">
&lt;p>&lt;a href="https://api.kde.org/frameworks/khtml/html/index.html">https://api.kde.org/frameworks/khtml/html/index.html&lt;/a>&amp;#160;&lt;a href="#fnref:37" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:38">
&lt;p>&lt;a href="https://www.midori-browser.org/">https://www.midori-browser.org/&lt;/a>&amp;#160;&lt;a href="#fnref:38" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:39">
&lt;p>&lt;a href="https://www.privacytools.io/#addons">https://www.privacytools.io/#addons&lt;/a>&amp;#160;&lt;a href="#fnref:39" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Announcing Exherbo subreddit</title><link>https://danyspin97.org/blog/announcing-exherbo-subreddit/</link><pubDate>Mon, 31 Dec 2018 16:00:00 +0100</pubDate><guid>https://danyspin97.org/blog/announcing-exherbo-subreddit/</guid><description>&lt;p>I am delighted to announce the opening of the &lt;strong>unofficial Exherbo subreddit&lt;/strong>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>!
You can discuss topic relavant to the distro, take up any problem that you have
encountered or share your thoughts and setups.&lt;/p>
&lt;p>Note that Exherbo development takes place on our &lt;em>Gitlab instance&lt;/em>&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> and the
critical discussions still happen on &lt;em>#exherbo&lt;/em> IRC channel on &lt;em>Freenode&lt;/em>&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>Furthermore, distro documentation&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup> is currently under reorganisation, and we
encourage you to open an &lt;em>issue&lt;/em> (or even better a &lt;em>Merge Request&lt;/em>!) telling us
which parts you don’t find and which parts are hard to grasp.&lt;/p>
&lt;p>&lt;strong>Stay tuned&lt;/strong> for more Exherbo development in 2019, like the introduction of &lt;em>66&lt;/em> init and rc
manager&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup>.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://www.reddit.com/r/exherbo/">https://www.reddit.com/r/exherbo/&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://gitlab.exherbo.org">https://gitlab.exherbo.org&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://freenode.net">https://freenode.net&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://exherbo.org/docs">https://exherbo.org/docs&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="http://repo.obarun.org/66/">http://repo.obarun.org/66/&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Fancy Vim Plugins</title><link>https://danyspin97.org/blog/fancy-vim-plugins/</link><pubDate>Mon, 24 Dec 2018 12:30:00 +0100</pubDate><guid>https://danyspin97.org/blog/fancy-vim-plugins/</guid><description>&lt;p>&lt;em>&lt;strong>Prerequisites:&lt;/strong>&lt;/em> &lt;em>basic knowledge of vim editor, minimal plugin configuration&lt;/em>.&lt;/p>
&lt;p>I read a lot of plugin posts over the internet back when I begun using vim. While I still find them supportive for starters, they suggest the same plugins over and over.&lt;/p>
&lt;p>Today I will talk about a bunch of unknown plugins which give the editor a modern look and feel. I call them &lt;em>“unknown”&lt;/em> because the number of stars these projects received doesn’t go above &lt;strong>1000&lt;/strong>.&lt;/p>
&lt;p>I will include installation commands for &lt;code>vim-plug&lt;/code>&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> plugin manager and optional configuration useful for the users. You can use your plugin manager of choice by replacing &lt;code>Plug&lt;/code> with whatever it uses.&lt;/p>
&lt;h2 id="1-colorizer2">1. colorizer&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>Have you read an HTML color code and asked yourself which color represented? In this case, &lt;code>colorizer&lt;/code> will save your day. I enjoy it the most when working on small CSS files and on dotfiles.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/colorizer.jpg" alt="">
&lt;/p>
&lt;p>Installation:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">Plug&lt;/span> &lt;span class="s1">&amp;#39;lilydjwg/colorizer&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="2-rainbow3">2. rainbow&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>Doesn&amp;rsquo;t matter which language you’re writing in, nested parentheses and braces give developers headaches; matches highlighting don’t help much either.&lt;/p>
&lt;p>&lt;code>rainbow&lt;/code> highlights the parentheses and braces based on their nesting level; as a result, the window will be hightlighted with “rainbow” colors, hence the plugin name.&lt;/p>
&lt;p>But it’s easier to see with some lisp code:&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/rainbow_screenshot.png" alt="">
&lt;/p>
&lt;p>Installation:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">Plug&lt;/span> &lt;span class="s1">&amp;#39;luochen1990/rainbow&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>rainbow&lt;/code> can the toggled using &lt;code>:RainbowToggle&lt;/code>; to enable the plugin at startup add:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="k">let&lt;/span> &lt;span class="nx">g&lt;/span>:&lt;span class="nx">rainbow_active&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">1&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="3-vim-illuminate4">3. vim-illuminate&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>&lt;code>vim-illuminate&lt;/code> highlights the words in the current buffer matching the one under the cursor, letting you glance at once the local references of a variable or method.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/vim-illuminate.gif" alt="">
&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">Plug&lt;/span> &lt;span class="s1">&amp;#39;RRethy/vim-illuminate&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The default configuration shipped is sane and use &lt;code>cursorline&lt;/code> as highlight group. Since I prefer a highlight group little more constrast with the background, I set &lt;code>Visual&lt;/code> in place of &lt;code>cursorline&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="k">hi&lt;/span> &lt;span class="nx">link&lt;/span> &lt;span class="nx">illuminatedWord&lt;/span> &lt;span class="nx">Visual&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="4-vim-smooth-scroll6">4. vim-smooth-scroll&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>Window scroll in vim comply to the overall efficiency. However, scroll isn’t the nicest feature to expect from a modern editor, expecially when we run many instances of Chrome at the same time (I’m pointing at you Electron!). &lt;code>vim-smooth-scroll&lt;/code> provides exactly this feature:&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/vim-smooth-scroll.gif" alt="">
&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">Plug&lt;/span> &lt;span class="s1">&amp;#39;terryma/vim-smooth-scroll&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">noremap&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">silent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">c&lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="nx">u&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> :&lt;span class="nx">call&lt;/span> &lt;span class="nx">smooth_scroll&lt;/span>#&lt;span class="nx">up&lt;/span>&lt;span class="p">(&lt;/span>&amp;amp;&lt;span class="nx">scroll&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">0&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">)&amp;lt;&lt;/span>&lt;span class="nx">CR&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">noremap&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">silent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">c&lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="nx">d&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> :&lt;span class="nx">call&lt;/span> &lt;span class="nx">smooth_scroll&lt;/span>#&lt;span class="nx">down&lt;/span>&lt;span class="p">(&lt;/span>&amp;amp;&lt;span class="nx">scroll&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">0&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">)&amp;lt;&lt;/span>&lt;span class="nx">CR&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">noremap&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">silent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">c&lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="nx">b&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> :&lt;span class="nx">call&lt;/span> &lt;span class="nx">smooth_scroll&lt;/span>#&lt;span class="nx">up&lt;/span>&lt;span class="p">(&lt;/span>&amp;amp;&lt;span class="nx">scroll&lt;/span>*&lt;span class="m">2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">0&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">4&lt;/span>&lt;span class="p">)&amp;lt;&lt;/span>&lt;span class="nx">CR&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">noremap&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">silent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">c&lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="nx">f&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> :&lt;span class="nx">call&lt;/span> &lt;span class="nx">smooth_scroll&lt;/span>#&lt;span class="nx">down&lt;/span>&lt;span class="p">(&lt;/span>&amp;amp;&lt;span class="nx">scroll&lt;/span>*&lt;span class="m">2&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">0&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">4&lt;/span>&lt;span class="p">)&amp;lt;&lt;/span>&lt;span class="nx">CR&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>You can customize &lt;em>dinstance&lt;/em>, &lt;em>duration&lt;/em> and &lt;em>speed&lt;/em> by changing the respective parameters of &lt;code>smooth_scroll#&lt;/code> methods. I personally prefer a value of &lt;code>5&lt;/code> for &lt;em>duration&lt;/em>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">noremap&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">silent&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nx">c&lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="nx">u&lt;/span>&lt;span class="p">&amp;gt;&lt;/span> :&lt;span class="nx">call&lt;/span> &lt;span class="nx">smooth_scroll&lt;/span>#&lt;span class="nx">up&lt;/span>&lt;span class="p">(&lt;/span>&amp;amp;&lt;span class="nx">scroll&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">5&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="m">2&lt;/span>&lt;span class="p">)&amp;lt;&lt;/span>&lt;span class="nx">CR&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="5-vim-search-pulse">5. vim-search-pulse&lt;/h2>
&lt;p>&lt;code>vim-search-pulse&lt;/code> add a tiny and peculiar feature: it pulses every time you scroll the search results by pressing &lt;code>n&lt;/code>/&lt;code>N&lt;/code>.&lt;/p>
&lt;p>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/vim-search-pulse.mp4" alt="">
&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">Plug&lt;/span> &lt;span class="s1">&amp;#39;inside/vim-search-pulse&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The pulse duration can be customized to user’s taste.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-vim" data-lang="vim">&lt;span class="line">&lt;span class="cl">&lt;span class="k">let&lt;/span> &lt;span class="nx">g&lt;/span>:&lt;span class="nx">vim_search_pulse_duration&lt;/span> &lt;span class="p">=&lt;/span> &lt;span class="m">200&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="bonus-semshi5">bonus: semshi&lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>&lt;/h2>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>&lt;/em>: &lt;em>the following plugin works in Neovim but doesn’t support Vim 8 due to a missing equivalent highlighting API, sorry folks! Have you considered upgrading to neovim?&lt;/em>&lt;/p>
&lt;p>&lt;code>semshi&lt;/code> provides semantic highlighting for Python. Semantic highlighting directly follow syntax’s one in color coding, coloring fixed words &lt;em>and&lt;/em> all the remaining words. Analizing the code, it rapidly gives each word a color based on its type, with a much better result than before.&lt;/p>
&lt;dl>
&lt;dt>With semshi&lt;/dt>
&lt;dd>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/w-semshi.jpg" alt="After">
&lt;/dd>
&lt;dt>Without semshi&lt;/dt>
&lt;dd>
&lt;img src="https://danyspin97.org/img/fancy_vim_plugins/wo-semshi.jpg" alt="Before">
&lt;/dd>
&lt;/dl>
&lt;p>This plugin is fast, static and works on single files; it means that it doesn’t need to know how your project structure and can be invoked anywhere.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://github.com/junegunn/vim-plug">https://github.com/junegunn/vim-plug&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://github.com/lilydjwg/colorizer">https://github.com/lilydjwg/colorizer&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://github.com/luochen1990/rainbow">https://github.com/luochen1990/rainbow&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://github.com/RRethy/vim-illuminate">https://github.com/RRethy/vim-illuminate&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://github.com/terryma/vim-smooth-scroll">https://github.com/terryma/vim-smooth-scroll&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://github.com/numirias/semshi">https://github.com/numirias/semshi&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Makefiles, Best Practices</title><link>https://danyspin97.org/blog/makefiles-best-practices/</link><pubDate>Thu, 29 Nov 2018 09:49:01 +0200</pubDate><guid>https://danyspin97.org/blog/makefiles-best-practices/</guid><description>&lt;p>&lt;code>Makefile&lt;/code>s are widely used to build a lot of languages and projects, with C/C++ projects being the majority. Whenever you are developing or testing software, it&amp;rsquo;s highly probable that you will encounter them.&lt;/p>
&lt;p>This post will try to address some common errors in &lt;code>Makefile&lt;/code>s, as well as good practices and cross-compiling support.&lt;/p>
&lt;p>&lt;em>&lt;strong>Prerequisites&lt;/strong>: good understanding of &lt;code>Makefile&lt;/code>s, UNIX directory hierarchy and compilation process.&lt;/em>&lt;/p>
&lt;h2 id="make-versions">Make versions&lt;/h2>
&lt;p>POSIX Make standard syntax&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup> is often extended by the different implementations. In this post we will use GNU Make&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> (&lt;code>gmake&lt;/code>) and its extensions.&lt;/p>
&lt;p>Each Make dialect searches for a specific file when executed and fallbacks to a general &lt;code>Makefile&lt;/code> if it doesn’t succeed; for GNU Make, this file is &lt;code>GNUMakefile&lt;/code>. When using a dialect over the POSIX interface, consider to name the &lt;code>Makefile&lt;/code> accordingly; this way it’s clear which implementation is needed.&lt;/p>
&lt;p>In most Linux systems and OSX systems, &lt;code>make&lt;/code> is a symlink to &lt;code>gmake&lt;/code>. You can check the version of make on your system by running:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-plain" data-lang="plain">&lt;span class="line">&lt;span class="cl">$ make --version
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">GNU Make 4.2.1
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Built for x86_64-pc-linux-gnu
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Copyright (C) 1988-2016 Free Software Foundation, Inc.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">License GPLv3+: GNU GPL version 3 or later &amp;lt;http://gnu.org/licenses/gpl.html&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">This is free software: you are free to change and redistribute it.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">There is NO WARRANTY, to the extent permitted by law.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>For simplicity, from now on we will refer to &lt;code>GNUMakefile&lt;/code> and &lt;code>gmake&lt;/code> as respectively &lt;code>Makefile&lt;/code> and &lt;code>make&lt;/code>.&lt;/p>
&lt;h2 id="variable-setting">Variable setting&lt;/h2>
&lt;p>In this post we will use two ways (of the five available&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup>) to set a variable in &lt;code>Makefile&lt;/code>. Here is a recap from StackOverflow&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>:&lt;/p>
&lt;dl>
&lt;dt>Lazy Set&lt;/dt>
&lt;dd>
&lt;p>Normal setting of a variable — values within it are recursively expanded when the variable is used, not when it&amp;rsquo;s declared&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">VARIABLE&lt;/span> &lt;span class="o">=&lt;/span> value
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;dl>
&lt;dt>Immediate Set&lt;/dt>
&lt;dd>
&lt;p>Setting of a variable with simple expansion of the values inside — values within it are expanded at declaration time.&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">VARIABLE&lt;/span> &lt;span class="o">:=&lt;/span> value
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;dl>
&lt;dt>Set If Absent&lt;/dt>
&lt;dd>
&lt;p>Setting of a variable only if it doesn&amp;rsquo;t have a value&lt;/p>
&lt;/dd>
&lt;/dl>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">VARIABLE&lt;/span> &lt;span class="o">?=&lt;/span> value
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="compiler">Compiler&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CC&lt;/span> &lt;span class="o">?=&lt;/span> gcc
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">LD&lt;/span> &lt;span class="o">?=&lt;/span> gcc
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>While it is usually safe to assume that sensible values have been set for &lt;code>CC&lt;/code> and &lt;code>LDD&lt;/code>, it does no harm to set them if and &lt;em>only&lt;/em> if they are not already set in the environment, using the operator &lt;code>?=&lt;/code>.&lt;/p>
&lt;p>Using the assignment operator &lt;code>=&lt;/code> will instead override &lt;code>CC&lt;/code> and &lt;code>LDD&lt;/code> values from the environment; it means that we choose the default compiler and it cannot be changed without editing the Makefile or appending these variables in the command line. This leads to two problems:&lt;/p>
&lt;ul>
&lt;li>The user has set &lt;code>CC=clang&lt;/code> in the environment but &lt;code>gcc&lt;/code> will be used anyway, even if it isn&amp;rsquo;t installed.&lt;/li>
&lt;li>A cross-compile environment has set &lt;code>CC&lt;/code> to a link of the actual target architecture compiler, like for example &lt;code>arm-pc-linux-cc&lt;/code>, but &lt;code>gcc&lt;/code> of the host will be used.&lt;/li>
&lt;/ul>
&lt;p>If the user has acknowledged these problems (i.e. the compilation fails because gcc is not installed), he can append &lt;code>CC=clang&lt;/code> to the &lt;code>make&lt;/code> call:&lt;/p>
&lt;pre tabindex="0">&lt;code>$ make CC=clang
&lt;/code>&lt;/pre>&lt;p>This solution works as intended (&lt;code>clang&lt;/code> compiles the sources), whatever the Makefile uses &lt;code>=&lt;/code> or &lt;code>?=&lt;/code> operators but it adds workload on the user: a reading of the &lt;code>Makefile&lt;/code> is needed to check the variables to append on the command line. It’s also error-prone because it’s easy to skip one variable assignment in a large project while it is safe to assume that the environment already contains correct values.&lt;/p>
&lt;p>For these reasons, this solution is considered sub-optimal, especially for package maintaining, and therefore its usage is discouraged.&lt;/p>
&lt;h2 id="compiler-flags">Compiler flags&lt;/h2>
&lt;p>&lt;code>make&lt;/code> utility also use variables that are defined by implicit rules&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup> and between these variables, some define extra build flags:&lt;/p>
&lt;ul>
&lt;li>&lt;code>CFLAGS&lt;/code>: flags for the &lt;code>C&lt;/code> compiler&lt;/li>
&lt;li>&lt;code>CXXFLAGS&lt;/code>: flags for the &lt;code>C++&lt;/code> compiler&lt;/li>
&lt;li>&lt;code>CPPFLAGS&lt;/code>&lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup>: for preprocessor flags for &lt;code>C/C++&lt;/code> and &lt;code>Fortran&lt;/code> compilers&lt;/li>
&lt;/ul>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: there is a variable named &lt;code>CCFLAGS&lt;/code> that some projects are using; it defines extra flags for both the &lt;code>C&lt;/code>/&lt;code>C++&lt;/code> compilers. This variable is not defined by the implicit rules, please avoid it if you can&lt;/em>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Note 2&lt;/strong>: build systems usually follow the &lt;code>make&lt;/code> implicit rules for both variable naming and meaning. In other words, defining &lt;code>CFLAGS&lt;/code> means defining extra flags for &lt;code>C&lt;/code> compiler whatever build system you&amp;rsquo;re using&lt;/em>.&lt;/p>
&lt;p>Usually, we add to the compiler options specific for the application we&amp;rsquo;re writing, such as language revision (do we want to use &lt;code>c89&lt;/code> or &lt;code>c99&lt;/code>?).
Then the user add his own &lt;code>CFLAGS&lt;/code>/&lt;code>CXXFLAGS&lt;/code> to include debug option and add optimizations; it is important to add these user defined flags.&lt;/p>
&lt;p>We would be tempted to do:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">=&lt;/span> -ansi -std&lt;span class="o">=&lt;/span>&lt;span class="m">99&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>But this would discard the environment &lt;code>CFLAGS&lt;/code>, which might contain user defined value. You should instead do:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">:=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">CFLAGS&lt;/span>&lt;span class="si">}&lt;/span> -ansi -std&lt;span class="o">=&lt;/span>&lt;span class="m">99&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>&lt;strong>Note:&lt;/strong>&lt;/em> &lt;em>The Immediate set (&lt;code>:=&lt;/code>) is used because the Lazy set (&lt;code>=&lt;/code>) would result in a recursive loop&lt;/em>.&lt;/p>
&lt;p>Or, if you have a long &lt;code>CFLAGS&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">+=&lt;/span> -ansi -std&lt;span class="o">=&lt;/span>&lt;span class="m">99&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>In this last example, we append our values to environment &lt;code>CFLAGS&lt;/code>; if it isn’t defined, it will be expanded to no text. The resulting &lt;code>CFLAGS&lt;/code> will still be a &lt;em>recursively expanded variable&lt;/em>&lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>We can optimize a little by converting &lt;code>CFLAGS&lt;/code> from a recursive variable to a simple one.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">:=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">CFLAGS&lt;/span>&lt;span class="si">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">+=&lt;/span> -ansi -std&lt;span class="o">=&lt;/span>&lt;span class="m">99&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="libraries">Libraries&lt;/h2>
&lt;p>In order to include the libraries in the
program, gcc flags are needed for both compile and link time.&lt;/p>
&lt;p>You can add default values when including libraries, like for example default headers location &lt;code>/usr/include/&lt;/code>; use this value inside a variable that can be overriden from the environment (&lt;code>?=&lt;/code> set) if you follow this approach.&lt;/p>
&lt;p>Suppose we want to include and link our program against &lt;code>OpenSSL&lt;/code>, a broadly used library for cryptography and TLS/SSL protocols; we would intuitively add &lt;code>-I/usr/include/openssl&lt;/code> to our &lt;code>CFLAGS&lt;/code>/&lt;code>CXXFLAGS&lt;/code>. It might be good for the most of the linux system, but a MacOS user could have OpenSSL headers in &lt;code>/usr/local/include/openssl&lt;/code>, breaking compilation, same thing goes for cross compilation.&lt;/p>
&lt;p>What it should be done instead is:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">OPENSSL_INCLUDE&lt;/span> &lt;span class="o">?=&lt;/span> -I/usr/include/openssl
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">OPENSSL_LIBS&lt;/span> &lt;span class="o">?=&lt;/span> -lssl -lcrypto
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">?=&lt;/span> -O2 -pipe
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">+=&lt;/span> &lt;span class="k">$(&lt;/span>OPENSSL_INCLUDE&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">LIBS&lt;/span> &lt;span class="o">:=&lt;/span> &lt;span class="k">$(&lt;/span>OPENSSL_LIBS&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>While this approach result in successful compilation, by overriding values when needed, it is really cumbersome and error-prone. A better way to include external libraries is to use &lt;code>pkg-config&lt;/code>.&lt;/p>
&lt;h2 id="pkg-config">pkg-config&lt;/h2>
&lt;p>&lt;code>pkg-config&lt;/code>&lt;sup id="fnref:8">&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref">8&lt;/a>&lt;/sup> is a command-line tool that provides correct compiler options when including libraries; it is widely used in &lt;code>Makefile&lt;/code>s but also in various build systems as &lt;code>CMake&lt;/code>&lt;sup id="fnref:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup> and &lt;code>meson&lt;/code>&lt;sup id="fnref:10">&lt;a href="#fn:10" class="footnote-ref" role="doc-noteref">10&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>Let&amp;rsquo;s rewrite the previous snippet using &lt;code>pkg-config&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-Makefile" data-lang="Makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">PKG_CONFIG&lt;/span> &lt;span class="o">?=&lt;/span> pkg-config
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">?=&lt;/span> -O2 -pipe
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">+=&lt;/span> -std&lt;span class="o">=&lt;/span>&lt;span class="m">99&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">CFLAGS&lt;/span> &lt;span class="o">+=&lt;/span> &lt;span class="k">$(&lt;/span>shell &lt;span class="si">${&lt;/span>&lt;span class="nv">PKG_CONFIG&lt;/span>&lt;span class="si">}&lt;/span> --cflags openssl&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">LIBS&lt;/span> &lt;span class="o">:=&lt;/span> &lt;span class="k">$(&lt;/span>shell &lt;span class="si">${&lt;/span>&lt;span class="nv">PKG_CONFIG&lt;/span>&lt;span class="si">}&lt;/span> --libs openssl&lt;span class="k">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Note how &lt;code>pkg-config&lt;/code> executable can be overriden from the environment, again for supporting cross-compiling.&lt;/p>
&lt;p>Immediate set should be used with &lt;code>LIBS&lt;/code> to avoid spawning &lt;code>pkg-config&lt;/code> every time the variable is evaluated. &lt;em>Thanks to u/dima55&lt;sup id="fnref:11">&lt;a href="#fn:11" class="footnote-ref" role="doc-noteref">11&lt;/a>&lt;/sup> for the tip.&lt;/em>&lt;/p>
&lt;h2 id="miscellaneous">Miscellaneous&lt;/h2>
&lt;p>Other executables often used when compiling are &lt;code>ar&lt;/code>, &lt;code>ranlib&lt;/code> and &lt;code>as&lt;/code>; don&amp;rsquo;t call these executables directly but
store their name in variables and use these variables instead.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">AR&lt;/span> &lt;span class="o">?=&lt;/span> ar
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">RANLIB&lt;/span> &lt;span class="o">?=&lt;/span> ranlib
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nv">AS&lt;/span> &lt;span class="o">?=&lt;/span> as
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>From &lt;code>make&lt;/code> documentation&lt;sup id="fnref:12">&lt;a href="#fn:12" class="footnote-ref" role="doc-noteref">12&lt;/a>&lt;/sup>:&lt;/p>
&lt;blockquote>
&lt;p>The precise recipe is &lt;code>${AS} ${ASFLAGS}&lt;/code>.&lt;/p>
&lt;/blockquote>
&lt;h2 id="installation">Installation&lt;/h2>
&lt;p>The last part of a &lt;code>Makefile&lt;/code> is the installation of program itself and the related data. This is the trickiest part because there a lot of data types, and each one can be installed in various locations.&lt;/p>
&lt;h3 id="prefix">PREFIX&lt;/h3>
&lt;p>Before talking about the different components to install, we should discuss briefly the &lt;code>PREFIX&lt;/code> variable. The binaries usually go in a &lt;code>bin&lt;/code> directory, in Linux environment &lt;code>/usr/bin&lt;/code> is used for system packages managed by the package managers and &lt;code>/usr/local/bin&lt;/code> for system packages installed by the user, FreeBSD ports use &lt;code>/usr/local/bin&lt;/code>; same goes for the other components (data, man pages).&lt;/p>
&lt;p>It is important to specify which &lt;code>PREFIX&lt;/code> the &lt;code>bin&lt;/code> directory should be installed in:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">PREFIX&lt;/span> &lt;span class="o">?=&lt;/span> /usr/local
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The default value should be &lt;code>/usr/local&lt;/code>&lt;sup id="fnref:13">&lt;a href="#fn:13" class="footnote-ref" role="doc-noteref">13&lt;/a>&lt;/sup>.&lt;/p>
&lt;h3 id="bindir">BINDIR&lt;/h3>
&lt;p>The principal component of every program (excluding libraries) is the executable itself. As we stated before, the usually directory is &lt;code>${PREFIX}/bin&lt;/code>, so at a first glance we could choose to install the executables directly there like this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nf">install&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p foo &lt;span class="si">${&lt;/span>&lt;span class="nv">PREFIX&lt;/span>&lt;span class="si">}&lt;/span>/bin/foo
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>While this is correct most of the time, it limits flexibility of the &lt;code>Makefile&lt;/code> we&amp;rsquo;re writing. To give user more choice we should instead use a variable to specify executables location: &lt;code>BINDIR&lt;/code>.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">BINDIR&lt;/span> &lt;span class="o">?=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">PREFIX&lt;/span>&lt;span class="si">}&lt;/span>/bin
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nf">install&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p foo &lt;span class="si">${&lt;/span>&lt;span class="nv">BINDIR&lt;/span>&lt;span class="si">}&lt;/span>/foo
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="datadir">DATADIR&lt;/h3>
&lt;p>From the GNU Coding Standards&lt;sup id="fnref:14">&lt;a href="#fn:14" class="footnote-ref" role="doc-noteref">14&lt;/a>&lt;/sup>:&lt;/p>
&lt;blockquote>
&lt;p>The directory for installing idiosyncratic read-only architecture-independent data files for this program.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>DATADIR&lt;/code> directory, usually &lt;code>/usr/share&lt;/code> contains read-only data, from application icon to man pages and documentation.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">DATADIR&lt;/span> &lt;span class="o">?=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">PREFIX&lt;/span>&lt;span class="si">}&lt;/span>/share
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>It is important to specify &lt;code>DATADIR&lt;/code> because &lt;code>MANDIR&lt;/code> and other variables depend on it.&lt;/p>
&lt;p>It can happen that this directory doesn&amp;rsquo;t start with &lt;code>PREFIX&lt;/code>; for example a cross-compiled system can have the executables in &lt;code>/usr/${ARCH}/bin&lt;/code> (therefore &lt;code>/usr/${ARCH}&lt;/code> as &lt;code>PREFIX&lt;/code>) and have &lt;code>/usr/share&lt;/code> as &lt;code>DATADIR&lt;/code>.&lt;/p>
&lt;h3 id="mandir">MANDIR&lt;/h3>
&lt;p>The location where the man pages are installed is stored in &lt;code>MANDIR&lt;/code>.&lt;/p>
&lt;p>If you are using &lt;code>DATADIR&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>MANDIR ?= ${DATADIR}/man
&lt;/code>&lt;/pre>&lt;p>Otherwise:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">MANDIR&lt;/span> &lt;span class="o">?=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">PREFIX&lt;/span>&lt;span class="si">}&lt;/span>/share/man
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The first approach is better because a user can just set &lt;code>DATADIR&lt;/code> and forget about &lt;code>MANDIR&lt;/code>; they are equally flexible.&lt;/p>
&lt;h3 id="destdir">DESTDIR&lt;/h3>
&lt;p>Now, we chose all the various component location, there is one last important question to ask ourself: &lt;em>which is the base install directory&lt;/em>?&lt;/p>
&lt;p>We usually want to install the program in root folder which works with everything we&amp;rsquo;ve seen so far. Let&amp;rsquo;s suppose there is a system mounted in whatever place or the toolchain merges the a special destination directory with the root install, how can we target this custom destination directory?&lt;/p>
&lt;p>&lt;code>DESTDIR&lt;/code> is a special variable that let us specify a destination directory. Its usage is simple, we prefix all the variables we saw with &lt;code>${DESTDIR}&lt;/code> in the &lt;code>install&lt;/code> section.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nf">install&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p foo &lt;span class="si">${&lt;/span>&lt;span class="nv">DESTDIR&lt;/span>&lt;span class="si">}${&lt;/span>&lt;span class="nv">BINDIR&lt;/span>&lt;span class="si">}&lt;/span>/foo
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> @cp -p foo &lt;span class="si">${&lt;/span>&lt;span class="nv">DESTDIR&lt;/span>&lt;span class="si">}${&lt;/span>&lt;span class="nv">MANDIR&lt;/span>&lt;span class="si">}&lt;/span>/man1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>There is no need to set it because either the user set &lt;code>DESTDIR&lt;/code> or &lt;code>/&lt;/code> will be used.&lt;/p>
&lt;p>Note that the following assignment to &lt;code>BINDIR&lt;/code> is incorrect because &lt;code>DESTDIR&lt;/code> should only be added later in the &lt;code>install&lt;/code> section and not on variable assignment.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-makefile" data-lang="makefile">&lt;span class="line">&lt;span class="cl">&lt;span class="nv">BINDIR&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">DESTDIR&lt;/span>&lt;span class="si">}${&lt;/span>&lt;span class="nv">PREFIX&lt;/span>&lt;span class="si">}&lt;/span>/bin
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="other-locations">Other locations&lt;/h3>
&lt;p>Since there are many other locations, we covered the most used ones. Refer to GNU Coding Standard&lt;sup id="fnref1:14">&lt;a href="#fn:14" class="footnote-ref" role="doc-noteref">14&lt;/a>&lt;/sup> and big projects&amp;rsquo; &lt;code>Makefile&lt;/code> to see other variables.&lt;/p>
&lt;h2 id="reproducible-builds">Reproducible builds&lt;/h2>
&lt;p>Another practice, which got an increasing usage in the last years, is &lt;em>reproducible builds&lt;/em>&lt;sup id="fnref:15">&lt;a href="#fn:15" class="footnote-ref" role="doc-noteref">15&lt;/a>&lt;/sup>:&lt;/p>
&lt;blockquote>
&lt;p>&lt;strong>Reproducible builds&lt;/strong> are a set of software development practices that create an &lt;strong>independently-verifiable path&lt;/strong> from &lt;strong>source code to the binary code&lt;/strong> used by computers.&lt;/p>
&lt;/blockquote>
&lt;p>This practice is being adopted by Debian&lt;sup id="fnref:16">&lt;a href="#fn:16" class="footnote-ref" role="doc-noteref">16&lt;/a>&lt;/sup> and it is worth adopting in general. Explaining how to adopt &lt;em>reproducible builds&lt;/em> goes beyond the scope of this post, but you can read more in the official site&lt;sup id="fnref1:15">&lt;a href="#fn:15" class="footnote-ref" role="doc-noteref">15&lt;/a>&lt;/sup>.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>Following these rules and standards you will have a better &lt;code>Makefile&lt;/code>, along with great flexibility among all the user environments and cross-compiling support.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html">https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="https://www.gnu.org/software/make/manual/make.html">https://www.gnu.org/software/make/manual/make.html&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="https://www.gnu.org/software/make/manual/make.html#Setting">https://www.gnu.org/software/make/manual/make.html#Setting&lt;/a>&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://stackoverflow.com/a/448939">https://stackoverflow.com/a/448939&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="https://www.gnu.org/software/make/manual/make.html#index-CFLAGS">https://www.gnu.org/software/make/manual/make.html#index-CFLAGS&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://stackoverflow.com/questions/2754966/cflags-vs-cppflags">https://stackoverflow.com/questions/2754966/cflags-vs-cppflags&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors">https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:8">
&lt;p>&lt;a href="https://www.freedesktop.org/wiki/Software/pkg-config/">https://www.freedesktop.org/wiki/Software/pkg-config/&lt;/a>&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:9">
&lt;p>&lt;a href="https://cmake.org">https://cmake.org&lt;/a>&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:10">
&lt;p>&lt;a href="https://mesonbuild.com">https://mesonbuild.com&lt;/a>&amp;#160;&lt;a href="#fnref:10" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:11">
&lt;p>&lt;a href="https://www.reddit.com/user/dima55">https://www.reddit.com/user/dima55&lt;/a>&amp;#160;&lt;a href="#fnref:11" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:12">
&lt;p>&lt;a href="https://www.gnu.org/software/make/manual/make.html#index-AR">https://www.gnu.org/software/make/manual/make.html#index-AR&lt;/a>&amp;#160;&lt;a href="#fnref:12" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:13">
&lt;p>&lt;a href="https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s09.html">https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch04s09.html&lt;/a>&amp;#160;&lt;a href="#fnref:13" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:14">
&lt;p>&lt;a href="https://www.gnu.org/prep/standards/html_node/Directory-Variables.html">https://www.gnu.org/prep/standards/html_node/Directory-Variables.html&lt;/a>&amp;#160;&lt;a href="#fnref:14" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:14" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:15">
&lt;p>&lt;a href="https://reproducible-builds.org/">https://reproducible-builds.org/&lt;/a>&amp;#160;&lt;a href="#fnref:15" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&amp;#160;&lt;a href="#fnref1:15" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:16">
&lt;p>&lt;a href="https://wiki.debian.org/ReproducibleBuilds">https://wiki.debian.org/ReproducibleBuilds&lt;/a>&amp;#160;&lt;a href="#fnref:16" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Getting started with execline scripting</title><link>https://danyspin97.org/blog/getting-started-with-execline-scripting/</link><pubDate>Tue, 04 Sep 2018 22:15:00 +0100</pubDate><guid>https://danyspin97.org/blog/getting-started-with-execline-scripting/</guid><description>&lt;h2 id="preface">Preface&lt;/h2>
&lt;p>In this post, the &lt;code>execline&lt;/code> scripting language will be outlined: we will learn anything you need to get started.&lt;/p>
&lt;p>&lt;em>&lt;strong>Prerequisites&lt;/strong>: basic understanding of shell scripting, and environment; access to unix shell and &lt;code>execline&lt;/code> installed.&lt;/em>&lt;/p>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: all the scripts have been tested with &lt;code>execline&lt;/code> version 2.5.0.1.&lt;/em>&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>&lt;code>execline&lt;/code> is scripting language written with security and simplicity in mind.
Its goal is to provide a predictable syntax while remaining portable and easy on resources.&lt;/p>
&lt;p>Why not just use /bin/sh?&lt;sup id="fnref:1">&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref">1&lt;/a>&lt;/sup>&lt;/p>
&lt;p>Let&amp;rsquo;s have a look at it.&lt;/p>
&lt;pre tabindex="0">&lt;code>importas home HOME cd $home ls
&lt;/code>&lt;/pre>&lt;p>A single chain load as an entire script; it seems really weird, doesn&amp;rsquo;t it?&lt;/p>
&lt;p>&lt;code>execline&lt;/code> relies completely on chain loading: it simply executes the first word and uses the
remaining ones as &lt;code>argv&lt;/code>. This makes &lt;code>execline&lt;/code> perfect for critical scripts
like init and rc scripts. It is primary used as scripting language by the &lt;code>s6&lt;/code>&lt;sup id="fnref:2">&lt;a href="#fn:2" class="footnote-ref" role="doc-noteref">2&lt;/a>&lt;/sup> supervision suite and the &lt;code>s6-rc&lt;/code>&lt;sup id="fnref:3">&lt;a href="#fn:3" class="footnote-ref" role="doc-noteref">3&lt;/a>&lt;/sup> service manager.&lt;/p>
&lt;h2 id="words-and-whitespaces">Words and whitespaces&lt;/h2>
&lt;p>An &lt;code>execline&lt;/code> script is a string, parsed as words with whitespaces in between.&lt;/br> And &lt;code>execline&lt;/code> parser consider &lt;em>spaces&lt;/em>, &lt;em>tabs&lt;/em>, &lt;em>newlines&lt;/em> and &lt;em>carriage returns&lt;/em> as whitespace.&lt;/p>
&lt;p>Understanding that, we can rewrite the previous script in a more friendly way, by adding newlines here and there:&lt;/p>
&lt;pre tabindex="0">&lt;code>importas home HOME
cd $home
ls
&lt;/code>&lt;/pre>&lt;p>In each line we find a program and its respective arguments. &lt;code>ls&lt;/code> is an external program while &lt;code>cd&lt;/code> and &lt;code>importas&lt;/code> are two builtins. The difference will be discussed in details later.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>cd dir prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>cd changes the current working directory to &lt;code>dir&lt;/code> and then executes &lt;code>prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>importas variable envvar prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>importas&lt;/code> fetches the value of &lt;code>envvar&lt;/code> in the environment and import it in the literal &lt;code>variable&lt;/code>. It then executes &lt;code>prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;p>So what the script does is, in order:&lt;/p>
&lt;ul>
&lt;li>get &lt;code>HOME&lt;/code> value from the environment and assign its value to &lt;code>home&lt;/code> literal&lt;/li>
&lt;li>change the directory to the &lt;code>home&lt;/code> value&lt;/li>
&lt;li>call &lt;code>ls&lt;/code>&lt;/li>
&lt;/ul>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: &lt;code>execline&lt;/code> doesn&amp;rsquo;t expand &lt;code>~&lt;/code> to the home directory, so &lt;code>cd ~&lt;/code> won&amp;rsquo;t work.&lt;/em>&lt;/p>
&lt;p>&lt;code>execline&lt;/code> builtins take an arbitrary number of arguments and then execute the next program. The words left are the arguments of this new program executed. Therefore we can generalize the syntax as:&lt;/p>
&lt;pre tabindex="0">&lt;code>builtin args prog...
&lt;/code>&lt;/pre>&lt;p>where &lt;code>args&lt;/code> can be any number of arguments.&lt;/p>
&lt;h2 id="execution">Execution&lt;/h2>
&lt;p>We have our script ready to be executed. But how do we execute it?&lt;/p>
&lt;p>There are two ways:&lt;/p>
&lt;ul>
&lt;li>calling execline directly&lt;/li>
&lt;li>using a shebang&lt;/li>
&lt;/ul>
&lt;p>Create a new file named &lt;code>ls_home&lt;/code> and the following code in it:&lt;/p>
&lt;pre tabindex="0">&lt;code>importas home HOME cd $home ls
&lt;/code>&lt;/pre>&lt;p>Now execute the following command in a *nix shell:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">execlineb ls_home
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Yay! We have executed the script by calling &lt;code>execlineb&lt;/code> directly.
Though this could be a little cumbersome, expecially when we need to add arguments to the &lt;code>execlineb&lt;/code> call.
Indeed, shebangs are often chosen for simplicity.&lt;/p>
&lt;p>Using your editor of choice, open &lt;code>ls_home&lt;/code> and add the following as first line:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">#!/bin/exexlineb
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now that we&amp;rsquo;ve added the shebang, we have to make the file executable; get back to the shell and execute:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">chmod +x ls_home
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Now execute it:&lt;/p>
&lt;pre tabindex="0">&lt;code>./ls_home
&lt;/code>&lt;/pre>&lt;p>This shebang will be used from now and omitted for shortness, unless noted.&lt;/p>
&lt;h2 id="builtin-and-external-commands">Builtin and external commands&lt;/h2>
&lt;p>When we call a command in the shell, it usually searches in &lt;code>$PATH&lt;/code> for a matching one, executing the first that it finds.&lt;/p>
&lt;p>But for some command, usually the most used, the shell usually provide its own replacement; for example bash provides &lt;code>type&lt;/code>, &lt;code>cd&lt;/code> and &lt;code>test&lt;/code> (and many others). These commands are called &lt;em>shell builtins&lt;/em>. It means that if we call &lt;code>test&lt;/code>, bash &lt;code>test&lt;/code> implementation will be executed instead of &lt;code>/usr/bin/test&lt;/code>. &lt;code>type&lt;/code> cannot be called outside of bash because is a builtin and it doesn&amp;rsquo;t have a respective &lt;code>/usr/bin/type&lt;/code>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: in bash, you can know if a command is a builtin or not by using &lt;code>type&lt;/code> followed by the command.&lt;/em>&lt;/p>
&lt;p>So for the bash shell, we can say that everything we call is either a &lt;em>builtin&lt;/em> or a program in &lt;code>$PATH&lt;/code>. The latter are called external commands.&lt;/p>
&lt;p>&lt;code>execlineb&lt;/code> does not provide any builtin; instead, it provides its utilities (such as &lt;code>importas&lt;/code> and &lt;code>cd&lt;/code>) in &lt;code>$PATH&lt;/code>. We will call everything that is provided by &lt;code>execline&lt;/code> as builtin, and everything else an external command.&lt;/p>
&lt;h2 id="blocks">Blocks&lt;/h2>
&lt;p>&lt;code>execlineb&lt;/code> treats the arguments as one big &lt;code>argv&lt;/code>, but there are some cases where we need to extract two command lines from it. Blocks have this purpose.&lt;/p>
&lt;p>From the documentation&lt;sup id="fnref:4">&lt;a href="#fn:4" class="footnote-ref" role="doc-noteref">4&lt;/a>&lt;/sup>:&lt;/p>
&lt;blockquote>
&lt;p>execline commands that need more than one linear set of arguments use blocks.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>In &lt;code>execlineb&lt;/code> scripts, blocks are delimited by braces. They can be nested.&lt;/p>
&lt;/blockquote>
&lt;h2 id="redirection">Redirection&lt;/h2>
&lt;p>As you could guess, there is no redirection operator; instead &lt;code>execline&lt;/code> provides &lt;code>fdmove&lt;/code>&lt;sup id="fnref:5">&lt;a href="#fn:5" class="footnote-ref" role="doc-noteref">5&lt;/a>&lt;/sup> to move file descriptors&lt;sup id="fnref:6">&lt;a href="#fn:6" class="footnote-ref" role="doc-noteref">6&lt;/a>&lt;/sup> and &lt;code>redirfd&lt;/code>&lt;sup id="fnref:7">&lt;a href="#fn:7" class="footnote-ref" role="doc-noteref">7&lt;/a>&lt;/sup> to redirect a file descriptor to a file.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Integer value&lt;/th>
&lt;th>Name&lt;/th>
&lt;th>&amp;lt;stdio.h&amp;gt; file stream&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>0&lt;/td>
&lt;td>Standard input&lt;/td>
&lt;td>stdin&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>Standard output&lt;/td>
&lt;td>stdout&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>Standard error&lt;/td>
&lt;td>stderr&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>&lt;code>fdmove fdto fdfrom prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>fdmove&lt;/code> moves the file descriptor number &lt;code>fdfrom&lt;/code>, to number &lt;code>fdto&lt;/code>, then execs into &lt;code>prog&lt;/code> with its arguments.
&lt;code>-c&lt;/code> : duplicate &lt;code>fdfrom&lt;/code> to &lt;code>fdto&lt;/code> instead of moving it; do not close &lt;code>fdfrom&lt;/code>.&lt;/p>
&lt;/blockquote>
&lt;p>We don&amp;rsquo;t usually need to close the file descriptor, so the &lt;code>-c&lt;/code> flag is needed.&lt;/p>
&lt;p>To redirect &lt;code>stderr&lt;/code> to &lt;code>stdout&lt;/code> add the following before &lt;code>prog...&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>fdmove -c 2 1
&lt;/code>&lt;/pre>&lt;p>To redirect &lt;code>stdout&lt;/code> to &lt;code>stderr&lt;/code> invert the file descriptors above:&lt;/p>
&lt;pre tabindex="0">&lt;code>fdmove -c 1 2
&lt;/code>&lt;/pre>&lt;blockquote>
&lt;p>&lt;code>redirfd&lt;/code> redirects the file descriptor number &lt;code>fd&lt;/code> to file, then execs into &lt;code>prog...&lt;/code>.&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;dl>
&lt;dt>Options&lt;/dt>
&lt;dd>-r : open file for reading.&lt;/dd>
&lt;dd>-w : open file for writing, truncating it if it already exists.&lt;/dd>
&lt;dd>-a : open file for appending, creating it if it doesn&amp;rsquo;t exist.&lt;/dd>
&lt;/dl>
&lt;/blockquote>
&lt;dl>
&lt;dt>Shell equivalent&lt;/dt>
&lt;dd>&lt;code>redirfd -r n file prog...&lt;/code> is equivalent to &lt;code>prog... n&amp;lt; file&lt;/code>&lt;/dd>
&lt;dd>&lt;code>redirfd -w n file prog...&lt;/code> is equivalent to &lt;code>prog... n&amp;gt; file&lt;/code>&lt;/dd>
&lt;dd>&lt;code>redirfd -a n file prog...&lt;/code> is equivalent to &lt;code>prog... n&amp;gt;&amp;gt; file&lt;/code>&lt;/dd>
&lt;/dl>
&lt;p>To append the current date in a file in shell syntax, we would have done:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">date &amp;gt;&amp;gt; date_saved
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The equivalent in &lt;code>execlineb&lt;/code> scripting is:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">redirfd -a &lt;span class="m">1&lt;/span> date_saved
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">date
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>redirfd&lt;/code> can also be used to redirect a file descriptor to &lt;code>/dev/null&lt;/code>, discarding unwanted output:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">redirfd -w &lt;span class="m">1&lt;/span> /dev/null prog...
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="pipes">Pipes&lt;/h2>
&lt;p>Another feature used heavily by shell scripting languages are pipes&lt;sup id="fnref:8">&lt;a href="#fn:8" class="footnote-ref" role="doc-noteref">8&lt;/a>&lt;/sup>.
This is an example of pipes in &lt;code>execline&lt;/code>:&lt;/p>
&lt;pre tabindex="0">&lt;code>pipeline { ls }
wc -l
&lt;/code>&lt;/pre>&lt;p>&lt;code>pipeline&lt;/code> is builtin that take two linear argument, therefore blocks are used. It executes the chain load inside the block
and save its output. Then the second command line argument, that is &lt;code>wc -l&lt;/code> here, is executed and the saved output is used as input.&lt;/p>
&lt;p>This script display how many folders and files there are in the current directory.
The equivalent in bash would be:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="cp">#!/bin/sh
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cp">&lt;/span>ls &lt;span class="p">|&lt;/span> wc -l
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>We can also use the &lt;code>-w&lt;/code> flag to reverse the verse of the pipe. This is the pipe above looks like if we use &lt;code>-w&lt;/code> flag:&lt;/p>
&lt;pre tabindex="0">&lt;code>pipeline -w { wc -l }
ls
&lt;/code>&lt;/pre>&lt;p>Consider now three pipes one after another:&lt;/p>
&lt;pre tabindex="0">&lt;code># Returns all included headers in the current directory
pipeline { grep -R &amp;#34;#include &amp;lt;.*&amp;gt;&amp;#34; }
# sort the output of grep, uniq needs its input sorted
pipeline { sort }
# Remove all the results that appear twice
pipeline { uniq }
wc -l
&lt;/code>&lt;/pre>&lt;p>This script, which we will call &lt;code>uniq_results&lt;/code>, displays how many unique C/C++ headers are used in the current directory.&lt;/p>
&lt;h2 id="script-arguments">Script arguments&lt;/h2>
&lt;p>The string passed to grep is hardcoded, it means that the script usefulness is limited. To improve &lt;code>uniq_results&lt;/code> we will read and use
arguments passed to it.&lt;/p>
&lt;pre tabindex="0">&lt;code>#!/bin/execlineb -S1
# Gives us all the results in the current directory
pipeline { grep -R $1 }
# sort the output of grep, uniq needs its input sorted
pipeline { sort }
# Remove all the results that appear twice
pipeline { uniq }
wc -l
&lt;/code>&lt;/pre>&lt;p>&lt;code>$1&lt;/code> has taken the place of the hardcoded string: grep will search for whatever string we use as the script first argument. As in &lt;code>bash&lt;/code>, positional arguments are called by using &lt;code>$&lt;/code> followed by the number of the positional argument wanted.&lt;/p>
&lt;p>The last difference between this script and the previous one is in the shebang, where the flag &lt;code>-S nmin&lt;/code> has been added.
The latter tells &lt;code>execlineb&lt;/code> the minimum positional parameters that the script needs to run.&lt;/p>
&lt;p>Another useful flag is &lt;code>-s nmin&lt;/code>. It works like &lt;code>-S&lt;/code>, being &lt;code>$@&lt;/code> value the only difference:&lt;/p>
&lt;ul>
&lt;li>with &lt;code>-S&lt;/code>, it contains all arguments&lt;/li>
&lt;li>with &lt;code>-s&lt;/code>, it contains all arguments minus the first nmin&lt;/li>
&lt;/ul>
&lt;p>There are other powerful and flexible ways to handle positional parameters; &lt;code>execline&lt;/code> documentation explains them&lt;sup id="fnref:9">&lt;a href="#fn:9" class="footnote-ref" role="doc-noteref">9&lt;/a>&lt;/sup> in details. Have also a look at &lt;code>shift&lt;/code>&lt;sup id="fnref:10">&lt;a href="#fn:10" class="footnote-ref" role="doc-noteref">10&lt;/a>&lt;/sup> and &lt;code>dollarat&lt;/code>&lt;sup id="fnref:11">&lt;a href="#fn:11" class="footnote-ref" role="doc-noteref">11&lt;/a>&lt;/sup> programs.&lt;/p>
&lt;h2 id="multiple-execution">Multiple execution&lt;/h2>
&lt;p>We often need to execute external programs in a row, but &lt;code>execline&lt;/code> doesn&amp;rsquo;t allow the use of &lt;code>newlines&lt;/code>, that are considered whitespace, nor semicolons. It instead provides two different commands: &lt;code>foreground&lt;/code>&lt;sup id="fnref:12">&lt;a href="#fn:12" class="footnote-ref" role="doc-noteref">12&lt;/a>&lt;/sup> and &lt;code>background&lt;/code>&lt;sup id="fnref:13">&lt;a href="#fn:13" class="footnote-ref" role="doc-noteref">13&lt;/a>&lt;/sup>.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>foreground { prog1... } prog2...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>foreground&lt;/code> reads &lt;code>prog1&lt;/code> in a block. It executes it, waits for it to complete and then executes &lt;code>progs2&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>background { prog1... } prog2...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>background&lt;/code> reads a &lt;code>prog1...&lt;/code> command in a block, spawns a child executing &lt;code>prog1...&lt;/code> and then execs into &lt;code>prog2...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;p>Relating back to the &lt;code>sh&lt;/code> syntax:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;code>foreground { a } b&lt;/code> is the equivalent to &lt;code>a ; b&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;code>background { a } b&lt;/code> is the equivalent of &lt;code>a &amp;amp; v&lt;/code>&lt;/p>
&lt;/li>
&lt;/ul>
&lt;pre tabindex="0">&lt;code>foreground { sleep 10 }
echo &amp;#34;I waited 10 seconds.&amp;#34;
&lt;/code>&lt;/pre>&lt;p>This is an example where the script wait ten seconds and echo the message we choosed. &lt;code>foreground&lt;/code> can also be used several times in a row.&lt;/p>
&lt;h2 id="variable-management">Variable management&lt;/h2>
&lt;blockquote>
&lt;p>&lt;code>execline&lt;/code> maintains no state, and thus has no real variables&lt;/p>
&lt;/blockquote>
&lt;p>While somewhat of a misnomer, execline emulates variable management in other scripting languages via its substitution mechanism, which we will use in the next examples.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>define variable value prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>define&lt;/code> replaces the literal &lt;code>variable&lt;/code> with &lt;code>value&lt;/code>, then executes &lt;code>prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;p>&lt;code>define&lt;/code> remind us of an assignment operator, which is what it exactly does.&lt;/p>
&lt;pre tabindex="0">&lt;code>define home /home/foo
mkdir ${home}/scripts
&lt;/code>&lt;/pre>&lt;h3 id="variable-substitution">Variable Substitution&lt;/h3>
&lt;p>When a literal is followed by other strings, it needs to be wrapped inside curly braces; otherwise the &lt;code>execline&lt;/code> parser won&amp;rsquo;t apply substitution.&lt;/p>
&lt;p>The substitution will be applied here:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">define FOO blah
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> &lt;span class="nv">$FOO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>but won&amp;rsquo;t be applied here:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">define FOO blah
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> &lt;span class="nv">$FOO&lt;/span>-&lt;span class="nv">$FOO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>because the first literal must be wrapped inside the braces:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">define FOO blah
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> &lt;span class="si">${&lt;/span>&lt;span class="nv">FOO&lt;/span>&lt;span class="si">}&lt;/span>-&lt;span class="nv">$FOO&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: in &lt;code>$FOO$FOO&lt;/code> both variables will be substituted.&lt;/em>&lt;/p>
&lt;h4 id="quoting">Quoting&lt;/h4>
&lt;blockquote>
&lt;p>the following is the most complex part of the whole language&lt;/p>
&lt;/blockquote>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: Feel free to skip this paragraph if you don&amp;rsquo;t intend to use the quoting mechanism.&lt;/em>&lt;/p>
&lt;p>There are two possible cases: the variable is either substituted or not substituted. Both will be highlighted here, in order.&lt;/p>
&lt;blockquote>
&lt;p>if &lt;code>${FOO}&lt;/code> is preceded by &lt;code>2*n&lt;/code> backslashes (an even number), the whole sequence will be replaced with &lt;code>n&lt;/code> backslashes, followed by the substituted value.&lt;/p>
&lt;/blockquote>
&lt;p>As an example, consider the following script:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">define FOO blah
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> &lt;span class="se">\\&lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nv">FOO&lt;/span>&lt;span class="si">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>If &lt;code>${FOO}&lt;/code> is preceded by &lt;code>2*n+1&lt;/code> backslashes (an odd number), the whole sequence will be replaced with &lt;code>n&lt;/code> backslashes, followed by the literal &lt;code>${FOO}&lt;/code>.&lt;/p>
&lt;/blockquote>
&lt;p>Consider again the script above, this time with an odd number of backlashes:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">define FOO blah
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> &lt;span class="se">\$&lt;/span>&lt;span class="o">{&lt;/span>FOO&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>${FOO}&lt;/code> will not be substituted and its output will be &lt;code>${FOO}&lt;/code> literal. If we used three backlash (&lt;code>2*n + 1&lt;/code> with &lt;code>n=1&lt;/code>), the output would be &lt;code>\${FOO}&lt;/code>, that is &lt;code>n&lt;/code> backslashes and the literal.&lt;/p>
&lt;p>&lt;code>${FOO}&lt;/code> will be substituted with its value, and the &lt;code>2*n&lt;/code> (where &lt;code>n=1&lt;/code> in the example) backlashes will be substituted with &lt;code>n&lt;/code> backlashes.&lt;/p>
&lt;h3 id="environmental-variables">Environmental variables&lt;/h3>
&lt;p>Since execline takes heavy advantage of chainloading, we can use the environment as a true variable store, as we have already seen with &lt;code>importas&lt;/code>.&lt;/p>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: environment variables are real variables, they are just external to the substitution mechanism until brought in via &lt;code>importas&lt;/code> (or an execline utility that does automatic substitution).&lt;/em>&lt;/p>
&lt;p>We used &lt;code>define&lt;/code> to emulate the assignment operator, assigning a value to a literal; thus this value cannot be calculated at runtime. If we need to assign the output of a command to a variable, we should use the environment instead.&lt;/p>
&lt;p>&lt;code>backtick&lt;/code>&lt;sup id="fnref:14">&lt;a href="#fn:14" class="footnote-ref" role="doc-noteref">14&lt;/a>&lt;/sup> is the builtin used to set an envorimental variable from another command output:&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>backtick variable { prog1... } prog2...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>&lt;code>backtick&lt;/code> reads &lt;code>prog1...,&lt;/code> spawns a child executing it and saves its output, then it assigns this output to &lt;code>variable&lt;/code> in the environment.&lt;/p>
&lt;/blockquote>
&lt;p>Suppose we have to create a file named as the current date, and this file should be store inside the &lt;code>.cache&lt;/code> folder of the user calling the script:&lt;/p>
&lt;pre tabindex="0">&lt;code># Get the date and store it inside DATE variable
backtick DATE { date +%d%m%y }
# Import DATE var from environment into date literal
importas date DATE
# Do the same for HOME
importas home HOME
# Create the file
touch ${home}/.cache/used-$date
&lt;/code>&lt;/pre>&lt;h2 id="conditional-execution">Conditional execution&lt;/h2>
&lt;p>Another thing that we often do is a testing a condition and doing different things depending on its result (or exit code in shell scripting). In another words we execute something in case the condition was false, something else if it was true.&lt;/p>
&lt;p>&lt;code>exeline&lt;/code> provides four different builtins: &lt;code>if&lt;/code>&lt;sup id="fnref:15">&lt;a href="#fn:15" class="footnote-ref" role="doc-noteref">15&lt;/a>&lt;/sup>, &lt;code>ifelse&lt;/code>&lt;sup id="fnref:16">&lt;a href="#fn:16" class="footnote-ref" role="doc-noteref">16&lt;/a>&lt;/sup>, &lt;code>ifte&lt;/code>&lt;sup id="fnref:17">&lt;a href="#fn:17" class="footnote-ref" role="doc-noteref">17&lt;/a>&lt;/sup> and &lt;code>ifthenelse&lt;/code>&lt;sup id="fnref:18">&lt;a href="#fn:18" class="footnote-ref" role="doc-noteref">18&lt;/a>&lt;/sup>. In this tutorial we will only see the first two.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>if { prog1... } prog2..&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;p>if reads prog1&amp;hellip; in a block. It executes it, wait for it to complete and then:&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;ul>
&lt;li>If &lt;code>prog1&lt;/code> exits a non-zero status, &lt;code>if&lt;/code> exits 1.&lt;/li>
&lt;li>Else &lt;code>if&lt;/code> execs into &lt;code>prog2&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>This is a simple builtin, it just execute a program, that could also be a chain loads of programs, and then continue with the script execution only if the exit status is zero.&lt;/p>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: to test that a file exists the POSIX utility &lt;code>test&lt;/code>&lt;sup id="fnref:19">&lt;a href="#fn:19" class="footnote-ref" role="doc-noteref">19&lt;/a>&lt;/sup> will be used in the following examples.&lt;/em>&lt;/p>
&lt;pre tabindex="0">&lt;code>importas home HOME
if -n { test -d ${home}/.cache/used }
mkdir ${home}/.cache/used
&lt;/code>&lt;/pre>&lt;p>This is a simple script that check if the directory &lt;code>~/.cache/used&lt;/code> exists, if it doesn&amp;rsquo;t there is an attempt to create it. We would also need sometimes to check if &lt;code>mkdir&lt;/code> successfully exit and it can do done by wrapping the last line with another &lt;code>if&lt;/code>.&lt;/p>
&lt;p>We negate the result of the &lt;code>if&lt;/code> block, hence the &lt;code>-n&lt;/code> flag:&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>-n&lt;/code> : negate the test (exit on true, exec into &lt;code>prog2&lt;/code> on false)&lt;/p>
&lt;/blockquote>
&lt;p>By wrapping the &lt;code>if&lt;/code> with a &lt;code>foreground&lt;/code> call, we can execute the rest of the script, regardless of the result of the first block executed by the&lt;code>if&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">importas home HOME
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">foreground &lt;span class="o">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> -n &lt;span class="o">{&lt;/span> &lt;span class="nb">test&lt;/span> -d &lt;span class="si">${&lt;/span>&lt;span class="nv">home&lt;/span>&lt;span class="si">}&lt;/span>/.cache/used &lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> mkdir &lt;span class="si">${&lt;/span>&lt;span class="nv">home&lt;/span>&lt;span class="si">}&lt;/span>/.cache/used
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="o">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># This line will be executed regardless of the exit status in the if above&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">echo&lt;/span> The script finished the execution
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Let&amp;rsquo;s improve the scripts above: we create the directory &lt;code>~/.cache/used&lt;/code> if it does not exist, and then we create a file with the current date in this directory. The script exit with code 1 if a file with the same date has already been created. We will use &lt;code>ifelse&lt;/code>&lt;sup id="fnref:20">&lt;a href="#fn:20" class="footnote-ref" role="doc-noteref">20&lt;/a>&lt;/sup>:&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>ifelse { prog1... } { prog2... } prog3...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;ul>
&lt;li>ifelse reads prog1&amp;hellip;, it forks and executes it, then waits for it to complete.&lt;/li>
&lt;li>If &lt;code>prog1&lt;/code> exits with a return code equal to 0, &lt;code>ifelse&lt;/code> execs into &lt;code>prog2&lt;/code>.&lt;/li>
&lt;li>Else &lt;code>ifelse&lt;/code> execs into &lt;code>prog3&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;pre tabindex="0">&lt;code>importas home HOME
foreground
{
if -n { test -d ${home}/.cache/used }
mkdir ${home}/.cache/used
}
backtick DATE { date +%d%m%y }
importas date DATE
ifelse -n
# Run this block and check its exit code
{
test -d ${home}/.cache/used/$date
}
# If the previous block exit with non zero code then
# this block is executed (because of the -n flag in ifelse)
{
touch ${home}/.cache/used/$date
}
# Else the script continues here
exit 1
&lt;/code>&lt;/pre>&lt;h2 id="iteration">Iteration&lt;/h2>
&lt;p>&lt;code>loopwhilex&lt;/code>&lt;sup id="fnref:21">&lt;a href="#fn:21" class="footnote-ref" role="doc-noteref">21&lt;/a>&lt;/sup> is the &lt;code>execline&lt;/code> equivalent of &lt;code>while&lt;/code>:&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>loopwhilex prog...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;ul>
&lt;li>&lt;code>loopwhilex&lt;/code> runs &lt;code>prog...&lt;/code> as a child process and waits for it to complete.&lt;/li>
&lt;li>As long as prog exits zero, loopwhile runs it again.&lt;/li>
&lt;li>&lt;code>loopwhilex&lt;/code> then exits with the last &lt;code>prog&lt;/code> invocation&amp;rsquo;s exit code.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>Since this is pretty straightforward, we will skip an example and we will instead focus on &lt;code>forstdin&lt;/code>&lt;sup id="fnref:22">&lt;a href="#fn:22" class="footnote-ref" role="doc-noteref">22&lt;/a>&lt;/sup> and &lt;code>forbacktickx&lt;/code>&lt;sup id="fnref:23">&lt;a href="#fn:23" class="footnote-ref" role="doc-noteref">23&lt;/a>&lt;/sup>, which are the &lt;code>execline&lt;/code> equivalent of &lt;code>for&lt;/code> construction.&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>forstdin variable loop...&lt;/code>&lt;/p>
&lt;/blockquote>
&lt;blockquote>
&lt;ul>
&lt;li>&lt;code>forstdin&lt;/code> reads its standard input, splitting it automatically.&lt;/li>
&lt;li>For every argument &lt;code>x&lt;/code> in the split output, &lt;code>forstdin&lt;/code> runs &lt;code>loop...&lt;/code> as a child process, with &lt;code>variable=x&lt;/code> added to its environment.&lt;/li>
&lt;/ul>
&lt;/blockquote>
&lt;p>We have to remember that, even if the variable is added to the environment, we still need to import it in a literal, using &lt;code>importas&lt;/code>&lt;sup id="fnref:24">&lt;a href="#fn:24" class="footnote-ref" role="doc-noteref">24&lt;/a>&lt;/sup>, this time adding &lt;code>-u&lt;/code> flag:&lt;/p>
&lt;blockquote>
&lt;p>&lt;code>-u&lt;/code> : Unexport. &lt;code>envvar&lt;/code> will be removed from the environment after the substitution.&lt;/p>
&lt;/blockquote>
&lt;p>&lt;em>&lt;strong>Note&lt;/strong>: &lt;code>forstdin&lt;/code> reads from the standard input, so &lt;code>pipeline&lt;/code> is needed here.&lt;/em>&lt;/p>
&lt;pre tabindex="0">&lt;code># Print all the files and directory, and use them as
# input for the next program
pipeline { ls }
# For every files and directory printed,
# execute the following block, after replacing FOLDER
# with the name of file/directory
forstdin FOLDER
# Import the environmental variable into the literal folder
importas -u folder FOLDER
# Check if it is a folder, so we skip files
if { test -d $folder }
# Create the empty file
touch ${folder}/active
&lt;/code>&lt;/pre>&lt;p>This script create an empty file named active for each folder in the current directory.&lt;/p>
&lt;p>Using &lt;code>forbacktickx&lt;/code> instead, the script above could have been written like this:&lt;/p>
&lt;pre tabindex="0">&lt;code>forbacktickx FOLDER
{
ls
}
# Import the environmental variable into the literal folder
importas -u folder FOLDER
# Check if it is a folder, so we skip files
if { test -d $folder }
# Create the empty file
touch ${folder}/active
&lt;/code>&lt;/pre>&lt;h2 id="ambivalent-block-syntax">Ambivalent block syntax&lt;/h2>
&lt;p>There are two ways to describe a block; the first is curly braces, and this is the one that we&amp;rsquo;ve used in this tutorial.&lt;/p>
&lt;p>The second is to delimit only the end of a block with &lt;code>&amp;quot;&amp;quot;&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code>pipeline { ls } wc -l
&lt;/code>&lt;/pre>&lt;p>is equivalent to&lt;/p>
&lt;pre tabindex="0">&lt;code>pipeline ls &amp;#34;&amp;#34; wc -l
&lt;/code>&lt;/pre>&lt;h2 id="ending">Ending&lt;/h2>
&lt;p>Thank you for reading this getting started tutorial for this interesting scripting language.&lt;/p>
&lt;p>The great and complete documentation&lt;sup id="fnref:25">&lt;a href="#fn:25" class="footnote-ref" role="doc-noteref">25&lt;/a>&lt;/sup> references other programs provided and a deep explanation of the design and the grammar&lt;sup id="fnref:26">&lt;a href="#fn:26" class="footnote-ref" role="doc-noteref">26&lt;/a>&lt;/sup>.&lt;/p>
&lt;p>You can find some &lt;code>execline&lt;/code> scripts in the &lt;code>s6-rc&lt;/code> example services&lt;sup id="fnref:27">&lt;a href="#fn:27" class="footnote-ref" role="doc-noteref">27&lt;/a>&lt;/sup> and in the s6-rc services&lt;sup id="fnref:28">&lt;a href="#fn:28" class="footnote-ref" role="doc-noteref">28&lt;/a>&lt;/sup> used in Exherbo.&lt;/p>
&lt;p>EDIT: Thanks to Cogitri&lt;sup id="fnref:29">&lt;a href="#fn:29" class="footnote-ref" role="doc-noteref">29&lt;/a>&lt;/sup> and Heliocat&lt;sup id="fnref:30">&lt;a href="#fn:30" class="footnote-ref" role="doc-noteref">30&lt;/a>&lt;/sup> for their suggestions on improving this guide.&lt;/p>
&lt;div class="footnotes" role="doc-endnotes">
&lt;hr>
&lt;ol>
&lt;li id="fn:1">
&lt;p>&lt;a href="http://skarnet.org/software/execline/dieshdiedie.html">http://skarnet.org/software/execline/dieshdiedie.html&lt;/a>&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:2">
&lt;p>&lt;a href="http://skarnet.org/software/s6/">http://skarnet.org/software/s6/&lt;/a>&amp;#160;&lt;a href="#fnref:2" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:3">
&lt;p>&lt;a href="http://skarnet.org/software/s6-rc/">http://skarnet.org/software/s6-rc/&lt;/a>)&amp;#160;&lt;a href="#fnref:3" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:4">
&lt;p>&lt;a href="https://skarnet.org/software/execline/el_semicolon.html">https://skarnet.org/software/execline/el_semicolon.html&lt;/a>&amp;#160;&lt;a href="#fnref:4" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:5">
&lt;p>&lt;a href="http://skarnet.org/software/execline/fdmove.html">http://skarnet.org/software/execline/fdmove.html&lt;/a>&amp;#160;&lt;a href="#fnref:5" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:6">
&lt;p>&lt;a href="https://en.wikipedia.org/wiki/File_descriptor">https://en.wikipedia.org/wiki/File_descriptor&lt;/a>&amp;#160;&lt;a href="#fnref:6" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:7">
&lt;p>&lt;a href="http://skarnet.org/software/execline/fdmove.html">http://skarnet.org/software/execline/fdmove.html&lt;/a>&amp;#160;&lt;a href="#fnref:7" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:8">
&lt;p>&lt;a href="http://www.linfo.org/pipe.html">http://www.linfo.org/pipe.html&lt;/a>&amp;#160;&lt;a href="#fnref:8" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:9">
&lt;p>&lt;a href="http://skarnet.org/software/execline/el_pushenv.html">http://skarnet.org/software/execline/el_pushenv.html&lt;/a>&amp;#160;&lt;a href="#fnref:9" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:10">
&lt;p>&lt;a href="http://skarnet.org/software/execline/shift.html">http://skarnet.org/software/execline/shift.html&lt;/a>&amp;#160;&lt;a href="#fnref:10" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:11">
&lt;p>&lt;a href="http://skarnet.org/software/execline/dollarat.html">http://skarnet.org/software/execline/dollarat.html&lt;/a>&amp;#160;&lt;a href="#fnref:11" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:12">
&lt;p>&lt;a href="http://skarnet.org/software/execline/foreground.html">http://skarnet.org/software/execline/foreground.html&lt;/a>&amp;#160;&lt;a href="#fnref:12" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:13">
&lt;p>&lt;a href="http://skarnet.org/software/execline/background.html">http://skarnet.org/software/execline/background.html&lt;/a>&amp;#160;&lt;a href="#fnref:13" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:14">
&lt;p>&lt;a href="http://skarnet.org/software/execline/backtick.html">http://skarnet.org/software/execline/backtick.html&lt;/a>&amp;#160;&lt;a href="#fnref:14" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:15">
&lt;p>&lt;a href="http://skarnet.org/software/execline/if.html">http://skarnet.org/software/execline/if.html&lt;/a>&amp;#160;&lt;a href="#fnref:15" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:16">
&lt;p>&lt;a href="http://skarnet.org/software/execline/ifelse.html">http://skarnet.org/software/execline/ifelse.html&lt;/a>&amp;#160;&lt;a href="#fnref:16" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:17">
&lt;p>&lt;a href="http://skarnet.org/software/execline/ifte.html">http://skarnet.org/software/execline/ifte.html&lt;/a>&amp;#160;&lt;a href="#fnref:17" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:18">
&lt;p>&lt;a href="http://skarnet.org/software/execline/ifthenelse.html">http://skarnet.org/software/execline/ifthenelse.html&lt;/a>&amp;#160;&lt;a href="#fnref:18" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:19">
&lt;p>&lt;a href="https://www.computerhope.com/unix/test.htm">https://www.computerhope.com/unix/test.htm&lt;/a>&amp;#160;&lt;a href="#fnref:19" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:20">
&lt;p>&lt;a href="http://skarnet.org/software/execline/ifelse.html">http://skarnet.org/software/execline/ifelse.html&lt;/a>&amp;#160;&lt;a href="#fnref:20" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:21">
&lt;p>&lt;a href="http://skarnet.org/software/execline/loopwhilex.html">http://skarnet.org/software/execline/loopwhilex.html&lt;/a>&amp;#160;&lt;a href="#fnref:21" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:22">
&lt;p>&lt;a href="http://skarnet.org/software/execline/forstdin.html">http://skarnet.org/software/execline/forstdin.html&lt;/a>&amp;#160;&lt;a href="#fnref:22" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:23">
&lt;p>&lt;a href="http://skarnet.org/software/execline/forbacktickx.html">http://skarnet.org/software/execline/forbacktickx.html&lt;/a>&amp;#160;&lt;a href="#fnref:23" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:24">
&lt;p>&lt;a href="http://skarnet.org/software/execline/importas.html">http://skarnet.org/software/execline/importas.html&lt;/a>&amp;#160;&lt;a href="#fnref:24" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:25">
&lt;p>&lt;a href="http://skarnet.org/software/execline/">http://skarnet.org/software/execline/&lt;/a>&amp;#160;&lt;a href="#fnref:25" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:26">
&lt;p>&lt;a href="http://skarnet.org/software/execline/grammar.html">http://skarnet.org/software/execline/grammar.html&lt;/a>&amp;#160;&lt;a href="#fnref:26" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:27">
&lt;p>&lt;a href="https://github.com/skarnet/s6-rc/tree/master/examples/source">https://github.com/skarnet/s6-rc/tree/master/examples/source&lt;/a>&amp;#160;&lt;a href="#fnref:27" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:28">
&lt;p>&lt;a href="https://gitlab.exherbo.org/exherbo-misc/s6-exherbo">https://gitlab.exherbo.org/exherbo-misc/s6-exherbo&lt;/a>&amp;#160;&lt;a href="#fnref:28" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:29">
&lt;p>&lt;a href="https://github.com/Cogitri">https://github.com/Cogitri&lt;/a>&amp;#160;&lt;a href="#fnref:29" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;li id="fn:30">
&lt;p>&lt;a href="http://heliocat.net/">http://heliocat.net/&lt;/a>&amp;#160;&lt;a href="#fnref:30" class="footnote-backref" role="doc-backlink">&amp;#x21a9;&amp;#xfe0e;&lt;/a>&lt;/p>
&lt;/li>
&lt;/ol>
&lt;/div></description></item><item><title>Termish[2] = yadm</title><link>https://danyspin97.org/blog/termish2-yadm/</link><pubDate>Tue, 10 Apr 2018 15:30:18 +0200</pubDate><guid>https://danyspin97.org/blog/termish2-yadm/</guid><description>&lt;p>&lt;em>Dotfiles&lt;/em>: the files whom dictate pretty much anything on your workstation,
from vi[m] behavior to desktop customization. If you had never heard of
dotfiles or you&amp;rsquo;re not familiar with their concept,
&lt;a href="https://askubuntu.com/questions/94780/what-are-dot-files">this&lt;/a> is a little explanation.&lt;/p>
&lt;p>But what if your laptop and data got lost? Rewrite everything from scratch would be a real hell: indeed they are usually stored on Github or whatever so that restoring or porting to a fresh install requires just 2 clicks.&lt;/p>
&lt;p>It seems simple, doesn&amp;rsquo;t it? Well, it is. And simple problems can be resolved in a dozen of different ways. Dotfiles make no difference: people have distinct way to manage configuration files (&lt;a href="https://dotfiles.github.com/index.html#general-purpose-dotfile-utilities">this&lt;/a> is only a glance) and use from symlinks to rsync and everything in between.&lt;/p>
&lt;h2 id="yet-another-dotfiles-manager">Yet Another Dotfiles Manager&lt;/h2>
&lt;p>Yadm is a simple program: there are no symlinks and it doesn&amp;rsquo;t use rsync either. It just clone your repository into your home and let you use git commands to manage it. Yea, you can commit, merge and whatever from yadm.&lt;/p>
&lt;h2 id="how-it-works">How it works&lt;/h2>
&lt;script src="https://asciinema.org/a/168409.js" id="asciicast-168409" async>&lt;/script>
&lt;p>At the first call you can either clone the remote repository or init a new one, then you can use all git commands, from commit to rebase.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">yadm init
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">yadm add &amp;lt;your dotfiles&amp;gt;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">yadm commit
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Adding a remote repository and pushing to it its trivial, so I&amp;rsquo;ll skip it (you can find more in the &lt;a href="https://thelocehiliosan.github.io/yadm/docs/getting_started">getting started&lt;/a> of the official documentation).
Instead, let&amp;rsquo;s focus on specific features of yadm, like encryption and alternate files.&lt;/p>
&lt;h3 id="encryption">&lt;a href="https://thelocehiliosan.github.io/yadm/docs/encryption">Encryption&lt;/a>&lt;/h3>
&lt;p>Both symmetric and asymmetric encryption can be used, with symmetric as default. It is a pretty simple method, with all files encrypted together, and it&amp;rsquo;s perfect for sensible data like ssh or OpenGPG keys. However, pushing sensible data to a public repository, even if encrypted, is &lt;em>discouraged&lt;/em>.&lt;/p>
&lt;h3 id="alternate-files">&lt;a href="https://thelocehiliosan.github.io/yadm/docs/alternates">Alternate files&lt;/a>&lt;/h3>
&lt;p>Alternate files are a powerful way to have the same dotfiles in different computers that may run different Os or need only a different &lt;code>.bashrc&lt;/code>. You can use up to 4 different matches (&lt;em>CLASS&lt;/em>, &lt;em>OS&lt;/em>, &lt;em>HOSTNAME&lt;/em>, &lt;em>USER&lt;/em>) to differentiate your files.&lt;/p>
&lt;h3 id="bootstrap">&lt;a href="https://thelocehiliosan.github.io/yadm/docs/bootstrap">Bootstrap&lt;/a>&lt;/h3>
&lt;p>You are installing dotfiles but you also want to install all vim plugins so you don&amp;rsquo;t have to do it manually? Bootstrap is the perfect tool for the job. It will execute commands right after the dotfiles repositories has been cloned.&lt;/p>
&lt;h2 id="features">Features&lt;/h2>
&lt;ul>
&lt;li>No symlinks&lt;/li>
&lt;li>Few dependencies&lt;/li>
&lt;li>Alternate files between hosts&lt;/li>
&lt;li>Encryption&lt;/li>
&lt;li>Use git internally&lt;/li>
&lt;/ul>
&lt;h2 id="installation">Installation&lt;/h2>
&lt;p>&lt;a href="https://thelocehiliosan.github.io/yadm/">yadm&lt;/a> is available in almost every distro.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>&lt;a href="https://thelocehiliosan.github.io/yadm/">yadm&lt;/a> is a reliable program that will manage your dotfiles with as little effort as possible, both if you&amp;rsquo;re an advanced user or a novice. Its commands are the same as git, which mean you don&amp;rsquo;t need to learn everything new. Its encrypt, alternate and boostrap features make it flexible and powerful. If you need a tool to manage dotfiles, this is definitely the best.&lt;/p></description></item><item><title>Termish[1] = ddgr</title><link>https://danyspin97.org/blog/termish1-ddgr/</link><pubDate>Sun, 25 Feb 2018 10:32:38 +0100</pubDate><guid>https://danyspin97.org/blog/termish1-ddgr/</guid><description>&lt;p>What is the most common thing we do each day? We browse the internet using a search engine, from &lt;em>&lt;a href="https://google.com">Google&lt;/a>&lt;/em> to &lt;em>&lt;a href="https://duckduckgo.com">DuckDuckGo&lt;/a>&lt;/em>.&lt;/p>
&lt;p>But what&amp;rsquo;s the process?&lt;/p>
&lt;p>Open the browser, fire up the search and wait for results; then take the mouse and click on it, or if there is some vim-like plugin installed, press f and wait for popups.&lt;/p>
&lt;p>It is too long for something we do so often, isn&amp;rsquo;t it?&lt;/p>
&lt;p>There are two different terminal utilities which improve this simple course of action, respectively for &lt;em>&lt;a href="https://google.com">Google&lt;/a>&lt;/em> and &lt;em>&lt;a href="https://duckduckgo.com">DuckDuckGo&lt;/a>&lt;/em> : &lt;strong>&lt;a href="https://github.com/jarun/googler">googler&lt;/a>&lt;/strong> and &lt;strong>&lt;a href="https://github.com/jarun/ddgr">ddgr&lt;/a>&lt;/strong>. &lt;/br> We are going to talk about the latter.&lt;/p>
&lt;h2 id="overview">Overview&lt;/h2>
&lt;p>&lt;em>&lt;a href="https://github.com/jarun/ddgr">ddgr&lt;/a>&lt;/em> is a python3 script, ~1800 lines of code as of version &lt;code>1.2&lt;/code>, which take your query and show you the results. It doesn&amp;rsquo;t waste &lt;em>precious&lt;/em> space on your screen: there are only your prompt and you.&lt;/p>
&lt;h3 id="how-it-works">How it works&lt;/h3>
&lt;p>There are two ways to call &lt;em>ddgr&lt;/em>: with or without the search query as an argument. Both lead to the prompt, which is called &lt;em>omniprompt&lt;/em>, where you can:&lt;/p>
&lt;ul>
&lt;li>select an index to open a result&lt;/li>
&lt;li>choose to open either in a text-based or GUI browser&lt;/li>
&lt;li>go back and forth between the result pages&lt;/li>
&lt;li>use DuckDuckGo &lt;em>&lt;a href="https://duckduckgo.com/bang">bangs&lt;/a>&lt;/em> or site specific search&lt;/li>
&lt;/ul>
&lt;/br>
If you call the utility without the search query, you'll need to insert it afterwards and you cannot take advantage of the various search options, like "I'm feeling Ducky" or time based search. However, this way it can be easily called from a window manager like i3/Sway:
&lt;pre tabindex="0">&lt;code class="language-i3" data-lang="i3">bindsym $mod+c exec alacritty -e ddgr
&lt;/code>&lt;/pre>&lt;/br>
But lets _ddgr_ talk for itself. Here's an asciinema:
&lt;script src="https://asciinema.org/a/151849.js" id="asciicast-151849" async>&lt;/script>
&lt;h3 id="features">Features&lt;/h3>
&lt;p>Quoting the exhaustive list of &lt;a href="https://github.com/jarun/ddgr#features">features&lt;/a> from readme:&lt;/p>
&lt;ul>
&lt;li>Fast and clean (no ads, stray URLs or clutter), custom color&lt;/li>
&lt;li>Designed to deliver maximum readability at minimum space&lt;/li>
&lt;li>Specify the number of search results to show per page&lt;/li>
&lt;li>Navigate result pages from omniprompt, open URLs in browser&lt;/li>
&lt;li>Search and option completion scripts for Bash, Zsh and Fish&lt;/li>
&lt;li>DuckDuckGo Bang support (along with completion)&lt;/li>
&lt;li>Open the first result directly in browser (as in I&amp;rsquo;m Feeling Ducky)&lt;/li>
&lt;li>Non-stop searches: fire new searches at omniprompt without exiting&lt;/li>
&lt;li>Keywords (e.g. filetype:mime, site:somesite.com) support&lt;/li>
&lt;li>Limit search by time, specify region, disable safe search&lt;/li>
&lt;li>HTTPS proxy support, Do Not Track set, optionally disable User Agent&lt;/li>
&lt;li>Support custom url handler script or cmdline utility&lt;/li>
&lt;li>Comprehensive documentation, man page with handy usage examples&lt;/li>
&lt;li>Minimal dependencies&lt;/li>
&lt;/ul>
&lt;h3 id="installation">Installation&lt;/h3>
&lt;p>&lt;em>&lt;a href="https://github.com/jarun/ddgr">ddgr&lt;/a>&lt;/em> is available pretty much in every distro as shown &lt;a href="https://github.com/jarun/ddgr#from-a-package-manager">here&lt;/a>.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>&lt;em>&lt;a href="https://github.com/jarun/ddgr">ddgr&lt;/a>&lt;/em> is really a must for people who use DuckDuckGo and want a clean terminal utility; it worked flawlessly for me in the past months, both in features and stability. Plus, it can encode the results in JSON format, making effortless the implementation in other scripts.&lt;/p></description></item><item><title>Termish[0] = ncpamixer</title><link>https://danyspin97.org/blog/termish0-ncpamixer/</link><pubDate>Mon, 05 Feb 2018 14:40:52 +0100</pubDate><guid>https://danyspin97.org/blog/termish0-ncpamixer/</guid><description>&lt;p>Welcome to the first post of &lt;em>Termish&lt;/em>. Please, read what this is about
&lt;a href="https://danyspin97.org/blog/termish--malloc255--size/">here&lt;/a>, if you haven&amp;rsquo;t already.&lt;/p>
&lt;p>Let&amp;rsquo;s talk about &lt;em>PulseAudio&lt;/em>, a popular sound server that is widely used in
Linux Desktop for its features out of the box. If you don&amp;rsquo;t know which your
system audio service is, probably there is PulseAudio running (considering
that even Firefox use it as default on Linux from version &lt;a href="https://www.bleepingcomputer.com/news/software/some-firefox-52-users-on-linux-left-without-sound/">52&lt;/a>).&lt;/p>
&lt;p>How can we control audio input/output and raise volume? There is a graphical
interface, &lt;em>pavucontrol&lt;/em>, which accomplish those easily.&lt;/p>
&lt;br/>
&lt;p>
&lt;img src="https://danyspin97.org/img/pavucontrol.png" alt="pavucontrol">
&lt;/p>
&lt;br/>
&lt;p>Is there a lightweight alternative to pavucontrol? Something like &lt;a href="https://en.wikipedia.org/wiki/Alsamixer">alsamixer&lt;/a>
to use from our beloved terminal? Well, yes; its name is &lt;em>&lt;a href="https://github.com/fulhax/ncpamixer">ncpamixer&lt;/a>&lt;/em>.&lt;/p>
&lt;p>ncpamixer, which stands for &lt;em>ncurses PulseAudio Mixer&lt;/em>, offers basic
PulseAudio server control from a terminal interface; even more, there is a
customizable shortcut for anything.&lt;/p>
&lt;br/>
&lt;p>
&lt;img src="https://danyspin97.org/img/ncpamixer.gif" alt="ncpamixer">
&lt;/p>
&lt;br/>
&lt;p>At a first glance it really seems to use pavucontrol from the terminal, in
fact the README says:&lt;/p>
&lt;blockquote>
&lt;p>An ncurses mixer for PulseAudio inspired by pavucontrol.&lt;/p>
&lt;/blockquote>
&lt;h2 id="features">Features&lt;/h2>
&lt;p>&lt;em>ncpamixer&lt;/em> implements the following features:&lt;/p>
&lt;ul>
&lt;li>&lt;em>per&lt;/em> application volume changing&lt;/li>
&lt;li>devices monitoring and configuration&lt;/li>
&lt;li>granular input and output control&lt;/li>
&lt;/ul>
&lt;p>However, it cannot do (but &lt;em>pavucontrol&lt;/em> can):&lt;/p>
&lt;ul>
&lt;li>change latency offset&lt;/li>
&lt;li>do any advanced configuration&lt;/li>
&lt;li>filter applications by category&lt;/li>
&lt;/ul>
&lt;h2 id="installation">Installation&lt;/h2>
&lt;p>If you want to give it a try, &lt;a href="https://github.com/fulhax/ncpamixer#install">these&lt;/a> are the installation instructions.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>&lt;em>ncpamixer&lt;/em> is not a drop-in replacement for its GTK+ counterpart, but it&amp;rsquo;s
suitable for everyday usage: it is perfect to use along with a window manager
and a shortcut assigned (I personally use super+p).&lt;/p>
&lt;h2 id="related-links">Related links&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://github.com/fulhax/ncpamixer">ncpamixer&lt;/a>&lt;/li>
&lt;li>&lt;a href="(https://www.reddit.com/r/commandline/comments/7vey2x/termish0_ncpamixer/?ref=share&amp;amp;ref_source=link)">/r/commandline thread&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://freedesktop.org/software/pulseaudio/pavucontrol/">pavucontrol&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://en.wikipedia.org/wiki/Alsamixer">alsamixer&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Termish = malloc(255 * size)</title><link>https://danyspin97.org/blog/termish-malloc255-size/</link><pubDate>Wed, 31 Jan 2018 00:07:46 +0100</pubDate><guid>https://danyspin97.org/blog/termish-malloc255-size/</guid><description>&lt;p>This is the preface for a series of post on terminal apps, called &lt;strong>Termish&lt;/strong>.&lt;/p>
&lt;p>But &lt;em>why&lt;/em>?&lt;/p>
&lt;p>I love staying in the terminal. A lot of things are faster to do and I don&amp;rsquo;t
have to move my hands away from keyboard every now and then.&lt;/p>
&lt;p>The problem is: we don&amp;rsquo;t always have the right tool to use.
Plus, a lot of goodies don&amp;rsquo;t have visibility.
We will explore these programs covering a great range of
categories, including a usage example for each one.&lt;/p>
&lt;p>As an &lt;em>Exherbo&lt;/em> user, all the programs discussed will be available, so you can
test them out. Also, fellow users will add these packages in &lt;em>Gentoo&lt;/em> and
&lt;em>Sabotage&lt;/em>. I bet that the &lt;em>AUR&lt;/em> already have them all.&lt;/p>
&lt;p>Please, feel free to comment and propose apps on &lt;em>Mastodon&lt;/em> and &lt;em>Reddit&lt;/em>,
where all the articles will be posted.&lt;/p>
&lt;p>In the meanwhile&amp;hellip;take this nyancat.&lt;/p>
&lt;script src="https://asciinema.org/a/160022.js" id="asciicast-160022" async>&lt;/script></description></item></channel></rss>