Samstag, 3. November 2012

anacron simulation on a Synology NAS

This is a post not directly related to Android, but to my NAS where I am storing all my personal files. I bought the Synology DS212+ some month ago and I am very happy with it. Having two 2TB hard disks build in, another external harddisk is connected via USB 3.0 for backup resons. This Harddisk I am switching on and off manually from time to time and when it is switched on, a cron job should back up all the files of the DS using rsnapshot to my backup disk.

On a first glance this should not be such a big problem, but digging into it there are some problems to be solved:

  1. starting the backup once via cron, the external harddisk might be switched off and no backup will be done :(
  2. starting the backup regularly via cron might lead to multiple backups for a single day :(

Unfortunately Synology is not providing anacron which provides the possibility to specify such "run once a period" tasks. I digged a bit around, but I couldn't find a simple suitable solution for my needs, so I wrote a small shell script which does the trick:

#!/bin/ash
#
# shell script to run a job once a period
# it takes three parameters:
# - name of the runfile
# - period definition ("1 day", "2 days", ..., "1 week", "2 weeks", ... "1 month", etc.)
# - program to be executed (i.e. backup-program / script)
#
#
# some helper functions
#

date2stamp () {
    date --utc --date "$1" +%s
}

stamp2date (){
    date --utc --date "1970-01-01 $1 sec" "+%Y-%m-%d %T"
}

dateDiff (){
    case $1 in
        -s)   sec=1;      shift;;
        -m)   sec=60;     shift;;
        -h)   sec=3600;   shift;;
        -d)   sec=86400;  shift;;
        *)    sec=86400;;
    esac
    dte1=$(date2stamp $1)
    dte2=$(date2stamp $2)
    diffSec=$((dte2-dte1))
    echo $((diffSec/sec))
}
###########################################################
#
#main program
###########################################################
EXECUTE="0"
RUNFILE=/var/run/$1
LOCKFILE=/var/run/"$1".lock
if [ -f $LOCKFILE ]
then
        echo "other process running -> exiting" >> /var/log/runOnce.log
        exit 2
fi  
touch $LOCKFILE
#      
# check whether runfile exists
#      
NOW=`date -d 'now' --iso-8601`
if [ -f $RUNFILE ]
then
        NEXTRUN=`cat $RUNFILE`
        # check wether next run date is in the past
        if [ `dateDiff -d "$NEXTRUN" "$NOW"` -ge 0 ]
        then
                EXECUTE="1"
        fi
else
        # did not run yet -> run forced
        EXECUTE="1"
        NEXTRUN=`date -d 'now' --iso-8601`
fi

if [ "$EXECUTE" == "1" ]
then    
        # execute (i.e. backup)
        $3
        STATUS_CODE=$?
        if [ $STATUS_CODE -eq 0 ]
        then
                # set next execution date
                while [ `dateDiff -d "$NEXTRUN" "$NOW"` -ge 0 ]
                do
                        # add period
                        NEXTRUN=`date -d "$NEXTRUN + $2" --iso-8601`
                done
                # set next execution date
                echo $NEXTRUN > $RUNFILE
        fi      
fi      
rm $LOCKFILE
exit 0

This script in combination with some entries in my crontab did the trick. ;)

0 18-23 * * * root /root/runOnce.sh backupDaily "1 day" /root/runDailyBackup.sh
20 18-23 * * * root /root/runOnce.sh backupWeekly "1 week" /root/runWeeklyBackup.sh
40 18-23 * * * root /root/runOnce.sh backupMonthly "1 month" /root/runMonthlyBackup.sh

Dienstag, 23. Oktober 2012

G1 celebrates it's 4th birthday

Today four years ago the first G1s were put to the market. Ok, my G1 is no longer in it's first configuration (Android 1.5 Cupcake) because I've upgraded to ADS_Magpie (Gingerbread 2.3.7), but I am still using and loving it ... ;-) More on the G1's history you can read on: T-Mobile G1 Celebrates Its 4th Birthday (That’s 80 In Smartphone Years)

Samstag, 20. Oktober 2012

Nexus 7 MTP automount on OpenSuse 11.4

Unfortunately Android 4.x devices cannot be mounted as a VFAT device any longer. While with 4.0 only the PTP mode is supported (which can be used to transfer photos only), on 4.1 you can switch between PTP mode and MTP mode in the settings.

While Windows has an acceptable MTP support, on Linux systems MTP is not supported out of the box, even worse if you want to automount your android device when connecting it. Looking around, I found Han-Wen Nienhuys go-mtpfs project on Github.


install mtpfs support

go-mtpfs is based on libmtp. For OpenSuse 11.4 you need to download the latest rpm from pbone.net and to install it on your system

After that, you can either checkout the go-mtpfs project from github and compile it by yourself or, probably more easy, download the binary from here.

You can install the binaries in every place you like, but it should be either on your path configuration or you need to define the full path to the binary when using it.


configure automount

Automount on current Linux systems is initiated by the udev system. In /etc/udev/rules.d/ you will find a set of rules which define what should happen when a new device is added, removed, ...

Create or modify a new ruleset, i.e./etc/udev/rules.d/50-android.rules. Here we need to add the following rules regarding the Nexus 7 device:


# Google Nexus 7 16 Gb Bootloader & recovery mode
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e40", MODE="0666" # Bootloader
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0666" # Recovery

# Google Nexus 7 16 Gb PTP mode (camera)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e43", MODE="0666" # PTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e44", MODE="0666" # PTP media with USB debug on

# Google Nexus 7 16 Gb MTP mode (multimedia device)
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e41", MODE="0666" # MTP media
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4e42", MODE="0666" # MTP media with USB debug on

# Google Nexus 7 MTP mode : automatic mount when plugged
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="add", RUN+="/usr/bin/sudo -u /go-mtpfs /media/nexus7"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="add", RUN+="/usr/bin/sudo -u /go-mtpfs /media/nexus7"

# Google Nexus 7 MTP mode : automatic unmount when unplugged
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e41", ACTION=="remove", RUN+="/usr/bin/fusermount -u /media/nexus7"
ENV{ID_MODEL}=="Nexus", ENV{ID_MODEL_ID}=="4e42", ACTION=="remove", RUN+="/usr/bin/fusermount -u /media/nexus7"

Be sure, that the mount point /media/nexus7 exists and is accessable for your user.

After sudo /etc/init.d/boot.udev restart your Nexus 7 device should be mounted automatically to /media/nexus7 when plugged to your PC.

If you want to mount other devices, you only need to add the corresponding rules, i.e. you need to know the corresponding idVendor/idProduct values. Those you can figure out using the dmesg command after the device is plugged.

Freitag, 19. Oktober 2012

compile android 4.x on a 32-bit environment

Compiling Android from the sources should be the basis for your own modifications / improvements the the Android system. Unfortunately Google removed 32-bit support with Gingerbread (Android 2.3), but nevertheless with some minor modifications to the build scripts it was still possible to build on 32-bit Linux systems. When I got my Nexus 7, I intended to compile the Jelly Bean sources, but unfortunately I still have a 32-bit OpenSuse Linux machine and compilation failed. I dearched the web, but the only answers I could get were: "you need a 64-bit environment", "yopu need to buy a new machine", ... I was very disappointed, but then I found Yath's project on Github. Following his instructions compiling Jelly Bean on a 32-bit Linux machine is still possible and I can wait soem additional months to buy a new machine ... ;-)

Nexus 7 partition sizes (16Gb model)

Partition NamePartition Descriptionby_nameSize in BlocksSize in MB
mmcblk0p1recoverySOS1228812
mmcblk0p2bootLNX81928
mmcblk0p3systemAPP665600650
mmcblk0p4cacheCAC453632443
mmcblk0p5miscMSC5120.5
mmcblk0p6stagingUSP1024010
mmcblk0p7provisionedPER51205
mmcblk0p8unknownMDA5120.5
mmcblk0p9userdataUDA1410355213773
mmcblk0boot020482
mmcblk0boot120482

remote debugging over TCP/IP

You can debug your applications on your Android device not only over USB, but also over a TCP/IP (LAN / WLAN) connection. To enable tcp debugging you have to enter the following commands on your device:

setprop service.adb.tcp.port 5555
stop adbd
start adbd

To start debugging enter on your PC:

adb tcpip
adb connect <ip of device>
...

now you can debug as you are used to debugging over USB.

To disable debugging you have to enter the following commands on your device:

setprop service.adb.tcp.port -1
stop adbd
start adbd

More info can be found on Android Debug Bridge