Archive

Archive for the ‘Uncategorized’ Category

ogc 5.0

May 7th, 2011 subogero No comments

The new version of the Lazy Man’s calculator maximizes laziness by taking your expressions directly from the command line. No pipes, no interactivity, no interpreter-scripts. Just what the customer wants.

$ ogc -e 2*21
42

The clever customer can actually take ogc’s laziness to even greater extremes. Just add the following line to ~/.bashrc

alias og='ogc -e'

And voilá:

$ og xFFd
255

You can download sources and Linux/Win32 binaries from the ogc page.

Geeks can clone the git repo as well:

git clone https://github.com/subogero/ogc.git
git clone http://subogero.dyndns.org/git/ogc.git

Human-like Robot

February 2nd, 2011 subogero 1 comment

My Moto V3i began to give up. As usual, the flip bearings became loose and, the phone reset itself ever more often, usually while receiving calls. Slightly disturbing.

So, eventually, I also gave up resisting the smartphone wave and started looking for incrementing my Linux kernel-count. The main candidate was the HTC Hero with its sturdy aluminium housing. That is, until I found the strange Motorola Defy on the Hungarian Price Machine. Slightly cheaper, with an even more sturdy shock- and waterproof housing and scratch-proof glass. Hungarians don’t like stuff if it is scratched. The gadget also has a 0.8 GHz ARM processor, accelerometers, n-type WiFi, GPS and a Full Wide touchscreen with 854 x 480 resolution.

True to form I did two things with it on the first day:

  • rooted it
  • poured water on it

Both with excellent results. It also got a Terminal Emulator and Busybox installed on it. The reason? It turned out that Android’s underlying Linux is an extremely crude environment. First, it has no GNU tools. And they did not even bother with installing Busybox, the usual commands are links to either Google’s toolbox or Motorola’s motobox. Both very poor. My 8 MB OpenWrt router’s command line environment is a luxurious place compared to this phone (half gig internal memory, remember).

Oh, and how does it work as a phone, you may ask? Quite brilliantly, actually.

I no more need a camera. It takes brilliant pictures in daylight.
I no more need to carry a private laptop while travelling, as it’s got WiFi, Email and Web.
I no more need maps or a GPS device. i just GO.
I no more need those bloody 20th century CDs in the car. Just play music from the phone.

One Gadget To Rule Them All.

Categories: Uncategorized Tags: ,

Curling

November 29th, 2010 subogero No comments

I’m not referring to the most boring sport EVER. Instead, it’s a command line tool I’ve discovered recently: curl. You specify a URL on the command line (e.g. curl http://napirajz.hu), and it prints the contents to standard output.

Time to write my most popular website ever:

The business case:
Bloody multinational corporations filter the internet. One cannot access inspiring content like http://napirajz.hu. Let’s make it accessible.

The tools:
My OpenWrt router hanging on the internet. I’ll create a mirror site on it, refreshed every day at 5:00 (before breakfast), 9:00 (arriving at the office), 13:00 (after lunch) and 18:00 (before I get home).

The beloved cron daemon will do the timing. And the mirroring? On OpenWrt, one lacks the luxuries or Perl and even the cosy comfort of Bash. One has to make do with the BusyBox versions of the Almquist Shell (ash), curl, sed and wget.

#!/bin/ash
PICS=`curl 'http://napirajz.hu' 2>/dev/null \
| sed -nr 's,^[\t ]*<p><img src=\"([a-z0-9/_.]+)\".+$,http://napirajz.hu\1,p'`
rm -f *.jp*
echo '<html><head><title>subogero napi</title></head><body>'
echo '<h1 align="center">subogero napi</h1>'
echo '<hr>'
for i in $PICS; do
 wget $i
 echo $i \
 | sed -r 's,^.+/([a-z0-9_]+)(\.[jpeg]+)$,<p><a href=\"napi/\1\2\">\1</a>,'
done
echo '<hr>'
echo '(c) CC - Mer&eacute;nyi D&aacute;niel'
echo '<br>Eredeti: h t t p : / / n a p i r a j z . h u'
echo '<p>Friss&iacute;tve:'
date "+%Y.%m.%d %H:%M"
echo '</body></html>'

See the result at http://subogero.dyndns.org/git/napi/

Categories: Uncategorized Tags: , , , , ,

Extend OpenWrt

November 9th, 2010 subogero 4 comments

An OpenWrt router needs to be extended a bit to run big stuff. For instance to build a git-hub. The installed size of git is 91MB. One has an external USB HDD, of course, but what is the right way to do it? The forums are full of extroots and opts and similar stuff. I think they are all evil.

Extroot seems to involve compiling custom firmware images, while /opt brakes the nice Unixy directory structure (standard locations of programs, libs and daemons). There must be a better way:

Mount a partition of an external USB HDD to /usr

Just think about it. The really big files go to /usr/bin /usr/sbin and /usr/lib almost exclusively. Only small stuff goes to /etc, like config files and daemon startup scripts.

Today my theory was confirmed by practice. It’s very simple. These are the important steps:

1. Create an ext3 partition on your HDD just for this purpose

I actually did the partitioning before, on my normal Ubuntu laptop. It’s 2 GB and it’s called /dev/sda2 on the router.

2. Mount it to /opt temporarily

Create the /opt directory (or whatever else) temporarily and mount your partition into it using LUCI/Administration/System/Mount Points.

3. Copy the entire contents of /usr to /opt

The goal is that, initially, /usr looks the same with or without mounting something into it.

$ cp -dpr /usr/* /opt # preserve symlinks
4. Mount partition to /usr

Unmount /dev/sda2 from /opt, mount it into /usr using LUCI. You can also delete the temporary /opt directory.

5. Update /etc/opkg.conf

This involves OpenWrt’s most mysterious concept, overlay. Changing the line below has no effect except to calm down the worrying router about available storage-size for new packages:

option overlay_root /usr

You’re ready to install anything. As for me, I’ve since reinstalled mc and git. No dirty hacks this time with inserting /opt into PATH and manually creating some symlinks from /usr to /opt/usr. Just installed them like a breeze. My github is up and running again.

Categories: Uncategorized Tags: , , ,

Tao of Git Submodules 2

November 3rd, 2010 subogero No comments

During my exploits to spread the Gospel of git-managed websites, once a great crisis broke out. A user threatened me he would return to MKS Source Integrity.

Now, such an event would shake the foundations of the entire Open Source Free Software movement. Richard Stallman would put sackcloth upon his loins. Linus Torvalds would rend his clothes. I would mourn for many days and my soul would refuse to be comforted.

Time to do something. Or rather, time to think.

I had actually been wondering, why Git’s submodule interface is so inconsistent. There is a –recursive clone, but there is no recursive option for any other remote operation. And then I was enlightened. Of course

There Is No Recursive Push

How could there be? The entire concept of submodules is based on universally read-accessible subprojects inserted into your superproject. You reuse one from gnu.org, another from the Moon, and some from Alpha Centauri. Write access for these is not guaranteed, it’s the privilege of a chosen few.

So what to do with your git-managed remote website? There are two options.

1. The remote repo has a detached worktree (repo in ~, website in /var/www)

Set up remotes and server-side post-receive hooks to check out for the subprojects.
You may want to add a pre-commit hook to the superproject pushing the submodules first.

2. The remote repo is in the website worktree

Add “git submodule update” to the post-update hook on the server side.
This assumes the server is able to access the submodule URLs.

Categories: Uncategorized Tags: , ,

Tao of Git Submodules

October 31st, 2010 subogero No comments

Being a bloody webmaster has taught me a few hard lessons about git submodules.

The reason is that my CGI scripts managing the mailing lists and adding the navigation to the web pages proved to be quite reusable and I’ve moved them into their own git project. They are now used at at least 3 websites at the office as git submodules.

When Mr Noob first starts playing with them, usually this happens:

You have a project in ~/foo and another in ~/bar. Foo wants to reuse Bar as a subproject. So you call

$ cd foo
$ git submodule add ~/bar

It’s all very nice. Until, as usual, your Foo project becomes very popular and the whole Galaxy starts clonig it. At this moment great panic of cosmic proportions breaks out, as they cannot obtain the Bar submodule’s files from

/home/Noob/bar

Of course not. You get it? The Tao of git submodules is this:

Think Big.

In other words specify a path to your submodule in a universal way. With a Universal Resource Locator.

The used protocol is also of extreme importance. It should allow unlimited read access for your entire target audience. For write-access they can always add another remote to the subproject later. If they get write-access at all.

/somewhere/in/your/filesystem

We have already discussed this.
Bad.

smb://

Some will have access, but most not. Samba is a LAN thingy. And it’s bloody slow.
Bad.

ssh://

It’s a URL, but it’s not universal enough, as your users won’t have access.
Bad.

http://

Put your subproject on a webserver, allow directory listing: universal read access obtained.
Good. If a bit slow with git.

git://

Guarantees universal read access too, and it’s fast as well.
Good. The only problem is some corporate proxies are watching port 9418 with raised eyebrows.

Bottom line: use the http:// or git:// protocols.

Categories: Uncategorized Tags: , ,

OpenWrt

October 31st, 2010 subogero 2 comments

To cut a long story short, the number of Linux kernels running at home has increased. Again.

This time it’s a TP-Link WR1043ND router managing my new internet connection. And check this: the package came with a copy of the GNU General Public License. We live in a beautiful world!

The first thing I did was to overwrite the factory firmware with OpenWrt. It’s a fantastic thing. At the moment of writing, I’m running the following services on it:

  • USB hard disk with some ext3 partitions attached (big)
  • My own git-hub
  • A home file-server using Samba
  • Transmission bit-torrent client
  • It even has its own domain name

Git was a bit tricky, as it’s big, so it’s installed into /opt, mounted from the USB HDD.

I have a theory, that the real solution to increasing the capacity of such routers is not extroot, not /opt, but mounting a partition to /usr.

But I have not tried it. Yet.

I am a Webmaster

September 27th, 2010 subogero No comments

It happened that I had to put together a few html pages containing important info about a certain project at the company. Originally I stored them on a Samba share on the official Windows file-server. I turned out to be terrible. For instance Firefox needs FIVE slashes after the protocol-id in the URL:

file://///server/share/page.html

IE needs two, Chrome needs four. First step in the downward spiral: I need the http protocol, in other words a webserver. So I installed Cygwin’s lighttpd on our constantly running desktop box. Then moved the html files to “/srv/www/htdocs/site/”. First step done.

Next step: it’s very cumbersome to change the navigation links, whenever a new page is added. Time to automatize. Tools: SSI (server side includes) and CGI scripts in Perl.

Then, what about setting up a few mailing lists. No archiving, just free subscribing and sending mail via “mailto:” links. One day job in Perl.

Later SSI turned out to be a bad choice as you need an absolute path to your CGI script. Difficult if you want a test-site. So I rewrote the entire site that all links actually refer to the same CGI script which loads the required page, adding dynamic navigation.

The trickiest and nicest part is managing the website with git. On the server I set up a git repo in my home folder, with a detached worktree in “/srv/www/htdocs/site”:

server ~$ mkdir site.git && cd site.git
server ~/site.git$ git --bare init
server ~/site.git$ git config core.worktree '/srv/www/htdocs/site'
server ~/site.git$ git config receive.denycurrentbranch false

Additionally, we need a hook routine which checks out anything to the website whenever you push it into this repo:

server ~/site.git$ mv hooks/post-receive.sample hooks/post-receive
server ~/site.git$ mcedit hooks/post-receive
# checkout the received branch to the website
read OLD NEW REF
git checkout -f $RE

On my own machine, I also have a git repo to manage the site. To allow easy server-updates, I did this:

mybox ~/site$ git remote add web ssh://server/~/site.git
mybox ~/site$ git push web master

Finally, one wants a test-site. Lighty endeavours to give satisfaction, so simply enable module mod_userdir in /etc/lighttpd/lighttpd.conf, and each user’s public_html folder becomes his own website. The two lines below now refer to the same folder:

/home/foo/public_html/
http://server/~foo/

Let’s create a non-bare repo here and configure it to receive and automatically check out pushed commits:

server ~/public_html$ mkdir site && cd site
server ~/public_html/site$ git init
server ~/public_html/site$ git config receive.denycurrentbranch false

I applied the same post-receive hook as with the official website’s repo. But it refused to check out the pushed commits. After a considerable amount of cursing it turns out the bloody git runs the hooks in the “.git” folder. I discovered this when I found all my html files there. So the post-receive hook should look like this in a non bare repo:

#!/bin/sh
unset GIT_DIR
unset GIT_WORK_TREE
cd ..
read OLD NEW REF
REF=`echo $REF | sed 's:refs/..*/::'` # branch instead of detached head
git checkout -f $REF

On my box I added an other remote to allow pushing to the test site:

mybox ~/site$ git remote add test ssh://server/~/public_html/site
mybox ~/site$ git push test master

I even applied a post-commit hook on the local machine which pushes master-commits to the official site and branch-commits to the test site.

Jaunty vs Lucid Reboot Time

August 23rd, 2010 subogero No comments

I’ve measured the reboot time after the Lucid install on the ASUS UL20A. That’s what I call progress.

                         Jaunty  Lucid
--------------------------------------
from power-on until login  19 s   20 s
from login until ready     15 s    5 s
power off                  12 s    5 s
--------------------------------------
overall reboot time        46 s   35 s

ogc 4.2 – Math Functions

August 22nd, 2010 subogero No comments

The introduction of the lex (flex) tokenizer into the ogc development allows an incredible amount of new bloatware to be implemented. The first menacing omen was floating-point support.

And now it’s math functions. Our friends from <math.h> sin, cos, atan, log, exp, sqrt are available as @s @c @a @l @e @r. The little bastards, besides looking very ugly, also perform a sneaky implicit floating-point conversion.

Check it out. But where will this all end?