Definite's Extractor

My findings on Life, Linux, Open Source, and so on.

Legacy Python str.format() gotcha

In Python 2.7, str.format() works with empty string like:

python -c "print '{}'.format('')"

However, in Python < 2.6,  you will see:

ValueError: zero length field name in format

Workaround? Use %-formatting like:

python -c "print '%s' % ''"

 

Advertisements

Indent in Fedora-Flavored Markdown

I cannot find any documents about the indent in Fedora-Flavored Markdown. Yet I figure out following:

You need 4 spaces to indent. The rest is same with this Markdown Cheatsheet.

For example

- Upstream update to 1.10.0
    + Bug fixes:
        - Log to file defaults to unwritable location
        - Losing GUI config when restarting the OS

    + Enhancements:
        - CLI argument to control screen lock feature
        - Customizable size limit on clipboard sharing

- BuildRequires qt5-qtbase-devel

Becomes:

  • Upstream update to 1.10.0
    • Bug fixes:
      • Log to file defaults to unwritable location
      • Losing GUI config when restarting the OS
    • Enhancements:
      • CLI argument to control screen lock feature
      • Customizable size limit on clipboard sharing
  • BuildRequires qt5-qtbase-devel

See https://bodhi.fedoraproject.org/updates/synergy-1.10.0-1.el7 for the actual result.

Debugging Customizable Kickstart File

Kickstart file automates the installation Linux system. It does not provide a convenient way to pass parameters. Luckily,  passing kernel parameters to %pre installation section works. This method requires you to write your kickstart generation script in %pre section, then in the command section, you call the generated kickstart file.

Unfortunately, this mean it is more likely to fail if the parameters are not correct. How to debug? If you can at lease reach the installer, this document may point you direction.

1. Get the shell access

After anaconda the installer starts,  there are several console tabs, the ones that are useful are:

  • main: the main information screen (Alt-F1 or Ctrl-Alt-F1)
  • Shell: the shell access (Alt-F2 or Ctrl-Alt-F2)
  • GUI: show the install progress if graphical mode is not disabled (Alt-F6 or Ctrl-Alt-F6)

For now, shell access is the focus. Switch to Shell tab by pressing Alt-F2 or Crt-Alt-F2.

2. Inspect parameters by looking at /proc/cmdfile

Just cat /proc/cmdfile to inspect whether the parameters looks right. Personally, I do not want to write complex parser, thus I use quote_plus() from python to encode tricky characters like space, line feed, $ and so on.

3. Inspect the generated scripts and log files

The first thing to check is generated kickstart file. Then check following interesting files in /tmp

  • ks-script-XXX: The script in  section %pre  will be here. Inspect it, and even run it to see how it works or not
  • *.log: various of log files

Enjoy the debugging. 🙂

Solved: nginx module incompatible

I encountered when I run nginx -t:

nginx: [emerg] module
"/usr/lib64/nginx/modules/ngx_http_auth_spnego_module.so"
version x instead of y in 
/usr/share/nginx/modules/mod-spnego-http-auth-nginx-module.conf:1

It indicated that the module version is incompatible.
If nginx was installed using yum or dnf, use following command to set the version:

yum downgrade nginx{,-all-modules,-filesystem,-mod-*}-[version]-[release]

synergy-2.0.0 is in Fedora updates-testing

synergy is a software that allow you to use your favorite mouse and keyboard on multiple machines. It supports MacOS, Windows, and Linux.

I have packed the latest stable version, 2.0.0, for Fedora 27, 26 and EPEL 7. No EPEL 6 update this time as it requires CXX14, which EL6 does not provide.

Wii Remote for Fedora

I wish to play Ur-Quan Masters(UQM) with my kids in Fedora. The installation of UQM is simple, just dnf -y install uqm.

Then I use following steps to connect Wii to Fedora:

1. Install packages

sudo dnf -y install cwiid cwiid-wminput cwiid-utils wiiuse libwiimote

2. Make udev.d Rule

This step enable non-root user to use Wii remotes.

sudo tee << /dev/null
sudo udevadm control -R

3. (Optional) Test Bluetooth Connection

  1. Run wmgui
  2. Click File and connect, you will receive the prompt that you need to press BOTH 1 and 2 on the Wii remote to activate the Bluetooth discovery mode.

Once succeeded, you can press buttons to see whether they are recognized.

4. Configure and Run wminput

I found that mapping the Wii remote to Key Pad is much more convenient that wminput default, especially for laptop. The reason is obvious: it is less likely to cause key clash.

My config is saved as ~/.cwiid/wminput and looks like:

Wiimote.Up = KEY_KP8
Wiimote.Down = KEY_KP2
Wiimote.Left = KEY_KP4
Wiimote.Right = KEY_KP6
Wiimote.A = KEY_KPENTER
Wiimote.B = KEY_KP0
Wiimote.Minus = KEY_KPMINUS
Wiimote.Plus = KEY_KPPLUS
Wiimote.Home = KEY_KPDOT
Wiimote.1 = KEY_1
Wiimote.2 = KEY_3

Then, I ran:

wminput -w -c ~/.cwiid/wminput

That’s it.

Do not do the math with expr

expr EXPERSSION returns 1 when the EXPERSSION is empty or 0.  Thus, you cannot really use it to do arithmetic.

For example, you may find your script doing  expr 1 - 1  returns as error.

To be fair, man page expr actually mentions this. However, instead of a dedicate section EXIT STATUSES, it is hidden in the second last paragraph of DESCRIPTION.

So do yourself a favour, use BASH arithmetic like $((var+1)).

KDE connect makes your mobile life easier

KDE Connect connects between your mobile and Linux, wirelessly.

You can copy photos, videos, or other files from mobile, or vise versa.

You can use your mobile as remote control of Linux media player, or even wireless mouse and keyboard. On the other hands, the clipboard of mobile and Linux are shared, so you can use your favorite desktop keyboard and input methods on mobile applications, like Clash-of-Clans and WeChat. The mobile and Linux should be at the same subnet, though.

Another interesting way to use KDE Connect is replacing Yubikey. I use the Yubikey almost everyday. Consequently, it become loose contact, so I need to wiggle it to get the contact. KDE Connect with Google authenticator or FreeOTP Authenticator might to the trick.

AirDroid is feature richer, however, you need to register to AirDroid to use Airdroid, but with KDE Connect you just need to pair it, and the connection is encrypted. Most importantly, AirDroid is not open source.

So far, KDE connect is available in Google play and most major Linux distribution, including Fedora. iOS version is not yet in app store though.

GPG: no default secret key gpg

In Fedora, you may have both gpg and gpg2. The secret keys are stored in different ways.

Try

which gpg gpg2

You might get:

/usr/bin/gpg
/usr/bin/gpg2

If you do have both, run:

gpg2 --list-secret
gpg --list-secret

Suppose your gpg2 --list-secret returns nothing. You can then export from gpg then import to gpg2 like so:

gpg --export-secret-keys -a > secret.asc
gpg2 --import secret.asc

Note that pass phrase is required to export.
Finally, verify the import with

gpg2 --list-secret

You may encounter the error message: Unknown IPC command. The quick fix is set the environment variable LC_ALL=C

Chewable Fedora Atomic

Fedora Atomic is an operating system targets to containers. However, the documentation, for me, is very hard to read. In this document, I will share my adventure with Fedora Atomic, starting with post installation.

I have installed Fedora Atomic, now what?

Let’s say you want to install the tree and docker-compose for better understanding the directory structure of your new host; you also need to ping a host every hour; and of course, you want your shiny new docker application to be deploy to this machine.

Package Install with rpm-ostree

Read more of this post