File: script

package info (click to toggle)
owx 0~20110415-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 300 kB
  • ctags: 208
  • sloc: cpp: 1,253; sh: 111; makefile: 53
file content (214 lines) | stat: -rw-r--r-- 6,009 bytes parent folder | download
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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).