Use Nikola/GAE on android device

Some time ago I dis­cov­ered Ter­mux this cool An­droid app that al­lows you to find a good part of your lin­ux en­vi­ron­ment on your phone or tablet.

It has helped me more than once to make a quick change on the move, save it un­der git or mer­cu­ri­al be­fore push­ing it to­wards con­tin­u­ous in­te­gra­tion. Since I’ve mi­grat­ed this blog un­der Niko­la I was think­ing it would be con­ve­nient to be able to work on blog posts on the move, to pre­view them in a brows­er and to de­ploy the whole blog on GAE, ev­ery­thing from a phone.

It ac­tu­al­ly works pret­ty well.

editing this blog under termux

Screen­shot of edit­ing this blog on an­droid with ter­mux.

Here are the steps to fol­low:

Install Termux

This is sim­ply done from the Google Play app store or bet­ter from the f-­droid repos­i­to­ry.

Install mercurial (optional)

Mer­cu­ri­al al­lows me to man­age the his­to­ry of my blog edit­ing and to push it in­to a bit­buck­et pri­vate repos­i­to­ry. I like mer­cu­ri­al as re­vi­sion sys­tem man­age­ment tool main­ly be­cause of its con­sis­tent and well doc­u­ment­ed in­ter­face. Of course you can al­so use git.

pkg install python2-dev python-dev
pip2 install mercurial

Install Nikola

Preparing a virtual environment

pip install virtualenvwrapper
mkvirtualenv nikola

Install Nikola itself

workon nikola # if you are not already in the virtualenv
pkg install libxml2-dev libjpeg-turbo-dev libxslt-dev
LDFLAGS="-L/system/lib64/" CFLAGS="-I/data/data/com.termux/files/usr/include/" pip install "Nikola[extras]"

Install the google cloud sdk

I took my in­spi­ra­tion from the notes by ge­of­frey look­er:

export CLOUDSDK_PYTHON=/data/data/com.termux/files/usr/bin/python2.7
curl -k https://storage.googleapis.com/gceprd-iso/google-cloud-sdk-134.0.0-linux-x86_64__TERMUX.tar.gz -O
tar -xzf google-cloud-sdk-134.0.0-linux-x86_64__TERMUX.tar.gz
cd google-cloud-sdk
bash ./install.sh
bash a #(or zsh depending upon your taste)
gcloud components update
~/update-gcloud-sheebang.sh
gcloud auth login

Where the script update-gcloud-sheebang updates the shebang of each file potentially updated by the command gcloud components update and contains the following few lines:

#!/data/data/com.termux/files/usr/bin/bash
scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
cd ~/google-cloud-sdk/
find $(pwd) -type f -exec awk '
  /^#!.*/{print FILENAME}
  {nextfile}' {} + > "$scratch"/lines.txt
xargs -0 -n 1 termux-fix-shebang < <(tr \\n \\0 < "$scratch"/lines.txt)

Writing and publishing

Restart a shell and then:

workon nikola
nikola auto

Then vi­su­al­ize your site in an an­droid brows­er by vis­it­ing http://lo­cal­host:8000.

browsing the blog locally with firefox, served by nikola

Screen­shot of dire­fox brows­ing the blog served by niko­la on the phone.

And finally deploy it on Google App Engine with the command nikola deploy.

What remains to be improved

  • I have some er­ror mes­sages like [2018-01-19T21:28:28Z] WARN­ING: Niko­la: Lo­­cal fr_FR. ut­f8 for lan­guage fr not ac­­cep­t­ed by lo­­cal python and ap­par­ent­ly the lo­cales are not well sup­port­ed by ter­mux. I’m not quite sure of the con­se­quences.

  • Dur­ing my first test­s, I re­al­ized that some ut­f8 char­ac­ters were not well ren­dered un­der vim. I may have a con­fig­u­ra­tion to com­plete.

  • The jpe­gop­tim soft­ware is not avail­able on ter­mux, I had to dis­able it in the niko­la fil­ter con­fig­u­ra­tion which al­lows the op­ti­miza­tion of jpeg files for the we­b.

I will up­date this post to re­flect any im­prove­ments or oth­er prob­lems I have en­coun­tered.

Comments