metaUser

How deep does the rabbit hole go?

Finally a new post and site update

Converting My Blog from Django

I've been unhappy with the state of my blog for months, hence why I haven't updated in a very long time, and with work being a constant firefight it seems. I've been lacking motivation to do anything tech releated when I got home.

I'm redoing the site in pelican, which is a python powered static site generator. I'm not currently planning on moving hosting off my current vps, least not for now, I will move it to my works hosting soon. I will still need to work out some details with the site and add a few minor features here and there, as well as figure out the best gameplan for publishing. I will get it linked up to my github or bitbucket repos eventually as well.

more updates and getting back to consistent posts again!

Installing ClockworkMod Recovery on G2x from Linux

I said I was going to write about my experiences with this... and never came back to it. I've been running custom ROM's since my first post about rooting my G2x. However, I honestly was a little unsure about the whole process so I didn't want to write about the other bits. I went back through and upgraded ClockWorkMod Recovery again, this time it was a little less unnerving so, I will write down my steps here. First... I'm following bits from this xda thread

I downloaded the rar file and pulled out the bits needed for ClockWorkMod (CWM) 5.0.2.0, so I could flash it from linux. I originally had a script that I used to flash this... my appologies I don't remember where, nor do I want to claim it as my own... I will include it however at the bottom of this post. Anyway, here goes. After grabbing the files above and the nvflash bin and a script, I put all of this in a CWM-5.0.2 directory

mitch@kraven:~/g2xroot/CWM-5.0.2$ ls -l
total 5008
-rw-r--r-- 1 mitch mitch 3563520 2011-09-06 20:58 CWM-5020.img
-rw-r--r-- 1 mitch mitch    4080 2011-04-21 00:40 E1108_Hynix_512MB_H8TBR00U0MLR-0DM_300MHz_final_emmc_x8.bct
-rw-r--r-- 1 mitch mitch 1024992 2011-04-21 12:00 fastboot.bin
-rwxr-xr-x 1 mitch mitch     125 2011-10-01 15:59 flash-recovery.sh
-rwxr-xr-x 1 mitch mitch  526131 2011-10-01 15:58 nvflash

Before running the script, you need to connect your phone, follow these steps: - pull the battery on my phone - plug USB cable in laptop - Hold Volume Up AND Volume Down - WHILE holding #3, plug in USB to phone

This should result in a PCI connection to your phone... Your phone will not do anything.

mitch@kraven:~/g2xroot/CWM-5.0.2$ lspci
....
15:00.2 SD Host controller: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter (rev 21)
15:00.4 System peripheral: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter (rev 11)
15:00.5 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev 11)

From there, you run the flash-recovery.sh script.

mitch@kraven:~/g2xroot/CWM-5.0.2$ ./flash-recovery.sh 
Nvflash started
rcm version 0X20001
System Information:
   chip name: unknown
   chip id: 0x20 major: 1 minor: 3
   chip sku: 0xf
   chip uid: 0x02884207417fe4d7
   macrovision: disabled
   hdcp: enabled
   sbk burned: false
   dk burned: false
   boot device: emmc
   operating mode: 3
   device config strap: 0
   device config fuse: 17
   sdram config strap: 0


downloading bootloader -- load address: 0x108000 entry point: 0x108000
sending file: fastboot.bin
/ 1024992/1024992 bytes sent
fastboot.bin sent successfully
waiting for bootloader to initialize
bootloader downloaded successfully
sending file: CWM-5020.img
| 3563520/3563520 bytes sent
CWM-5020.img sent successfully

At this point... you phone will be showing a "software upgrade is in progress" screen... even after it completes... the above output took around 15 seconds to play out... and they say you can unplug right after this.. I left it pluged in for another 30 seconds... cause it makes me nervous... (probably unfounded...) Download files here

Sync Directory to S3

I needed the ability to sync a directory to S3 for a client... so I wrote up a script I'm calling sync2S3.py. Some of the code came from the Django extensions project, which I modified to work without django and just sync a directory in an rsync like fashion. Enjoy

Rooting G2x from Ubuntu

ince my only desktop is my work Lenovo ThinkPad running Ubuntu 11.04, and the bulk of the articles out there reference Windows... I did find a few articles articulating how to root the T-Mobile G2x, but I thought I'd do a full write up here over what exactly I did to root my G2x and will do a followup with flashing a CyanogenMod Nightly to it as well. First, I downloaded the latest Android SDK from Google I extracted the tarball and renamed it to androidsdk in my home directory:

$ tar -zxvf Downloads/android-sdk_r11-linux_x86.tgz
$ mv android-sdk-linux_x86 androidsdk

I then added the following to my .bashrc file and load it into your environment variables

$ export PATH=${PATH}:$HOME/androidsdk/tools:$HOME/androidsdk/platform-tools
$ source .bashrc

The directory, platform-tools, will not exist yet, and you will need to download the Android SDK Platform-tools. To do this, you will run the command

$ android

This will startup a GUI, click Available packages -> Android Repository -> Android SDK Platform-tools, revision 5 (Revision may be updated... this was the version when I did this) Click Install Selected wait till finished and close. Now, we need to update udev to setup the proper device permissions for when we connect our phone.

$ sudo echo 'SUBSYSTEM=="usb", SYSFS{idVendor}=="1004", MODE="0666"' >> /etc/udev/rules.d/51-android.rules

the idVendor string is unique per manufacturer, there is a list of them on Android Development here, But I've used the LG one here, since they're the maker of the G2x. Then you need to restart udev

$ sudo service udev restart

Now... we're almost done. I first attempted to use the SuperOneClick root... which wasn't working for me. I then found a shell script that was a simple root to... thought I'd give it a go, and it worked easily, which can be downloaded on xda I will note that... at this point, you should be able to connect your phone via USB, turn on USB Debug Mode. Settings -> Applications -> Development -> USB Debugging. Then run: adb devices. Should return this... or something similar at least... not sure what the hex number is... serial#?

$ adb devices
List of devices attached 
02884207417fe4d7    device

After Downloading the G2xRootMacLinux_v0.5.zip and unzipping it.

mitch@kraven:~$ mkdir g2xroot
mitch@kraven:~$ cd g2xroot/
mitch@kraven:~/g2xroot$ unzip ../Downloads/G2xRootMacLinux_v0.5.zip 
Archive:  ../Downloads/G2xRootMacLinux_v0.5.zip
   creating: G2xRootMacLinux_v0.5/
   creating: G2xRootMacLinux_v0.5/files/
  inflating: G2xRootMacLinux_v0.5/files/adb_linux  
  inflating: G2xRootMacLinux_v0.5/files/adb_mac  
  inflating: G2xRootMacLinux_v0.5/files/busybox  
  inflating: G2xRootMacLinux_v0.5/files/psneuter  
  inflating: G2xRootMacLinux_v0.5/files/shared.sh  
  inflating: G2xRootMacLinux_v0.5/files/su  
  inflating: G2xRootMacLinux_v0.5/files/Superuser.apk  
  inflating: G2xRootMacLinux_v0.5/Readme.txt  
  inflating: G2xRootMacLinux_v0.5/root.command  
  inflating: G2xRootMacLinux_v0.5/unroot.command  
mitch@kraven:~/g2xroot$ ls
 G2xRootMacLinux_v0.5
mitch@kraven:~/g2xroot$ cd G2xRootMacLinux_v0.5/
mitch@kraven:~/g2xroot/G2xRootMacLinux_v0.5$ ls
files  Readme.txt  root.command  unroot.command
mitch@kraven:~/g2xroot/G2xRootMacLinux_v0.5$ less Readme.txt 
mitch@kraven:~/g2xroot/G2xRootMacLinux_v0.5$ ./root.command

Checking for connected device...
Pushing temporary root exploint (psneuter) to device...
1262 KB/s (585731 bytes in 0.453s)
Running psneuter on device...
property service neutered.
killing adbd. (should restart in a second or two)
Waiting for device...
Remounting /system read/write...
remount succeeded
Pushing su to /system/bin/su...
635 KB/s (26324 bytes in 0.040s)
Pushing busybox to /system/bin/busybox...
1253 KB/s (1062992 bytes in 0.827s)
Installing Superuser.apk android application...
1283 KB/s (196521 bytes in 0.149s)
Removing psneuter from device...


Rebooting device...

Once device has rebooted you should be rooted.
Press Enter when you're ready to quit:  
mitch@kraven:~/g2xroot/G2xRootMacLinux_v0.5$

And that was it. Phone is rooted. Many Thanks to jnichols959 for the scripts! Next up CyanogenMod Nightly

Junos EX Switch last port flap

Here is a little script I wrote that logs into a Juniper EX switch and grabs the port status of all interfaces in a down state, then checks to see their "LastFlap" state... which translates into how long the port has been in a down state. This script depends on a wrapper for SSH (ssh.py) which I grabbed here: http://commandline.org.uk/python/sftp-python-really-simple-ssh/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
##
## Mitch - May 17th 2010
## This script logs into a Juniper EX Switch, lists out ports, greps for downed
## ports, and then checks each to see how long they've been in a down state.
##
## This script logs into the switch with the provided username/password
##


import re,sys,getpass,getopt


mesg = """ This script depends on python-paramiko please install it...."""


try:
    import ssh
except:
    print mesg
    sys.exit(1)


def getLastFlapped(port,sshconn):
    '''Return the Date and Time of the Last time the port flapped'''
    lastflapped = sshconn.execute('show interfaces %s | grep Last' % port)[0]
    lastflapped = lastflapped.split(':',1)[1]
    return lastflapped.strip()


def main(outfile=None):
    # get switch information
    switch = raw_input("Switch to connect to: ")
    username = raw_input("Username [%s]: " % getpass.getuser())
    if username == None:
        username = getpass.getuser()
    password = getpass.getpass("Password: ")


    # connect to switch
    try:
        s = ssh.Connection(host = switch, username = username, password = password)
    except:
        print "There was an error connecting to %s." % switch
        sys.exit(2)


    portList = []
    # grab our list and get out
    output = s.execute('show interfaces terse | grep down | except \.0 | grep ge-')
    for port in output:
        port = port.strip()
        if port == '': continue
        p = port.split()[0]
        portList.append({'port': p, 'lastflapped': getLastFlapped(p, s)})
    s.close()


    # process and write the output to a variable
    display = "Ports currently down on switch %s:  \n" % switch
    for p in portList:
        display = display + " %s\t: %s\n" % (p['port'],p['lastflapped'])

    # Check to see if we are to write the output to a file
    # or the screen
    if outfile: 
        try:    
            f = open(outfile, 'w')
        except:
            print "Error... couldn't write to %s" % outfile
            sys.exit(3)


        f.write(display)
        f.close()
    else:
        print display



if __name__ == '__main__':
    try:
        opts, args = getopt.getopt(sys.argv[1:], "f:", ["file="])
    except getopt.GetoptError, err:
        print str(err)
        sys.exit(1)


    for o, a in opts:
        if o in ("-f", "--file"):
            outfile = a

    try:
        main(outfile)
    except:
        main()

OSPF on Juniper EX4200 Switches

At work, I had a situation arrive where I have two buildings connected together with Metro Optical Ethernet. There are two lines, one 100Mbit Ethernet line through Utopia and another 200Mbit Ethernet line through Qwest. I initially had a simple /30 subnet static route accross each line, with preferences as to which line to use. However... since these lines have optical to ethernet devices on each end... the only way my simple static route would fail over was if those devices lost power and shut down the link between them and my switches. So something a little more redundant that would check the actual connectivity of the lines was needed.

Enter OSPF, I had decided on using OSPF to enable dynamic routing for these networks. I will past show the relavent bits of my code here for future reference. From my hub switch (main switch... with default route connected)

policy-options {
    policy-statement export_default_route_into_ospf {
        from term1
            from {
                route-filter 0.0.0.0/0 exact;
            }
            then accept;
         }
         term term2 {
            then reject;
         }
    }
}
protocols {
    ospf {
        export export_default_route_into_ospf;
        area 0.0.0.0 {
            interface ge-0/0/1.0 {
                metric 10;
            }
            interface ge-1/0/1.0 {
               metric 20;
            }
    }
}

From the spoke switch:

protocols {
    ospf {
        area 0.0.0.0 {
            interface ge-0/0/1.0 { 
                metric 10;
            }
            interface ge-1/0/1.0 {
                metric 20;
            }
            interface vlan.101 {
                passive;
            }
            interface vlan.102 {
                passive;
            }
        }
    }
}

For simplicity's sake, interface ge-0/0/1.0 is connected to the same interface on the other switch stack... But that should be the whole config... each vlan on the spoke side, needs to be added to the same ospf area to be advertised to the other side. After adding this... i was able to remove my static routes and everything has worked fine since. I've even had problems with the line since then... it failed over with out much trouble. I didn't even get a call about it.