+### FUNCTIONS ###
+
+function test_connection() {
+ # given a user and host,
+ # tests the connection.
+ # if user or host is missing, returns 0
+ # (ie, assume it's a local connection).
+ if [ $# -lt 2 ]; then
+ debug "(local is assumed to be a good connection)"
+ return 0
+ fi
+ local user=$1
+ local host=$2
+ debug "ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n 1'"
+ local ret=`ssh $sshoptions -o PasswordAuthentication=no $host -l $user 'echo -n host is alive'`
+ if echo $ret | grep "host is alive"; then
+ debug "Connected to $host as $user successfully"
+ else
+ fatal "Can't connect to $host as $user."
+ fi
+}
+
+function get_version() {
+ # given no arguments, returns the local version.
+ # given a user and host, returns the remote version.
+ # if user or host is missing, returns the local version.
+ if [ "$#" -lt 2 ]; then
+ debug "$RDIFFBACKUP -V"
+ echo `$RDIFFBACKUP -V`
+ else
+ local user=$1
+ local host=$2
+ debug "ssh $sshoptions $host -l $user '$RDIFFBACKUP -V'"
+ echo `ssh $sshoptions $host -l $user "$RDIFFBACKUP -V | grep rdiff-backup"`
+ fi
+}
+
+function check_consistency() {
+ local section=$1
+ local type=$2
+ local user=$3
+ local host=$4
+ if [ "$type" == "local" ]; then
+ if [ "$user" != "" ]; then
+ warning "User should not be specified for local $section."
+ fi
+ if [ "$host" != "" ]; then
+ warning "Host should not be specified for local $section."
+ fi
+ fi
+ if [ "$type" == "remote" ]; then
+ if [ "$user" == "" ]; then
+ fatal "User must be specified for remote $section."
+ fi
+ if [ "host" == "" ]; then
+ fatal "Host must be specifed for remote $section."
+ fi
+ fi
+}
+
+function check_cstream() {
+ local cstream=$1
+ if [ ! -x $cstream ]; then
+ fatal "Can't find your cstream binary (trying: $cstream). If you use bwlimit you must have cstream installed."
+ fi
+}
+
+### GET CONFIG ###
+
+getconf options
+getconf testconnect yes
+getconf nicelevel 0
+getconf bwlimit
+