#!/bin/bash # back up stuff from siemens C65, set time etc... # by jkt@flaska.net DEVICE=/dev/tts/USB0 DATE=`date "+%Y-%m-%d--%H-%M-%S"` DIR=~/siemens-backup OUT=$DIR/$DATE export SLINK_DEVICE=$DEVICE dummy_workaround() { # let's try to touch the phone by requesting memory info as suggested by avi.b@tiscali.cz slink i > /dev/null # ... but let's wait as well as the phone might be extremely braindead :( sleep 1 } check_result() { if [[ "$res" -eq "0" ]] ; then echo "ok" else echo "failed ($res)" fi } set_time() { echo -n "setting time... " scmxx --device $DEVICE --set-time &> /dev/null local res=$? check_result } get_phonebook() { echo -n "retrieving phonebook... " slink g telecom/pb.vcf $OUT/pb.vcf &>/dev/null local res=$? check_result } get_calendar() { echo -n "retrieving calendar... " slink g telecom/cal.vcs $OUT/cal.vcs &>/dev/null local res=$? check_result } gammu_sms() { echo -n "fetching all SMS via gammu... " gammu --geteachsms > $OUT/sms-complete.gammu local res=$? check_result } fetch_sms_slot() { local slot=$1 if [[ "$REMOVE" == "yes" ]] ; then local myopts="--remove" local msg=" and removing" else local myopts="" local msg="" fi echo -n "fetching${msg} $slot SMS... [" scmxx --device $DEVICE --sms --get --slot=$slot $myopts --out=$OUT/sms-$slot 2>&1 >/dev/null \ | egrep --line-buffered "(Found|was deleted)" \ | sed --unbuffered "s:Found .* SMS in slot ::;s:SMS slot :D:;s: was deleted.::;s:\.::" | awk 'ORS=" " {print $1}' # | grep --line-buffered "Found" | sed --unbuffered "s/\.$//" | awk 'ORS=" " {print $7}' echo "]" # FIXME: can't check the result of `scmxx` this way... #local res=$? #check_result } echo "Starting daily backup to $OUT" mkdir $OUT || { echo "unable to mkdir $OUT" exit } if [[ "$1" == "--remove-sms" ]]; then REMOVE=yes touch $OUT/sms.REMOVED else REMOVE=0 fi set_time dummy_workaround get_phonebook dummy_workaround get_calendar gammu_sms # That REMOVE magic is to prevent accidental deletion # of UNREAD messages. Let's hope it works... fetch_sms_slot read REMOVE=0 fetch_sms_slot unread fetch_sms_slot sent fetch_sms_slot unsent echo "Backup hopefuly completed"