Subversion checkout script

Here’s a simple script to check out all subversion repositories on a remote host. It requires that you have SSH access on the host, to be able to fetch the repository names (otherwise you can hardcode them in $repositories). You’ll also need to have Perl installed.

How to use:

  1. Download checkout-all-svn.sh.
  2. chmod u+x path/to/checkout-all-svn.sh
  3. path/to/checkout-all-svn.sh -r http://example.org/svn/

Some features:

  • Works with plain /bin/sh, so it should work on any Linux / BSD distribution.
  • Works with repository names with spaces, but not yet with unusual characters.

checkout-all-svn.sh

#!/bin/sh
#
# $Id: checkout-all-svn.sh 387 2008-06-07 20:36:08Z vengmark $
#
# NAME
#    checkout-all-svn.sh - Check out all Subversion repositories.
#
# SYNOPSIS
#    checkout-all-svn.sh [options]
#
# OPTIONS
#    -v     Verbose output
#    -p     Target host SSH port
#    -u     Target host SSH user name
#    -d     Subversion repository directory on target host
#    -r     URL part before the repository name,
#           e.g. https://example.org/svn/
#
# EXAMPLE
#    ./checkout-all-svn.sh -v -p 1234 -u ssh-admin -d /var/lib/svn -r
#    https://example.com/reps/
#
# DESCRIPTION
#    Gets all your subversion repositories. If they are already
#    present, they will be updated.
#
#    The current (or specified with -u) user must have SSH access to the remote
#    host. To circumvent this you can specify the repository names in
#    $repositories, separated by newlines.
#
#    To avoid having to type your password several times, you can setup SSH
#    keys - See e.g. https://help.ubuntu.com/community/SSHHowto
#
# BUGS
#    Email bugs to victor dot engmark at gmail dot com. Please include the
#    output of running this script in verbose mode (-v).
#
# COPYRIGHT AND LICENSE
#    Copyright (C) 2008 Victor Engmark
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

# Init
ifs_original="$IFS" # Reset when done

PATH="/usr/bin:/bin"
cmdname=`basename $0`
directory=`dirname $0`
target_dir=~

# Remote host
target_port=22
target_user=`whoami`

# Subversion
svn_root="/var/lib/svn"

#Error messages
errm_unknown="Unknown error in $cmdname" #Code 1
#Code 2 is reserved: http://www.faqs.org/docs/abs/HTML/exitcodes.html
usage="Usage: ${cmdname} [-v] [-p port] [-u user] [-d svn_directory] -r repositories_url" #Code 3

# Process parameters
until [ $# -eq 0 ]
do
	case $1 in
		-v)
			verbose=1
			shift
			;;
		-p)
			if [ -z "$2" ]
			then
				echo "$usage" >&2
				exit 3
			fi
			target_port=$2
			shift 2
			;;
		-u)
			if [ -z "$2" ]
			then
				echo "$usage" >&2
				exit 3
			fi
			target_user=$2
			shift 2
			;;
		-d)
			if [ -z "$2" ]
			then
				echo "$usage" >&2
				exit 3
			fi
			svn_root=$2
			shift 2
			;;
		-r)
			if [ -z "$2" ]
			then
				echo "$usage" >&2
				exit 3
			fi
			base_url=$2
			shift 2
			;;
		*)
			#Unknown parameter
			if [ $verbose ]
			then
				echo "Unknown parameter: $1" >&2
			fi
			echo "$usage" >&2
			exit 3
			;;
	esac
done

if [ ! $base_url ]
then
	echo "$usage" >&2
	exit 3
fi
base_url=`echo $base_url | sed "s/ /%20/g"` # To avoid problems with spaces

target_host=$base_url
target_host=${target_host#*//}
target_host=${target_host%%/*}
if [ $verbose ]
then
	echo "Target host: ${target_host}"
fi

repositories=`ssh -p ${target_port} ${target_user}@${target_host} $(if [ $verbose ]; then echo '-v'; else echo '-q'; fi;) -x "ls '${svn_root}'"`
error=$?
if [ $error -ne 0 ]
then
	echo "Failed to get repository names. Error code $error" >&2
	exit 1
fi
if [ $verbose ]
then
	echo "Repositories:\n${repositories}"
fi

IFS="
" # Make sure paths with spaces don't make any trouble when looping

# Concatenate URLs
rep_urls=""
for repository in $repositories
do
	repository=`echo $repository | sed "s/ /%20/g"`
	rep_urls="${rep_urls} ${base_url}${repository}"
done

IFS="$ifs_original"

svn co $rep_urls --non-interactive -r 'HEAD' `if [ ! $verbose ]; then echo '--quiet'; fi;` "${target_dir}"

# End
exit 0
Advertisements

Subversion backup script

Following up on the good work of Jean-Francois Roy, here’s my slightly extended version of his script to backup all Subversion repositories to a remote host.

How to use:

  1. Download backup-all-svn.sh
  2. chmod u+x path/to/backup-all-svn.sh
  3. ./backup-all-svn.sh -h target_host (can also set target port and user name)

Some features:

  • Works with plain /bin/sh, so it should work on any Linux / BSD distribution.
  • Works with repository names with spaces and non-ASCII characters.

backup-all-svn.sh

#!/bin/sh
#
# $Id: backup-all-svn.sh 387 2008-06-07 20:36:08Z vengmark $
#
# NAME
#    backup-all-svn.sh - Backup all Subversion repositories
#
# SYNOPSIS
#    backup-all-svn.sh [options]
#
# OPTIONS
#    -v     Verbose output
#    -h     Target host name (mandatory)
#    -p     Target host port
#    -u     Target host user name
#
# EXAMPLE
#    ./backup-all-svn.sh -v -h example.com -p 1234 -u johndoe
#
# DESCRIPTION
#    Backups all your subversion repositories to a remote machine.
#
#    The current user must have access to the subversion repositories.
#    To work around this, you should `sudo adduser <username> <svn-group>`
#    and `sudo chmod -R g+w /path/to/repos`.
#
#    To avoid having to type your password several times, you can setup SSH
#    keys - See e.g. https://help.ubuntu.com/community/SSHHowto
#
# BUGS
#    Email bugs to victor dot engmark at gmail dot com. Please include the
#    output of running this script in verbose mode (-v).
#
# COPYRIGHT AND LICENSE
#    Copyright (C) 2005 Jean-Francois Roy
#    Copyright (C) 2008 Victor Engmark
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

# Init
ifs_original="$IFS" # Reset when done

PATH="/usr/bin:/bin"
cmdname=`basename $0`
directory=`dirname $0`

# Remote host
target_dir=".svn-backup/`date +%G-%m-%d`"
target_port=22
target_user=`whoami`

# Subversion
svn_root="/var/lib/svn"
svn_install_root="/usr/bin"

# Error messages from /usr/include/sysexits.h, recommended by
# http://www.faqs.org/docs/abs/HTML/exitcodes.html
EX_OK=0
EX_USAGE=64
EX_CANT_CREATE=73

# Custom errors
EX_NO_SUCH_DIR=91
EX_NO_SUCH_EXEC=92

usage_error()
{
	echo "Usage: ${cmdname} [-v] -h host [-p port] [-u user]" #Code 3 
	exit $EX_USAGE
}

# Process parameters
until [ $# -eq 0 ]
do
	case $1 in
		-v)
			verbose=1
			shift
			;;
		-h)
			if [ -z "$2" ]
			then
				usage_error
			fi
			target_host=$2
			shift 2
			;;
		-p)
			if [ -z "$2" ]
			then
				usage_error
			fi
			target_port=$2
			shift 2
			;;
		-u)
			if [ -z "$2" ]
			then
				usage_error
			fi
			target_user=$2
			shift 2
			;;
		*)
			#Unknown parameter
			usage_error
			;;
	esac
done

if [ -z ${target_host} ]
then
	usage_error
fi

# Use for mandatory directory checks
# $1 is the directory path
# $2 is the (optional) error message
check_directory()
{
	if [ ! -d $1 ]
	then
		echo "No such directory: '${1}'" >&2
		echo $2 >&2
		exit $EX_NO_SUCH_DIR
	fi
}

check_directory $svn_root "Please change \$svn_root to point to the directory where your Subversion repositories are."

check_directory $svn_install_root "Please change \$svn_install_root to point to the directory where Subversion is installed."

# Make sure an executable is available
# $1 is the path to the executable
# $2 is the (optional) error message
check_executable()
{
	if [ ! -x $1 ]
	then
		echo "No such executable: '${1}'" >&2
		echo $2 >&2
		exit $EX_NO_SUCH_EXEC
	fi
}

svn_install_missing="Please change \$svn_install_root to point to the directory where Subversion is installed."
check_executable ${svn_install_root}/svnlook $svn_software_missing
check_executable ${svn_install_root}/svnadmin $svn_software_missing

# Create the temporary folder
temp_dir=`mktemp -t -d ${cmdname}.XXXXXXXXXX` || exit $?

verbose_echo()
{
	if [ $verbose ]
	then
		echo "$*"
	fi
}

# Announce that we're running
verbose_echo "Running $cmdname at `date`."

# Create target directory
ssh -p ${target_port} ${target_user}@${target_host} "mkdir -p \"${target_dir}\"" || exit $?

# Loop over repositories
cd "${svn_root}"
IFS="
" # Make sure paths with spaces don't make any trouble when looping
for repository in *
do
	# Get the last revision
	revision=`${svn_install_root}/svnlook youngest "${repository}"`
	verbose_echo "Backing up repository \"${repository}\" revision ${revision}."

	# Make sure the repo is OK
	verbose_echo "Recovering the repository."
	${svn_install_root}/svnadmin recover --wait "${repository}" > /dev/null

	# Did the recover operation fail?
	if [ $? -ne 0 ]
	then
		echo "Backup failed because recovery failed." >&2
		break
	fi

	# Hotcopy
	verbose_echo "Hot-copying the repository."
	${svn_install_root}/svnadmin hotcopy --clean-logs "${repository}" "$temp_dir/${repository}"

	# Did the hotcopy fail?
	if [ $? -ne 0 ]
	then
		echo "Backup failed because hotcopy failed." >&2
		rm -Rf "$temp_dir"
		break
	fi

	# Compress the hotcopy
	verbose_echo "Compressing the repository in a tar.bz2 archive."
	archive="${repository}-r${revision}.tar.bz2"
	tar -cjpf "$temp_dir/${archive}" -C "$temp_dir" "${repository}"

	# Send it over
	verbose_echo "Copying repository archive to remote host."
	scp -P ${target_port} "$temp_dir/${archive}" "${target_user}@${target_host}:\"${target_dir}/${archive}\""

done

verbose_echo "Cleaning up."
rm -Rf $temp_dir
IFS="$ifs_original"

# End
verbose_echo "${cmdname} completed at `date`."

exit $EX_OK

Recursive symbolic link creation script

This might be useful if you keep your settings (.bashrc, .subversion/config, etc.) outside the home directory, like in a Subversion repository. Just copy the following script to the repository directory corresponding to $HOME and run
/path/to/make-links.sh
to create symlinks from ~ to each file in the repository, recursively.

If you don’t want to use meld to see differences, just change the diff variable near the top of the code.

Edit 2: Now actually does something useful if the target file already exists or the target directory does not exist.

make-links.sh

#!/bin/sh
#
# $Id: make-links.sh 1870 2009-11-10 08:56:35Z vengmark $
#
# NAME
#    make-links.sh - Make symlinks to all user settings in repository
#
# SYNOPSIS
#    make-links.sh [options]
#
# OPTIONS
#    -v,--verbose    Verbose output
#    -d              Specify the source and target directories for the symlinks
#
# EXAMPLE
#    /path/to/make-links.sh -d ~/settings/user ~
#
#    Create links in the home directory based on files in ~/settings/user
#
#    /path/to/make-links.sh -v
#
#    Create links in / based on files in the directory of make-links.sh
#
# DESCRIPTION
#    If the file in the source directory doesn't exist in the target directory,
#    a symlink is created directly.
#    If the file exists, or the target directory does not exist, the user is
#    given options to continue.
#
# BUGS
#    Email bugs to victor dot engmark at gmail dot com. Please include the
#    output of running this script in verbose mode (-v).
#
# COPYRIGHT AND LICENSE
#    Copyright (C) 2008-2009 Victor Engmark
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

# Output error message with optional error code
error()
{
    if [ -z "$2" ]
    then
        error_code=$EX_UNKNOWN
    else
        error_code=$2
    fi
    echo "$1" >&2
    exit $error_code
}

usage()
{
    error "Usage: ${cmdname} [-v|--verbose] [-d source target]" $EX_USAGE
}

verbose_echo()
{
    if [ $verbose ]
    then
        echo "$*"
    fi
}

# Use for mandatory directory checks
# $1 is the directory path
# $2 is the (optional) error message
directory_exists()
{
    if [ ! -d $1 ]
    then
        error "No such directory '${1}'
$2" $EX_NO_SUCH_DIR
    fi
}

# Make sure an executable is available
# $1 is the path to the executable
# $2 is the (optional) error message
executable_exists()
{
    if [ ! -x $1 ]
    then
        error "No such executable '${1}'
$2" $EX_NO_SUCH_EXEC
    fi
}

ifs_original="$IFS" # Reset when done
IFS="
" # Make sure paths with spaces don't make any trouble when looping

PATH="/usr/bin:/bin"
cmdname=`basename $0`
directory=$(dirname $(readlink -f $0))

diff=/usr/bin/meld
source_base="${directory}/home/$(whoami)/"
target_base="$HOME"

# Exit codes from /usr/include/sysexits.h, as recommended by
# http://www.faqs.org/docs/abs/HTML/exitcodes.html
EX_OK=0           # successful termination
EX_USAGE=64       # command line usage error
EX_DATAERR=65     # data format error
EX_NOINPUT=66     # cannot open input
EX_NOUSER=67      # addressee unknown
EX_NOHOST=68      # host name unknown
EX_UNAVAILABLE=69 # service unavailable
EX_SOFTWARE=70    # internal software error
EX_OSERR=71       # system error (e.g., can't fork)
EX_OSFILE=72      # critical OS file missing
EX_CANTCREAT=73   # can't create (user) output file
EX_IOERR=74       # input/output error
EX_TEMPFAIL=75    # temp failure; user is invited to retry
EX_PROTOCOL=76    # remote error in protocol
EX_NOPERM=77      # permission denied
EX_CONFIG=78      # configuration error

# Custom errors
EX_UNKNOWN=1
EX_NO_SUCH_DIR=91
EX_NO_SUCH_EXEC=92

# Process parameters
until [ $# -eq 0 ]
do
    case $1 in
        -v|--verbose)
            verbose=1
            shift
            ;;
	-d)
	    if [ -z "$2" ] || [ -z "$3" ]
	    then
		usage_error
	    fi
	    source_base=$2
	    target_base=$3
	    shift 3
	    ;;
        *)
            # Unknown parameter
            usage
            ;;
    esac
done

verbose_echo "Running $cmdname at `date`."

# Make sure the directory paths don't end with a slash
source_base="${source_base%\/}"
target_base="${target_base%\/}"

# Preliminary checks
directory_exists "$source_base"
directory_exists "$target_base"

verbose_echo "Source directory: '${source_base}'"
verbose_echo "Target directory: '${target_base}'"

# Find files excluding .svn directories
for source_path in `find "$source_base" -mindepth 1 -type f | grep -v "/.svn/"`
do
    target_path="${target_base}${source_path#${source_base}}"
    target_dir="$(dirname "${target_path}")"
    unset replace_file
    unset create_dir

    verbose_echo ""
    verbose_echo "Source file: \"${source_path}\"."
    verbose_echo "Target file: \"${target_path}\"."

    # Trivial case
    if [ -L "$target_path" ]
    then
        verbose_echo "\"${target_path}\" is already a symlink; skipping."
        continue
    fi

    # File exists
    if [ -f "$target_path" ]
    then
        # Make sure we skip or replace in the end
        while ! expr "$replace_file" : "^[SsRr]$" > /dev/null
        do
            echo "\"${target_path}\" is a proper file. What do you want to do?"
            read -p "[S]kip, [D]iff, [R]eplace: " replace_file
            if expr "$replace_file" : "^[Dd]$" > /dev/null
            then
                verbose_echo "Diffing \"${source_path}\" and \"${target_path}\""
                $diff "$source_path" "$target_path"
            fi
        done

        if expr "$replace_file" : "^[Rr]$"
        then
            verbose_echo "Removing ${target_path}"
            rm "$target_path"
        else
            continue
        fi
    fi

    # Not a proper file
    if [ -e "$target_path" ]
    then
        echo "\"${target_path}\" exists but is not a file; skipping."
        continue
    fi

    # Directory missing; might have to create it
    if [ ! -e "$target_dir" ]
    then
        while ! expr "$create_dir" : "^[SsCc]$" > /dev/null
        do
            echo "\"${target_dir}\" doesn't exist. What do you want to do?"
            read -p "[S]kip or [C]reate: " create_dir
        done

        if expr "$create_dir" : "^[Cc]$" > /dev/null
        then
            mkdir -p "$target_dir"
        else
            continue
        fi
    fi

    echo "Creating symlink at \"${target_path}\"."
    ln -s "$source_path" "$target_path"
done

verbose_echo "Cleaning up."
IFS="$ifs_original"

verbose_echo "${cmdname} completed at `date`."
exit $EX_OK

HOWTO: Synchronizing vCard address books with Nokia 6300 via Bluetooth on Ubuntu Linux

Edit: After learning a bit of sed magic, this is now a single script.

This Works For Me™, and I hope it works with other phones and on other distributions as well, but no guarantees.

Here’s how:

  1. Download synchronize-bluetooth.sh.
  2. chmod u+x synchronize-bluetooth.sh
  3. sudo apt-get install gnokii
  4. Setup Gnokii (replace the phone name): echo -e "[global]\nmodel = 6510\nport = $(hcitool scan | grep 'phone name' | cut --fields=2)\nconnection = bluetooth" > ~/.gnokiirc
  5. Turn Bluetooth on on the computer and the phone.
  6. Pair the computer and phone. On Ubuntu, simply click the Bluetooth icon and follow the "Set up new device..." wizard.
  • If you want to copy your existing contacts to disk, you can run ./synchronize-bluetooth.sh -r > phone.vcf
  • To copy vCards to the phone, overwriting the existing contacts, run cat *.vcf | ./synchronize-bluetooth.sh -f
  • Note that synchronize-bluetooth.sh works only with the internal phone memory. Address book entries stored in the SIM card, phone log or elsewhere will not be read or written.

    Some features of the script:

    • Works with plain /bin/sh, so it should work on any Linux / BSD distribution.
    • Has separate parameters to read, write and flush contacts.

    synchronize-bluetooth.sh

    #!/bin/sh
    #
    # NAME
    #    synchronize-bluetooth.sh - Synchronize contacts with Bluetooth device.
    #
    # SYNOPSIS
    #    synchronize-bluetooth.sh [options]
    #
    # OPTIONS
    #    -f,--flush       Flush entries on the phone before synchronization
    #    -r,--read        Read phonebook entries (no synchronization)
    #
    # EXAMPLES
    #    ./synchronize-bluetooth.sh -r
    #        Read phone address book entries.
    #
    #    cat *.vcf | ./synchronize-bluetooth.sh -fv
    #        Remove all phone address book entries and write new ones.
    #
    # DESCRIPTION
    #    Warning: Overwrites the existing entries on the phone if you give it any
    #    input.
    #
    #    Some limitations:
    #    - Gnokii (or the phone) doesn't understand N, NICKNAME, ORG and URL
    #      parameters.
    #    - Conflicts have to be resolved manually.
    #    - Getting a "Data format is not valid" error for unknown reasons.
    #    - Needs conv.pl so long as Gnokii / phone doesn't understand the full vCard
    #      spec.
    #
    #    Tested on Nokia 6300 under Ubuntu (7.10-9.10). Instructions:
    #    <https://l0b0.wordpress.com/2008/03/18/howto-copying-vcard-address-books-to-nokia-6300-via-bluetooth-on-ubuntu-linux/>
    #
    # BUGS
    #    1: Not yet tested on other phones or operating systems.
    #    2: No automated comparison of computer and phone entries.
    #    3: Should use safe temporary directory creation - See web pages.
    #    4: Flushing doesn't always get rid of all address book entries.
    #
    #    Email bugs to victor dot engmark at gmail dot com. Please include the
    #    output of running this script.
    #
    # COPYRIGHT AND LICENSE
    #    Copyright (C) 2008-2010 Victor Engmark
    #
    #    This program is free software: you can redistribute it and/or modify
    #    it under the terms of the GNU General Public License as published by
    #    the Free Software Foundation, either version 3 of the License, or
    #    (at your option) any later version.
    #
    #    This program is distributed in the hope that it will be useful,
    #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #    GNU General Public License for more details.
    #
    #    You should have received a copy of the GNU General Public License
    #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    #
    ################################################################################
    
    # Init
    PATH='/usr/bin:/bin'
    ifs_original="$IFS" # Reset when done
    cmdname=$(basename $0)
    directory=$(dirname $0)
    
    # Exit codes from /usr/include/sysexits.h, as recommended by
    # http://www.faqs.org/docs/abs/HTML/exitcodes.html
    EX_USAGE=64
    
    # Output error message with optional error code
    error()
    {
        test -t 1 && {
            tput setf 4
            echo "$1" >&2
            tput setf 7
        } || echo "$1" >&2
        if [ -z "$2" ]
        then
            exit $EX_UNKNOWN
        else
            exit $2
        fi
    }
    
    usage()
    {
        # Print documentation until the first empty line
        while read line
        do
            if [ ! "$line" ]
            then
                exit $EX_USAGE
            fi
            echo "$line"
        done < $0
    }
    
    # Process parameters
    params=$(getopt -o fr -l flush,read --name $cmdname -- "$@")
    if [ $? -ne 0 ]
    then
        usage
    fi
    
    eval set -- "$params"
    
    while true
    do
        case $1 in
            -f|--flush)
                flush=1
                shift
                ;;
            -r|--read)
                read=1
                shift
                ;;
            --) shift
                break
                ;;
            *)
                usage
                ;;
        esac
    done
    
    if [ $read ]
    then
        gnokii --getphonebook ME 1 end --vcard \
            || error 'Failed to get phonebook.'
        exit
    fi
    
    if [ $flush ]
    then
        gnokii --deletephonebook ME 1 end \
            || error 'Could not flush phone entries.'
    fi
    
    sleep 1
    
    # Is there anything on stdin?
    if [ -t 0 ]
    then
        exit
    fi
    
    sed -n '1h;1!H;${;g;s/\r\n //g;p}' <&0 | \
    sed -E s/^ADR\;.*?\(home\|work\).*?:/ADR\;TYPE=\\1:/i\;s/^EMAIL\;.*?\(INTERNET\).*?:/EMAIL\;TYPE=\\1:/i\;s/^TEL\;.*?\(CELL\|FAX\|HOME\|WORK\).*?:/TEL\;TYPE=\\1:/i | \
    gnokii --writephonebook --overwrite --memory-type ME --vcard
    
    err_code=$?
    if [ $err_code -eq 20 ]
    then
        echo 'Data format error, eh? Dunno what to do about that for now.'
    elif [ $err_code -ne 0 ]
    then
        error 'Could not write to phone.' $err_code
    fi

    If you have problems sending the vCards to your phone, you may want to validate them first.

    Reader’s diggest: 2001, 2010, 2061 and 3001 by Arthur C. Clarke

    2001: Aliens have left a monolith to monitor and help mankind’s evolution towards intelligence.

    2010: A second monolith transforms Jupiter into a mini-sun to help creatures on Europa in the same way.

    2061: A third monolith on Europa is controlled to some extent by Dave / HAL.

    3001: A resurrected member of the 2001 crew destroys the monoliths with a computer virus.