Tag Archives: gentoo

gentoo gcc – “emake failed with bootstrap-lean”

I found this short and simple solution to be the source of the error 90% of the time. Your server is running out of resources. Try the following:

  • Remove -pipe from CLFAGS
  • Decrease your -j# opts
  • Increase/enable swap
  • Increase RAM

This should clear the problem, but if it does not then problems may run deeper. Be sure to check your build.log, as this (while difficult to read and sometimes cryptic) will help you diagnose the problem.

irssi, ultimate configuration

This is a post about my (almost perfect and completely wonderful) irssi rig. Nothing is perfect, but this is pretty damn close in my opinion.

There are two main ways for IRCnuts like us to keep a permanent connection to IRC; irssi/weechat in a terminal multiplexer like screen or tmux, and a bnc. Both have their advantages and disadvantages; bnc’s are cheap, simple, allow for GUI clients while terminal multiplexers keep huge logs, timestamps/messages remain intact, and with irssi it’s easy to add scripts and actions with tools like trigger.pl. On the negative side, bnc’s destroy timestamps, logs are horrible to read, scripts are harder to write, while terminal multiplexers are dependant on a stable internet connection and require an ssh client (hard to use on you phone for example).

My ultimate configuration uses both a bnc, and irssi running in a tmux session. I am going to briefly discuss how I set this up, and why it rocks.

You will need:

  • A vps (running Linux)
  • Cup of tea

We’ll need a terminal multiplexer

I use tmux because it’s lovely, but you can use whatever you want (GNU screen).
I have a post about tmux you might like to read.

Install and configure znc

First, lets configure znc. Install znc on your system of choice. Mine is Gentoo so I just

# emerge znc

(Don’t forget to check your useflags!)
Switch to the login you normally use (not root!!) and configure znc. Luckily znc provides us with a tool to do this easily.

$ znc --makeconf

Answer the questions and write your config to ~/.znc/configs/znc.conf. Note, you can only have one server per user. For multiple servers, add multiple users. A good way to do this is create passwords with the pattern “nickname:commonpassword”.

If you use the module nickserv, then now you should set your nickserv password. You can either start znc, connect with irssi and do

/msg *nickserv set pass

or you can run

echo 'Password pass' >> ~/.znc/users/youruser/moddata/nickserv/.registry

Once this was done, I copied the USER block in the znc.conf file for all my other users (for other servers) and also copied (and changed the password for) the ~/.znc/users/firstuser/. Use znc –makepass to generate a password hash.

Now znc is correctly configured, you can fire it up by typing

$ znc

and it will automatically fork.

Using znc

You can control znc from your IRC client when connected. To see a list of commands type

/msg *status help

You may want to execute some commands when you connect (such as /oper). For this we can use the perform module.

/msg *status LoadMod perform

And then

/msg *perform help

You can find a list of modules here.

Install, configure and set up bitlbee

There is no better way to use MSN/Gtalk/etc than Bitlbee. All your contacts appear as users on a special IRC channel, allowing you to communicate with them using an IRC client like irssi. Excellent. I would recommend using libpurple with bitlbee, since you get many more account types. Add purple to your useflags if you’re using Gentoo. Then emerge, configure and start.

# emerge -a bitlbee
# vim /etc/bitlbee/bitlbee.conf
# /etc/init.d/bitlbee start

Now, connect to bitlbee using the port you configure above and create an account. It’ll automatically join you to a channel called &bitlbee. The first step is to register,

/msg &bitlbee register yourpass

To add an MSN/Google Talk account:

/msg &bitlbee account add msn email password
/msg &bitlbee account add jabber username@gmail.com mypasswd talk.google.com:5223:ssl

You can always try “help” for more information. Now you’re done, start your accounts and don’t forget to add this server to your znc config. You can also add your identify command to the znc perform module to have it automatically log you in on start.

Install and configure irssi

Install irssi and tmux. Again do this with whatever package manager your distribution uses.

# emerge irssi

(Don’t forget to check your useflags!)

For irssi, I like to first get a theme. Look at http://www.irssi.org/themes to pick one if you so desire.

$ wget http://irssi.org/themefiles/bluu.theme -O ~/.irssi/default.theme

There are a few scripts that I absolutely cannot live without. We want them to start automatically.

$ mkdir -p ~/.irssi/scripts/autorun/

Now any scripts in this directory will be loaded automatically.

nickcolor.pl

This will colour all nicknames and remember them, I find it easier to follow a conversation at a glance this way.

$ wget http://scripts.irssi.org/scripts/nickcolor.pl -O ~/.irssi/scripts/autorun/nickcolor.pl

tmux_away.pl

Sets you to away when you detach the tmux session irssi is running inside.

$ wget http://cybione.org/~cdidier/code/misc/tmux_away.pl -O ~/.irssi/scripts/autorun/tmux_away.pl

There is also a screen_away.pl script.

$ wget http://scripts.irssi.org/scripts/screen_away.pl -O ~/.irssi/scripts/autorun/screen_away.pl

hilightwin.pl

Make a special window for all your highlighted messages (and private messages).

$ wget http://scripts.irssi.org/scripts/hilightwin.pl -O ~/.irssi/scripts/autorun/hilightwin.pl

adv_windowlist.pl

A better window list.

$ wget http://anti.teamidiot.de/static/nei/*/Code/Irssi/adv_windowlist.pl -O ~/.irssi/scripts/autorun/adv_windowlist.pl

Now lets start irssi and configure these scripts. They will load automatically. (Make sure to start this in tmux, otherwise tmux_away.pl won’t load)

Turn tmux_away.pl on

/set tmux_away_active ON

Make the window for hilightwin.pl

/win new split
/win rename hilight
/win size 6

Make adv_windowlist.pl look pretty

/set awl_display_key $Q%K|%n$H$C$S

Finally, lets save everything!

/layout save
/save

Final thoughts

This configuration is the ultimate configuration, but it’s still not great. while this configuration is still far from perfect – it is (imo) the best one I’ve seen so far. If you found this useful, it’d be great to hear from you. If you found a bug, it would be even better to hear from you.

nginx, php, php-fpm and postgresql – Gentoo.

Today we’re going to install nginx, php (with php-fpm) and postrgesql. I need to set up a new development environment locally so I figured I may as well just document it as well. I will be doing this on Gentoo.

First lets setup some useflags.

www-servers/nginx fastcgi nginx_modules_http_auth_basic nginx_modules_http_rewrite vim-syntax
dev-lang/php bzip2 cgi crypt curl gd hash json postgres sqlite3 unicode xml fpm
dev-db/postgresql-base readline

I took the doc useflag out because it has a lot of dependancies, and the docs are the same as the ones online! Now get on with some emerging (make sure you’ve syncd too!).

# emerge -a nginx php postgresql-server
 
These are the packages that would be merged, in order:
 
Calculating dependencies... done!
[ebuild  N    ] dev-libs/geoip-1.4.6  USE="-perl-geoipupdate"
[ebuild  N    ] dev-python/egenix-mx-base-3.1.3
[ebuild  N    ] app-admin/eselect-postgresql-0.3
[ebuild  N    ] app-vim/nginx-syntax-0.3.1
[ebuild  N    ] dev-db/postgresql-base-9.0.3  USE="nls pam readline ssl zlib -doc -kerberos -ldap -pg_legacytimestamp -threads" LINGUAS="-af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW"
[ebuild  N    ] www-servers/nginx-1.0.0-r1  USE="http http-cache ipv6 pcre ssl vim-syntax -aio -debug -libatomic" NGINX_MODULES_HTTP="access auth_basic autoindex browser charset empty_gif fastcgi geo gzip limit_req limit_zone map memcached proxy referer rewrite scgi split_clients ssi upstream_ip_hash userid uwsgi -addition -cache_purge -dav -degradation -ey_balancer -flv -geoip -gzip_static -headers_more -image_filter -passenger -perl -push -random_index -realip -secure_link -slowfs_cache -stub_status -sub -upload -xslt" NGINX_MODULES_MAIL="-imap -pop3 -smtp"
[ebuild   R   ] dev-lang/php-5.3.6  USE="postgres* -mysql*"
[ebuild  N    ] dev-db/postgresql-server-9.0.3  USE="nls perl python -doc -pg_legacytimestamp (-selinux) -tcl -uuid -xml" LINGUAS="-af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW"
 
Would you like to merge these packages? [Yes/No]

Before we do anything else, you must set the locale for postgresql. Edit /etc/conf.d/postgresql-9.0 and set PG_INITDB_OPTS appropriately! I used –locale=en_GB.UTF-8.
Now we must setup the initial database environment. emerge will tell you what command to run. For this version I must run

#  emerge --config =dev-db/postgresql-server-9.0.3

Start the daemon.

#  /etc/init.d/postgresql-9.0 start

Finally, set up our users. Connect as root and set the password.

# psql -U postgres
psql (9.0.3)
Type "help" for help.
 
postgres=# \password
Enter new password:
Enter it again:
postgres=# \q

Edit vim /var/lib/postgresql/9.0/data/pg_hba.conf and set “trust” to “password”.
Add users to postgres group, if they will be using the PostgreSQL server. I added nginx.

# gpasswd -a nginx postgres

Finally restart the server

# /etc/init.d/postgresql-9.0 restart

Let’s add a user and a database to play with

# psql -U postgres
Password for user postgres:
psql (9.0.3)
Type "help" for help.
 
postgres=# CREATE USER nginx WITH PASSWORD 'safepass';
CREATE ROLE
postgres=# CREATE DATABASE ourdb;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE ourdb to nginx;
GRANT
postgres=# \q

We’re done here, lets move on!

Open php-fpm’s config file, found here: /etc/php/fpm-php5.3/php-fpm.conf. You want to set the user to nginx, and make note of the port php-fpm will listen for FastCGI connections. Here we see php-fpm will listen on port 9000. (this should be default) Finally, since this server will not take much load we want to lower the amount of processes it starts by default, we will set 5 since 20 (default) is rather a lot!

listen = 127.0.0.1:9000
user = nginx
pm.start_servers = 5

Now open up the nginx config file /etc/nginx/nginx.conf. We need to configure nginx to use php-fpm. Inside the server { tag you will want to add

listen 80;
 
location ~ .php$ {
    fastcgi_pass 127.0.0.1:9000;
}

And inside the http { tag you should add:

include /etc/nginx/fastcgi.conf;
include /etc/nginx/fastcgi_params;
 
index index.php;

I will not cover SSL here. This is only a local dev server, so there is no need for SSL right now. Set the server names and log files as you wish. Make sure the user is nginx.

You should now be ready to start the server. Go ahead and fire them up.

r00ph ~ # /etc/init.d/php-fpm start
 * Starting PHP FastCGI Process Manager ...                                       [ ok ]
r00ph ~ # /etc/init.d/nginx start
 * Checking nginx' configuration ...
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful           [ ok ]
 * Starting nginx ...                                                                          [ ok ]
r00ph ~ #

Lets test it out:

" > /var/www/localhost/htdocs/index.php
# chown nginx:nginx /var/www/localhost/htdocs/index.php

And head over to http://localhost/ (or where ever it is hosted). If everything is okay you should see the phpinfo information! You can check here that PostgreSQL is enabled in the PHP config. (it should be)

Now everything should be working perfectly! Finally you’ll want to use rc-update to get the init script to run automatically on boot.

# rc-update add nginx default
# rc-update add php-fpm default
# rc-update add postgresql-9.0 default

You should be good to go!

Key-based OpenSSH authentication.

Here’s a quick and dirty guide to getting key-based OpenSSH authentication working, and using keychain to manage your keys. This will allow you to login to all your remote machines without a password, while still remaining secure!

First we need to generate a public/private key pair. This is pretty easy, using the ssh-keygen tool supplied with OpenSSH.

$ ssh-keygen -t dsa

This will create a public/private key pair using DSA encryption. Pick a passphrase which is secure (mine is 20 characters; alpha, numeric and special). A common mistake people make here is entering a blank passphrase. Sure enough, if you use a key pair like this you will be able to authenticate with a remote sshd without entering a password, but the private key will be unencrypted! This means anyone that obtains your private key would also have access to your remote machines. BAD! Don’t fret, there is a way around this…

Now you have created your key pair, you must copy the public key to the remote machine.

$ scp ~/.ssh/id_dsa.pub user@remote:
$ ssh user@remote echo ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys2

Now if you attempt

$ ssh user@remote

It should ask you for your passphrase, and authorise you when you enter it correctly. Great! We are on track.

Now, OpenSSH comes with a tool called ssh-agent. This is used to remember your passphrases, so you only have to enter them once. Unfortunately, it needs a bit of configuring before it will work effectively. For this, we are going to use keychain. Install the keychain package, if you’re using Gentoo this would be

# emerge keychain

Now all you need to do is add this to your ~/.bash_profile

/usr/bin/keychain ~/.ssh/id_dsa
. ~/.keychain/$HOSTNAME-sh
. ~/.keychain/$HOSTNAME-sh-gpg      # If you're using gpg-agent as well.

Now logout and log back in! You will be prompted for your passphrase, but after that you will be able to make passwordless key-based connections to all your remote machines (remember to copy the id_dsa.pub into ~/.ssh/authorized_keys2!).

Guitar pedal in Gentoo

No updates in a while, I’ve been lazy. Here is a guide to setting up a Zoom G2.1u guitar pedal with JACK under Linux.

First thing you want to do is compile usb_snd_audio support in your kernel. I have already discussed how to do this, as it’s the same module you maybe have used to run a USB MIDI keyboard. Here is a post showing you how to do this: Gentoo and MIDI keyboard

Next, plug your guitar pedal in. Now to check everything is working as expected you need to cat /proc/asound/cards

$ cat /proc/asound/cards 
 0 [Intel          ]: HDA-Intel - HDA Intel
                      HDA Intel at 0xd2000000 irq 16
 1 [default        ]: USB-Audio - USB Audio CODEC 
                      Burr-Brown from TI               USB Audio CODEC  at usb-0000:00:1d.3-2, full s
 2 [K88            ]: USB-Audio - Keystation Pro 88
                      Evolution Electronics Ltd. Keystation Pro 88 at usb-0000:00:1d.1-1, full speed

Here we can see my Intel sound card (0), Zoom G2.1u pedal (1) and M-Audio Keystation Pro 88 (3). If yours is similar to this, you’re on the right track!

Now we need to start alsa_in. Basically, your guitar pedal is acting a sound card with only an input. We want to take this input, and redirect it straight to our main sound card (the one with the speakers connected!). In the this example, 1 is the Zoom G2.1u and 0 is my main sound card (as seen above). We start alsa_in like this:

$ alsa_in -j zoom -d hw:1 -c 1 -q 1

In this example, I have called the port zoom, using device 1, with one channel (since guitars are monotone anyway) and set the sample rate quality to 1. You can fiddle with these arguments, they work well for me.

Finally all we have to do is connect alsa_in to our output device. For this, we use jack_lsp to list all our JACK ports.

$ jack_lsp 
system:capture_1
system:capture_2
system:playback_1
system:playback_2
zoom:capture_1

We want to connect zoom:capture_1 to system:playback_1 and system:playback_2. For this we use jack_connect.

$ jack_connect zoom:capture_1 system:playback_1
$ jack_connect zoom:capture_1 system:playback_2

And with any luck, now when you play your guitar sound comes out your speakers! :)