Kai Hendry's other blog archives


I attended an event at Hackerspace.SG Running your IoT devices on a low power, long range network, which showcased Lee Lup's slides on SIGFOX at Singtel.

My thoughts are that the 12 byte payload is not really suitable for monitoring, but more for events.

  • Door closed
  • Bin's full
  • Some significant threshold exceeded

It's not super good for monitoring since:

  • payload is too small
  • there is no accurate time
  • you can't monitor any less than 10 minute intervals

I found the people tracking / GPS use cases to be silly, since GPS needs a lot of power.

SIGFOX lends itself to well known fixed locations.

Fixed locations, such as public property that need maintenance and don't have Internet connectivity for one reason or another.

I'm thinking:

  • alerting to street lamps failing
  • alerting to flooding
  • alerting to when a bin is full & needs emptying
  • alerting when a special door/gate is opened

I like how the SIGFOX station seems to send out Github style Webhook payloads to a payload URL.

Back to bash after fish

Fish logo

I tried the http://fishshell.com/ instead of bash, mainly because my bash history is continually truncated despite my efforts to keep every command I've ever successfully (return code 0) typed!

x220:~$ wc -l .bash_history
84 .bash_history
x220:~$ history | wc -l

The fish shell's 85k SLOC versus bash's 225k was also re-assuring. autotools and cpp did make me cringe however.

So porting my aliases and such from ~/.config/fish/config.fish from my ~/.bashrc was a bit of a PITA since:

  • fish's conditional statements are not POSIX shell compatible <--- insane

Nonetheless I got fish up and running... and I used fish 2.1 for about a month.

So... does shell history work in fish?

Yes, yes it does. fishd provided me the commands I typed in, HOWEVER:

  • it logged failed commands, I DO NOT WANT FAILED COMMANDS SAVED
  • failed commands could be a password. To remove them I had to 'fish_config' and go to history tab.
  • ctrl+r (bash's reverse search) doesn't work. Instead you need to toggle between ctrl+f (autocomplete) and ctrl+p (search)

Tbh I could live with this fishiness. Simply because I had a working shell history. Seriously.

Why I stopped using fish

Consider this code from http://git.suckless.org/dmenu/tree/dmenu_run

dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} &

So I would choose a bash script like screenshot, to be run by dmenu, which is then piped to $SHELL. $SHELL being /usr/bin/fish when using fish. Screenshot's shebang #!/bin/bash does not apply.

IIUC variable expansion in fish is done different causing 99% of shell scripts to fail when run by fish. Nevermind the crazy stderr caret stuff. fish being a non-compatible shell is just a TOTAL FAIL.

Furthermore setting up PATH on Linux is just generally insane, probably because I've (wrongly) setup the PATH mainly in my ~/.bashrc, instead of ~/.profile or is it somewhere else? Anyway my PATH was consistency broken in fish too and I never figured 100% why. Perhaps because of its variable expansion anti-feature.

Back to GNU bash

Tbh, ctrl+r aka (reverse-i-search) is much better & intuitive than fish's ctrl+f & ctrl+p.

Now if only I could get my bash history working. I miss fishd I guess. Tbh I did like fish's fish_config and the way it attempted but kinda failed to integrate with the browser.


Latest tips

Working with a directories of unknown files

Using http://mywiki.wooledge.org/BashFAQ/020 as a starting point, you could:

find /tmp -type f -print0 | while IFS= read -r -d '' file
   echo properly escaped "$file" for doing stuff

However that's a bit ugly. And note that -d '' only works in bash. So none of this is "POSIX".

Another way of writing this, which works from bash 4 is using dotglob/globstar:

shopt -s dotglob  # find .FILES
shopt -s globstar # make ** recurse
for f in /tmp/**
    if <span class="createlink"><a href="/ikiwiki.cgi?page=_-f___36__f___38____38_____33___-L___36__f_&amp;from=e%2F13042&amp;do=create" rel="nofollow">?</a> -f &#36;f &#38;&#38; &#33; -L &#36;f </span>
        echo properly escaped "$f" for doing stuff

Another perhaps more POSIX way is

foo () { for i in "$@"; do echo $i; done };export -f foo;find /tmp -type f -exec bash -c 'foo "$@"' - {} + | wc -l

I.e. export a script function to be executed by the -exec parameter of find, or just use a seperate script file.

Ensure www-data is always able to write

Ensure your fs is mounted with acl.

 mount | grep acl
/dev/root on / type ext3 (rw,noatime,errors=remount-ro,acl,barrier=0,data=writeback)

And to ensure www-data always has free reign:

setfacl -R -m default:group:www-data:rwx /srv/www
Xorgs version
12:04 <hendry> i'm using wheezy Xorg packages  1:7.7+3~deb7u1 and http://ix.io/d2p says X.Org X Server 1.12.4
12:04 <hendry> Release Date: 2012-08-27
12:04 <hendry> Is that right?
12:05 <jcristau> probably
12:11 <hendry> wondering why there is a mis-match with versions
12:11 <hendry> is there a newer Xorg available for wheezy? something to eek out performance with intel cards
12:12 <jcristau> there isn't a mismatch
12:12 <jcristau> and no
12:12 <hendry> 1:7.7+3~deb7u1 & 1.12.4 doesn't make sense to me ... :}
12:13 <jcristau> you can't understand that different things can have different versions?
12:20 <hendry> so what does 7.7+3~deb7u1 refer to ?
12:22 <pochu> 7.7 is the upstream version, +3 is the debian revision, and deb7u1 is the first update to Debian 7 (wheezy)
12:22 <psychon> http://www.x.org/wiki/Releases/7.7/
12:28 <jcristau> 7.7 is the base version of X.Org's X11 distribution
12:28 <jcristau> 1.12.4 is the version of the X server


Setting a read S3 policy from the command line

Easier than logging into https://console.aws.amazon.com/s3/ since I need to get out my MFA device out everytime.

x220:/tmp$ bash allow-read.sh b3-webc
s3://b3-webc/: Policy updated

allow-read.sh is just a script to help write the policy:

x220:/tmp$ cat allow-read.sh
test "$1" || exit
s3cmd ls > $tmp
if ! grep -q $s3_bucket $tmp
        echo Could not find bucket s3://${s3_bucket}
        cat $tmp
cat <<END > $tmp
      "Principal": {
            "AWS": "*"
s3cmd setpolicy $tmp s3://${s3_bucket}
Failed to start Verify integrity of password and group files.

Fix it by running pwck.

x220:~$ sudo pwck
user 'umurmur': directory '/home/umurmur' does not exist
pwck: no changes
x220:~$ pacman -Ss umurmur
community/umurmur 0.2.14-1
    Minimalistic Mumble server
x220:~$ sudo vim /etc/passwd
x220:~$ sudo pwck
no matching password file entry in /etc/passwd
delete line 'umurmur:!:16094::::::'? yes
pwck: the files have been updated

Powered by Vanilla PHP feedback form