Download Android Source Code on RaspberryPI

Just a try. I don’t think I will use raspberryPI for developing, but using it for downloading code is a good idea.
###Go Back Home My raspberryPI is behind the router, so I have to use a ssh tunnel to reach raspberryPI.
Setting up tunnel:

$ ssh -L 2230:10.0.0.230:22 Tomcat.xxx.xx.xxx -l root

Login on local port:

$ ssh root@localhost -p 2230

Now we have a terminal which could reach raspberry PI.
###Package Preparation Since the OS on my raspberryPI is ArchLinux, I have to install following packages:

$ pacman -S w3m tmux lynx

###Account Setting Use w3m for accessing https://android.googlesource.com/new-password

But, remember, I have a BBB which also runs at home, so I can also use it.

$ apt-get install elinks

Use elinks for making connection to https://android.googlesource.com/new-password, remember the username, and the machine and login name, just copy them into your ~/.netrc, and make sure you have the right priviledge for the file ~/.netrc.
###Repo sync This will take for a long~long time, depending on your bandwidth:

repo init -u https://android.googlesource.com/a/platform/manifest -b master

then we use the following file for sync the repo:

#!/bin/bash

while [ 1 ]
do
    repo sync -j8
    if [ "$?" = "0" ] ; then
        echo "rsync completed normally"
        exit
    else
        echo "Rsync failure. Backing off and retrying..."
        sleep 1
    fi
done

Now call tmux for holding the sync procedure:

$ tmux new -s Android
$ /bin/bash ./autodown.sh 2>&1 | tee autodown.log
$ ctrl+b d

The sync process now is held in tmux session. Let it go, next time when you want to see the procedure, just ssh to the board use:

tmux a -t Android

Deploy Snova On Heroku

###Setting Account First you have to install heroku deploy tool via:

$ heroku plugins:install https://github.com/heroku/heroku-deploy 

Then login and create the app:

$ heroku login
Enter your Heroku credentials.
Email: xxx@gmail.com
Password (typing will be hidden): 
Authentication failed.
$ $ heroku apps:create xxx
Creating xxx... done, stack is cedar
http://xxx.herokuapp.com/ | git@heroku.com:xxx.git

###Source Code Preparation Download the source code from https://code.google.com/p/snova/, here you need to cross the Greatwall.

wget https://code.google.com/p/snova/downloads/detail?name=snova-c4-java-server-0.22.0.war
wget https://code.google.com/p/snova/downloads/detail?name=snova-0.22.0.zip&can=2&q=

Here, we use the java version of the snova.
###Deploy Apps On Heroku Now begin to deploy your Snova:

heroku deploy:war --war ./snova-c4-java-server-0.22.0.war --app "Your_App_Name" 

###Configure Client unzip the snova-0.22.0.zip and configure it:

unzip snova-0.22.0.zip
cd snova-0.22.0
vim conf/snova.conf
[C4]
Enable=1
WorkerNode[0]=Your_App_Name.herokuapp.com 

You can create a shortcut for calling the Snova, add following line into ~/.bashrc:

alias snova='/home/Trusty/code/gfw/snova/snova-0.22.0/bin/start.sh'

###Configure Browser The proxy address is 127.0.0.1, the port is 48100 or 48102.

SD Card Migration

Following are the tips for operating a SD card under Linux.
###Backup SD Card We can use dd for backup sd card into an image file.

dd if=/dev/mmcblk0 of=Your_Image_Name.img bs=1M

You need to wait for a moment until all of the data dump working done.
###Write Into SD Card Also use dd for writing the image file into the SD card:

dd if=Your_Image_Name.img os=/dev/mmcblk0 bs=1M

Make sure your SD Card’s volumn is bigger than the image file.
###Dump SD Card Partition This is simple, because you can mount the part into some mount points, use following commands:

sudo mount /dev/mmcblock0px /Your_Mount_Point

Maybe you have to specify the partition types.
###Dump Image File Partition First you have to get the image file partition list via following command:

fdisk BBB_USB.img 

Welcome to fdisk (util-linux 2.24.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk BBB_USB.img: 7.5 GiB, 8035237888 bytes, 15693824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device       Boot     Start       End  Blocks  Id System
BBB_USB.img1 *         2048    100351   49152   e W95 FAT16 (LBA)
BBB_USB.img2         100352  15693823 7796736  83 Linux

From the above output, we know this image file consist of 2 partitions, the first one is a FAT16 partition, the second is the Linux Partition.
First we use loop device for setting up the partition 1:

# First losetup to delete the mounted equipment
$  losetup -d /dev/loop0
# Now use losetp to set the first partition
# 1048576 = 2048*512, 25165824 = 49152*512. 
$ losetup -v -f -o 1048576 --sizelimit 25165824 ./BBB_USB.img
$ sudo mount /dev/loop1 /mnt
$ cp -ar /mnt/* Your_Directory

For the second partition, we use following command:

# sudo mount ./BBB_USB.img -o offset=51380224 /mnt
# cp -ar /mnt/* Your_Directory

By doing this you can directly copy out the partition files.
###Make Filesystem on SD Card After partition, directly use mkfs.xxx to make filesystems on SD Card. Following is the command which is used for creating vfat fs on SD Card:

mkfs.vfat -F 16/32 -n boot /dev/mmcblk0p1

###Zip Image File You can use following command for zipping the image file, in order to saving the disk space:

bunzip2 z BBB_USB.img

or

tar cjvf BBB_USB.img.tar.bz2 BBB_USB.img

First command will remove the origin image file, while the second one will remain the origin image.

Customize Awesome

###Wallpaper Setting When switching to big display in awesome, the desktop background will not fill the whole screen, thus we need to automatically set the background when we execute the ./singleview script, ./singleview script is a script which I wrote for switching to big display. Listed as following:

killall conky
xrandr --output LVDS1 --off
xrandr --newmode $(gtf 1680 1050 60 | grep Modeline | sed s/Modeline\ // | tr -d '"')
xrandr --addmode VGA1 1680x1050_60.00
xrandr --output VGA1 --mode 1680x1050_60.00 
xscreensaver -nosplash &
xset -b
xmodmap -e "pointer = 3 2 1"
fcitx &
sleep 4
###Add bluetooth
pactl load-module module-alsa-sink device=btheadset 
pacmd load_module module-bluetooth-discover
###Set Background
feh --bg-scale /home/Trusty/document/water.jpg

The last line is the newly-added one which is used for re-setting the background wallpaper.
###Conky Background Setting But when you set the background, your conky will become ugly, just like following picture:
/images/nobg.jpg

So you need to set the ~/.conky.rc, add following lines:

own_window yes
own_window_colour 41A834
TEXT
......
${image  /home/Trusty/document/greenleaf2.jpg  -p 0,0 -s 300x540}

The “own_window yes” could be commented.
So now you got conky looks like following:
/images/goodbg.jpg

Customize Awesome Startup Application

Let applications automatically start at boot will greatly save your time in configurating the system. Following is some tips on how to automatically start applications in awesome desktop environment.
###Xinit Way My startup configuration is listed as:

export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
exec awesome

So the awesome environment will be started.
###Awesome Way Run only once in awesome desktop, via following configuration file:

function run_once(cmd)
  findme = cmd
  firstspace = cmd:find(" ")
  if firstspace then
    findme = cmd:sub(0, firstspace-1)
  end
  awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. cmd .. ")")
end

run_once("udiskie -2 --tray")
run_once("wicd-client --tray")

Add the code into ~/.config/awesome/rc.lua, then you can get the udiskie and wicd-client icon in the tray.
###Change View Way

#dualview
killall conky
xrandr --output LVDS1 --mode 1366x768
xrandr --newmode $(gtf 1920 1080 60 | grep Modeline | sed s/Modeline\ // | tr -d '"')
xrandr --addmode VGA1 1920x1080_60.00
xrandr --output VGA1 --mode 1920x1080_60.00 --right-of LVDS1
xscreensaver -nosplash &
xset -b
xmodmap -e "pointer = 3 2 1"
fcitx &
sleep 2
sudo whatpulse &
conky &


###Systemd Way For example, we want to enable xampp.service on every start:

[root@DashArch system]# pwd
/etc/systemd/system
[root@DashArch system]# cat xampp.service

[Unit]
Description=xampp for ArchLinux, locate in /opt/lampp
After=network.target

[Service]
ExecStart=/opt/lampp/lampp start 
ExecStop=/opt/lampp/lampp stop
Type=forking

[Install]
WantedBy=multi-user.target

Then we can start/stop the service, enable/disable the service via:

systemctl start xampp.service
systemctl stop xampp.service
systemctl enable xampp.service