Description: simple wrapper script
 This script makes the operation on the .csv files more intuitive and
 reliable.

--- /dev/null
+++ owx-0~20110415/src/wouxun
@@ -0,0 +1,138 @@
+#! /bin/sh -e
+
+# simple wrapper script around the owx utility
+
+device=/dev/ttyUSB0
+delay=10
+
+usage() {
+    cat <<EOF
+$0 ( -i | -x ) [ <csvfile> ]
+
+-r reload pl2313 kernel module before doing anything (requires sudo)
+-i import csv into device
+-x export device into csv
+-f overwrite existing csv file during export
+-n simulate, don't do anything but checks
+-h this help
+
+<csvfile> defaults to wouxun.csv and must exist for import
+EOF
+    trap "" 0
+    exit 1
+}
+
+fail() {
+    cat <<EOF
+this thing is not working. try this:
+ 1. plug the damn thing in dude
+ 2. turn it off, unplug the dongle, plug it back in and turn it back on
+
+if all else fails: try turning it off and on again.
+
+if you already tried that, smartass, try reloading the pl2303 driver
+
+if you already tried that, try dumping the device image with -x first
+
+and if that fails too, try again tomorrow
+EOF
+    trap "" 0
+    exit 1
+}
+
+do_export() {
+    if [ -e "$csv" -a -z $force ]; then
+        while true; do
+            printf "file $csv already exists, overwrite? [y/N] "
+            read ans
+            case "$ans" in
+                [Yy]|[Yy][Ee][Ss]) break;;
+                ""|[Nn]|[Nn][Oo]) trap "" 0; exit 1;;
+                *) echo "uh? try again.";;
+            esac
+        done
+    fi
+        
+    if owx-check -p ${device}; then
+        echo "device detected on ${device}, letting it rest $delay seconds"
+        $simulate sleep $delay
+        echo "fetching the current image in file.bin"
+        $simulate owx-get ${force} -p ${device} -o file.bin
+        echo "converted to CSV file ${csv}"
+        $simulate owx-export -i file.bin -o "${csv}"
+        echo "converting back to unix file format"
+        $simulate sed -i "s/\r//" "${csv}"
+    fi
+}
+
+do_import() {
+
+    if [ ! -r "$csv" ]; then
+        echo "file $csv not readable"
+        usage
+    fi
+
+    if owx-check -p ${device}; then
+        echo "device detected on ${device}, letting it rest $delay seconds"
+        $simulate sleep $delay
+        echo "fetching the current image in file.bin"
+        $simulate owx-get ${force} -p ${device} -o file.bin
+        echo "backing up to backup.bin"
+        $simulate cp -f file.bin backup.bin
+        echo "patching image with $csv"
+        $simulate owx-import -i "$csv" -o file.bin
+        echo "sleeping $delay more"
+        $simulate sleep $delay
+        echo "loading image based on backup"
+        $simulate owx-put -p ${device}  -i file.bin -r backup.bin
+        echo "letting the device rest $delay more seconds"
+        $simulate sleep $delay
+        echo "okidou, all seems to have worked all great"
+        echo "please unplug that proprietary crap out of this box now"
+    else
+        fail
+    fi
+}
+
+do_reload_module() {
+	$simulate sudo modprobe -r pl2303
+	$simulate sleep 1
+	$simulate sudo modprobe pl2303
+	$simulate sleep $delay
+}
+
+set -- `getopt hxinfr $*`
+
+for i; do
+        case "$i" in
+              -h) shift; usage;;
+              -r) shift; reload="yes";;
+              -n) shift; simulate="echo > ";;
+              -x) shift; dothis="do_export";;
+              -i) shift; dothis="do_import";;
+              -f) shift; force="-f";;
+              --) shift; break;;
+        esac
+done
+
+csv=${@:-wouxun.csv}
+
+if [ -z "$dothis" ]; then
+    usage
+fi
+
+if [ ! -z "$simulate" ]; then
+    echo "*** SIMULATION: ECHOING COMMANDS ***"
+fi
+
+trap fail 0
+
+if [ ! -z "$reload" ]; then
+	echo "Reloading pl2313 kernel module..."
+	do_reload_module
+fi
+
+echo "preparing to $dothis on device..."
+$dothis
+
+trap "" 0
--- owx-0~20110415.orig/src/Makefile
+++ owx-0~20110415/src/Makefile
@@ -41,6 +41,7 @@ install: all
 	$(LN) -f -s $(PREFIX)/sbin/$(NAME) $(BINDIR)$(NAME)-put
 	$(LN) -f -s $(PREFIX)/sbin/$(NAME) $(BINDIR)$(NAME)-export
 	$(LN) -f -s $(PREFIX)/sbin/$(NAME) $(BINDIR)$(NAME)-import
+	$(INSTALL) -m 755 wouxun $(BINDIR)
 
 .PHONY: clean
 clean:
--- /dev/null	2011-10-17 01:04:54.909454458 -0400
+++ owx-0~20110415/src/wouxun.1	2011-10-26 22:22:04.280294824 -0400
@@ -0,0 +1,56 @@
+.\"                                      Hey, EMACS: -*- nroff -*-
+.\" First parameter, NAME, should be all caps
+.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
+.\" other parameters are allowed: see man(7), man(1)
+.TH WOUXUN 1 "October 26, 2011"
+.\" Please adjust this date whenever revising the manpage.
+.\"
+.\" Some roff macros, for reference:
+.\" .nh        disable hyphenation
+.\" .hy        enable hyphenation
+.\" .ad l      left justify
+.\" .ad b      justify to both left and right margins
+.\" .nf        disable filling
+.\" .fi        enable filling
+.\" .br        insert line break
+.\" .sp <n>    insert n+1 empty lines
+.\" for manpage-specific macros, see man(7)
+.SH NAME
+wouxun \- wrapper around the owx utility to operate CSV files directly
+.SH SYNOPSIS
+.B wouxun ( -i | -x ) [ <csvfile> ]
+.SH DESCRIPTION
+This manual page documents briefly the
+.B wouxun
+command.
+.SH OPTIONS
+These options are common to all commands.
+.TP
+.B \-h
+Show summary of options.
+.TP
+.B \-n
+Simulate, don't do anything but checks.
+.TP
+.B \-r
+Reload the pl2313 kernel module before doing anything (requires sudo).
+.TP
+.B \-i [ <csvfile> ]
+Import the given CSV into the device (defaults to wouxun.csv).
+.TP
+.B \-x [ <csvfile> ]
+Export the device into the given CSV file (defaults to
+wouxun.csv). Will not overwrite the file unless
+.B \-f
+is specified.
+.TP
+.B \-f
+Overwrite any existing .csv file.
+.SH SEE ALSO
+.BR owx (1), chirp (1),
+the README file.
+.SH AUTHOR
+The wouxun wrapper was writte by Antoine Beaupré <anarcat@koumbit.org>.
+.PP
+This manual page was written by Antoine Beaupré <anarcat@koumbit.org>,
+for the Debian project (and may be used by others).
