/usr/bin/wouxun is in owx 0~20110415-3.1+b2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 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
|