Archive for the ‘gentoo’ Category

Seventeen or Bust; a gentoo daemon script

Tuesday, July 12th, 2011

Seventeen or Bust

It’s been a while since I’ve just my available CPU cycles for vanity, but I’m a sucker for stats. Normally, you’d just start the binary mprime in some terminal and let it be, I didn’t like that for my servers (basically, I’d have to run SoB under some user, in some screen, and whenever something happens I’d have to manually interfere to kill it or restart it). So I wrote a very simple rc script to handle it for me.

The script

/etc/init.d/seventeenorbust

#!/sbin/runscript
 
depend() {
        use net
}
 
start() {
        PWHOME="$(getent passwd $USER | awk -F: '{ print $6 }')"
 
        ebegin "Starting SeventeenOrBust"
        env TERM="xterm" \
                start-stop-daemon \
                        --start \
                        --user $USER \
                        --env HOME="${PWHOME:-/home/$USER}" \
                        --name sob \
                        --exec /usr/bin/screen -- -dmS sob /home/sob/mprime -d
        eend $?
}
 
stop() {
        ebegin "Stopping SeventeenOrBust"
        start-stop-daemon --stop --signal 2 --name sob
        eend $?
}

/etc/conf.d/seventeenorbust

USER="sob"

Setup

  1. Copy the above files to your filesystem
  2. $ useradd -m -p "sob" sob
  3. Add a DenyUsers entry in your sshd_config for the sob account, don’t want people getting access to your box with a default user
  4. Login as the sob user, download and install the SoB binaries in your homedir and configure SoB accordingly (usually, this is just setting up your username in prime.txt
  5. (Optional); $ rc-update add seventeenorbust default

Like to view progress?

If you like to keep tabs on your instance, completion percentage and such, you can log in as the sob-user and run $ screen -dr sob to attach to te daemon’s screen session.

Android 2.2 USB Tethering on a Gentoo box

Tuesday, August 3rd, 2010

Why not use the WiFi Hotspot

Recently HTC rolled out the Android 2.2 upgrade for my Desire, finally enabling USB Tethering out of the box. Often enough I used the WiFi hotspot feature on my previous phone to enable my laptop to have internet on the go. Android’s got this feature as well nowadays, but I don’t really like it because it really, and I mean *really*, puts the drain on your phone’s battery. USB Tethering seems like a much better solution.

Setup for Android

This is by far the easiest part, just hook up your phone, drag down the status bar and instead of charge only, or whatever mode it is in at that time, set it to USB Tethering.

Setup for Gentoo

This part is a bit trickier, especially when you roll your own kernel. Open up menuconfig for your kernel and enable these options

Device Drivers --->
  [*] Network device support --->
    USB Network Adapters --->
      [*] Multi-purpose USB Networking Framework
        <*> CDC Ethernet support
        <*> CDC EEM support
        <*> Simple USB Network Links (CDC Ethernet subset)
          [*] Embedded ARM Linux links
  [*] USB Support --->
    <*> USB Modem (CDC ACM) support
    <*> USB Wireless Device Management support

Now build your kernel as usual and reboot. When you now plug in your Android phone when it’s in USB Tethering mode, if all is well, you should be able to see a new network interface, usbX, X usually being 0. The link might be down, so check it with the command

$ ifconfig -a

Which will output something like this

usb0      Link encap:Ethernet  HWaddr 26:10:72:ab:38:0e  
            BROADCAST MULTICAST  MTU:1500  Metric:1
            RX packets:0 errors:0 dropped:0 overruns:0 frame:0
            TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Which means it all worked. Now all you have to do is run a DHCP request on that interface, and Android will handle the rest. You can set up a init.d script for this interface much the same way you would for a normal interface. Just make a symlink from /etc/init.d/net.lo to /etc/init.d/net.usb0 and run that script whenever you want.

Beautifying the whole thing

Running around on the console starting bootscripts like that doesn’t suit everyone, including me when I’m just on the road and stuff needs to work. I recommend using something like wicd or NetworkManager to handle it for you. Using wicd it’s pretty easy to make it automagically use the usb0 interface when it appears, so you’ll only have to plug it on for it to work.