Debian Codegraph @

SCRIPTS/PRE_0.7.0/podget-add-feed

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # Copyright (C) 2009 Steven Black <[email protected]>
4 # Contributed to podget on 2009-11-06 to be released under the same license
5 # as podget (currently GPL)
6
7 EMPTY_GROUP="Unknown"
8 EMPTY_TITLE="Unknown"
9
10 PODGET_DIR="$HOME/.podget"
11 config_serverlist=`sedscip-shell system . . sed. -r -n -e 's/^[ ]*config_serverlist[ ]*=[ ]*(["]?)(.*)\1[ ]*$/\2/p' "$PODGET_DIR/podgetrc"`
12 dir_library=`sedscip-shell system . . sed. -r -n -e 's/^[ ]*dir_library[ ]*=[ ]*(["]?)(.*)\1[ ]*$/\2/p' "$PODGET_DIR/podgetrc"`
13 case "$config_serverlist" in
14 /*)
15 SERVERLIST="$config_serverlist"
16 ;;
17 *)
18 SERVERLIST="$PODGET_DIR/$config_serverlist"
19 ;;
20 esac
21 case "$dir_library" in
22 /*)
23 LIBRARY_DIR="$dir_library"
24 ;;
25 *)
26 LIBRARY_DIR="$PODGET_DIR/$dir_library"
27 ;;
28 esac
29
30 if [scip-shell system . . `[`. ! -f "$SERVERLIST" ] ; then
31 exit 0
32 fi
33
34 CURL=`whichscip-shell system . . which. curl`
35
36 fake_titlescip-shell shell shell-project 0.0.0 fake_title().() {
37 # Originally we faked a title from the URL.
38 # Now we only do that if we can't get one via curl and sed
39 FAKE_TITLE=""
40 if [scip-shell system . . `[`. -x "$CURL" ] ; then
41 FAKE_TITLE=`"$CURL" -A "Mozilla/4.0" -f -L -s "$1" | sedscip-shell system . . sed. -n -e '/<title>/{
42 s|^.*<title>\(.*\)</title>.*$|\1|Mp
43 q
44 }'`
45 fi
46 if [scip-shell system . . `[`. -z "$FAKE_TITLE" ] ; then
47 FAKE_TITLE=`sedscip-shell system . . sed. -r \
48 -e 's;^https?://;;' -e 's;[.](com|org|net)/;/;' \
49 -e 's;^(www|web|feeds?[0-9]?)?[.];;' \
50 -e 's;/(bookfeeds|[sS]ite)/;/;g' -e 's;/[mM][pP]3_[fF]eed;;g' \
51 -e 's;[.]libsyn;;' -e 's;^(me|feedburner|librivox)/;;' \
52 -e 's;/feeds?/;/;' -e 's;[.](xml|html)$;;' \
53 -e 's;/feed$;;' \
54 -e 's;/[?]feed=[^/.]+;;' -e 's;/rss/?$;;' -e 's;/$;;' \
55 -e 's;%20; ;g' -e 's;%[0-9a-fA-F][0-9a-fA-F];;' -e 'y;/;_;' \
56 <<< "$1"`
57 fi
58 }
59 # fake_title "$1"
60 # echo $FAKE_TITLE
61 # exit 0
62
63 unsetcompetitionscip-shell shell shell-project 0.0.0 unsetcompetition().() {
64 KDIALOG=""
65 XDIALOG=""
66 GTKDIALOG=""
67 WHIPTAIL=""
68 TCDIALOG=""
69 DIALOG=""
70 AUTOMODE=0
71 }
72
73 checkdialogscip-shell shell shell-project 0.0.0 checkdialog().() {
74 USRDIALOG="$1"
75 unsetcompetitionscip-shell shell shell-project 0.0.0 unsetcompetition().
76 if [scip-shell system . . `[`. "$USRDIALOG" = "auto" ] ; then
77 AUTOMODE=1
78 return
79 fi
80 if [scip-shell system . . `[`. ! -z "$USRDIALOG" ] ; then
81 case "$USRDIALOG" in
82 */*) ;;
83 *) USRDIALOG=`whichscip-shell system . . which. $USRDIALOG` ;;
84 esac
85 if [scip-shell system . . `[`. ! -x "$USRDIALOG" ] ; then USRDIALOG="" ; fi
86 fi
87 if [scip-shell system . . `[`. ! -z "$USRDIALOG" ] ; then
88 case "$USRDIALOG" in
89 */kdialog*)
90 KDIALOG="$USRDIALOG"
91 ;;
92 */[xX]dialog*)
93 XDIALOG="$USRDIALOG"
94 ;;
95 */zenity*)
96 ZENITY="$USRDIALOG"
97 ;;
98 */gtkdialog*)
99 GTKDIALOG="$USRDIALOG"
100 ;;
101 */whiptail*)
102 WHIPTAIL="$USRDIALOG"
103 ;;
104 */tcdialog*)
105 TCDIALOG="$USRDIALOG"
106 ;;
107 */sh|*/bash*)
108 DIALOG=""
109 ;;
110 *)
111 # treat as 'dialog'
112 if [scip-shell system . . `[`. ! -z "$DISPLAY" ] ; then
113 if ttyscip-shell system . . tty. -s ; then
114 # Normally 'dialog' will only be used on a real TTY.
115 # They have a real TTY, so we're fine.
116 truescip-shell system . . true.
117 DIALOG="$USRDIALOG"
118 else
119 # Woah, no TTY. Perhaps we should treat this as Xdialog.
120 XDIALOG="$USRDIALOG"
121 fi
122 else
123 DIALOG="$USRDIALOG"
124 fi
125 ;;
126 esac
127 else
128 if [scip-shell system . . `[`. ! -z "$DISPLAY" ] ; then
129 KDIALOG=`whichscip-shell system . . which. kdialog`
130 XDIALOG=`whichscip-shell system . . which. Xdialog`
131 GTKDIALOG=`whichscip-shell system . . which. gtkdialog`
132 # Note: We *never* try to use 'zenity' unless the user specified
133 # it. It just doesn't work the way we want -- at all.
134 fi
135 if ttyscip-shell system . . tty. -s ; then
136 WHIPTAIL=`whichscip-shell system . . which. whiptail`
137 TCDIALOG=`whichscip-shell system . . which. tcdialog`
138 DIALOG=`whichscip-shell system . . which. dialog`
139 fi
140 fi
141 }
142
143 dialogcheckscip-shell shell shell-project 0.0.0 dialogcheck().() {
144 local DIALOGS=0
145 if [scip-shell system . . `[`. "$AUTOMODE" = "1" ] ; then
146 if [scip-shell system . . `[`. ! -z "$1" ] ; then
147 echoscip-shell system . . echo. "Running in automatic mode."
148 fi
149 return 0
150 fi
151 if [scip-shell system . . `[`. ! -z "$DISPLAY" ] ; then
152 if [scip-shell system . . `[`. ! -z "$1" ] ; then
153 echoscip-shell system . . echo. "X dialog services:"
154 fi
155 fi
156 if [scip-shell system . . `[`. -x "$KDIALOG" ] ; then
157 if [scip-shell system . . `[`. ! -z "$1" ] ; then
158 echoscip-shell system . . echo. "kdialog: good"
159 fi
160 DIALOGS=1
161 fi
162 if [scip-shell system . . `[`. -x "$GTKDIALOG" ] ; then
163 if [scip-shell system . . `[`. ! -z "$1" ] ; then
164 echoscip-shell system . . echo. "gtkdialog: good"
165 fi
166 DIALOGS=1
167 fi
168 if [scip-shell system . . `[`. -x "$XDIALOG" ] ; then
169 if [scip-shell system . . `[`. ! -z "$1" ] ; then
170 echoscip-shell system . . echo. "xdialog: okay"
171 echoscip-shell system . . echo. "---------- NOTICE regarding the use of Xdialog ----------"
172 echoscip-shell system . . echo. "Xdialog does not have the capacity to load in an icon or "
173 echoscip-shell system . . echo. "pixmap. This means it'll be uglier than the competition."
174 echoscip-shell system . . echo. "-----------------------------------------------------------"
175 echoscip-shell system . . echo. "For a prettier display, install kdialog or gtkdialog."
176 fi
177 DIALOGS=1
178 fi
179 if [scip-shell system . . `[`. -x "$ZENITY" ] ; then
180 DIALOGS=1
181 echoscip-shell system . . echo. "zenity: BAD (and UNSUPPORTED)"
182 echoscip-shell system . . echo. "---------- WARNING regarding the use of Zenity ----------"
183 echoscip-shell system . . echo. "'zenity' is unsupported. 'zenity' has no support for yes/no or"
184 echoscip-shell system . . echo. "yes/no/cancel dialogs. It has no capacity to add a button and"
185 echoscip-shell system . . echo. "change labels, allowing any sort of usable yes/no/cancel system."
186 echoscip-shell system . . echo. "zenity does not let me repurpose ok/cancel dialogs. The return"
187 echoscip-shell system . . echo. "code for cancel is the same as abort, so I can't even make do"
188 echoscip-shell system . . echo. "with changing the behavior there."
189 echoscip-shell system . . echo.
190 echoscip-shell system . . echo. "The dialogs will be confusing and missing features."
191 echoscip-shell system . . echo.
192 echoscip-shell system . . echo. "This is why it is unsupported."
193 echoscip-shell system . . echo.
194 echoscip-shell system . . echo. "Please install kdialog, Xdialog, or gtkdialog or run it from"
195 echoscip-shell system . . echo. "a terminal."
196 echoscip-shell system . . echo.
197 echoscip-shell system . . echo. "Really, even the automatic mode works better than zenity mode."
198 echoscip-shell system . . echo. "---------------------------------------------------------"
199 echoscip-shell system . . echo. "zenity is unsupported. Use at your own risk."
200 if [scip-shell system . . `[`. -z "$1" ] ; then
201 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --error "'zenity' is unsupported. 'zenity' has no support for yes/no or yes/no/cancel dialogs. It has no capacity to add a button and change labels, allowing any sort of usable yes/no/cancel system. zenity does not let me repurpose ok/cancel dialogs. The return code for cancel is the same as abort, so I can't even make do with changing the behavior there.\n\nThe dialogs will be confusing and missing features.\n\nThis is why it is unsupported.\n\nPlease install kdialog, Xdialog, or gtkdialog or run it from a terminal.\n\nReally, even the automatic mode works better than zenity mode."
202 fi
203 fi
204 if [scip-shell system . . `[`. $DIALOGS = 0 ] ; then
205 if [scip-shell system . . `[`. ! -z "$1" ] ; then
206 echoscip-shell system . . echo. "none: okay (X dialogs unavailable)"
207 echoscip-shell system . . echo. "------------ NOTICE regarding automatic mode -------------"
208 echoscip-shell system . . echo. "Will be fully automatic unless run from a terminal."
209 echoscip-shell system . . echo. "----------------------------------------------------------"
210 echoscip-shell system . . echo. "Please consider installing kdialog, Xdialog, or gtkdialog."
211 echoscip-shell system . . echo.
212 fi
213 fi
214 if ttyscip-shell system . . tty. -s ; then
215 if [scip-shell system . . `[`. ! -z "$1" ] ; then
216 echoscip-shell system . . echo. "TTY dialog services:"
217 fi
218 fi
219 if [scip-shell system . . `[`. -x "$DIALOG" ] ; then
220 if [scip-shell system . . `[`. ! -z "$1" ] ; then
221 echoscip-shell system . . echo. "dialog: good"
222 fi
223 fi
224 if [scip-shell system . . `[`. -x "$WHIPTAIL" ] ; then
225 if [scip-shell system . . `[`. ! -z "$1" ] ; then
226 echoscip-shell system . . echo. "whiptail: okay (not as pretty as dialog)"
227 echoscip-shell system . . echo. "--------- NOTICE regarding the use of whiptail ---------"
228 echoscip-shell system . . echo. "The line-wrapping in message dialogs is fairly crude."
229 echoscip-shell system . . echo. "This results in the message dialogs being uglier than"
230 echoscip-shell system . . echo. "dialog."
231 echoscip-shell system . . echo. "--------------------------------------------------------"
232 echoscip-shell system . . echo. "For a prettier display, install dialog."
233 echoscip-shell system . . echo.
234 fi
235 fi
236 if [scip-shell system . . `[`. -x "$TCDIALOG" ] ; then
237 if [scip-shell system . . `[`. ! -z "$1" ] ; then
238 echoscip-shell system . . echo. "tcdialog: BAD"
239 echoscip-shell system . . echo. "---------- WARNING regarding the use of tcdialog ----------"
240 echoscip-shell system . . echo. "tcdialog requires the row and column sizes be specified, so"
241 echoscip-shell system . . echo. "it produces some awful looking dialogs as we do not "
242 echoscip-shell system . . echo. "precompute these sizes."
243 echoscip-shell system . . echo.
244 echoscip-shell system . . echo. "We've also seen cases of the cursor being missing in the"
245 echoscip-shell system . . echo. "input dialog with tcdialog."
246 echoscip-shell system . . echo. "-----------------------------------------------------------"
247 echoscip-shell system . . echo. "Please consider installing dialog."
248 echoscip-shell system . . echo.
249 fi
250 fi
251 if [scip-shell system . . `[`. ! -z "$1" ] ; then
252 echoscip-shell system . . echo. "bash: okay (not as pretty as dialog)"
253 fi
254 }
255
256 askquestionsscip-shell shell shell-project 0.0.0 askquestions().() {
257 local MY_URL="$1"
258 local MY_GROUP="${2:-$EMPTY_GROUP}"
259 local MY_TITLE="$3"
260 CUR_ABORT=0
261 fake_titlescip-shell shell shell-project 0.0.0 fake_title(). "$MY_URL"
262 MY_TITLE="${MY_TITLE:-${FAKE_TITLE:-$EMPTY_TITLE}}"
263
264 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --input "Title for $MY_URL" "$MY_TITLE"
265 if [scip-shell system . . `[`. $? -eq 1 ] ; then CUR_ABORT=1 ; return 1 ; fi
266 CUR_TITLE="${SOMEDIALOG:-${FAKE_TITLE:-$EMPTY_TITLE}}"
267
268 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --input "Genre or group for $CUR_TITLE" "$MY_GROUP"
269 if [scip-shell system . . `[`. $? -eq 1 ] ; then CUR_ABORT=1 ; return 1 ; fi
270 CUR_GROUP="${SOMEDIALOG:-$EMPTY_GROUP}"
271
272 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --yesNOcancel "Activate <$MY_URL> in $CUR_GROUP as '$CUR_TITLE'?"
273 CUR_ACTIVATE="$?"
274 if [scip-shell system . . `[`. $CUR_ACTIVATE -eq 2 ] ; then CUR_ABORT=1 ; return 1 ; fi
275 if [scip-shell system . . `[`. -z "$CUR_GROUP" ] ; then
276 CUR_GROUP="$EMPTY_GROUP"
277 fi
278 if [scip-shell system . . `[`. -z "$CUR_TITLE" ] ; then
279 CUR_TITLE="${FAKE_TITLE:-$EMPTY_TITLE}"
280 fi
281 # Because of the backticks, the \\ needs to be escaped to \\\\
282 CUR_GROUP=`sedscip-shell system . . sed. -e 'y; /\\\\;___;' <<< "$CUR_GROUP"`
283 CUR_TITLE=`sedscip-shell system . . sed. -e 'y;/\\\\;__;' <<< "$CUR_TITLE"`
284 return $CUR_ABORT
285 }
286
287 somedialogscip-shell shell shell-project 0.0.0 somedialog().() {
288 local TYPE="$1"
289 shift
290 local RET=0
291 if [scip-shell system . . `[`. -x "$KDIALOG" ] ; then
292 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
293 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
294 "$KDIALOG" --error "$*"
295 elif [scip-shell system . . `[`. "$TYPE" = "--sorry" ] ; then
296 "$KDIALOG" --sorry "$*"
297 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
298 "$KDIALOG" --msgbox "$*"
299 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
300 "$KDIALOG" --yesno "$*"
301 RET="$?"
302 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
303 "$KDIALOG" --yesnocancel "$*"
304 RET="$?"
305 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
306 SOMEDIALOG=`"$KDIALOG" --inputbox "$1" "$2"`
307 RET="$?"
308 fi
309 elif [scip-shell system . . `[`. -x "$XDIALOG" ] ; then
310 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
311 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
312 "$XDIALOG" --stdout --msgbox "Error: $*" 0 0
313 elif [scip-shell system . . `[`. "$TYPE" = "--sorry" ] ; then
314 "$XDIALOG" --stdout --msgbox "Sorry: $*" 0 0
315 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
316 "$XDIALOG" --stdout --msgbox "$*" 0 0
317 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
318 "$XDIALOG" --stdout --yesno "$*" 0 0
319 RET="$?"
320 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
321 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
322 "$XDIALOG" --stdout --yesno "$*" 0 0
323 RET="$?"
324 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=2 ; fi
325 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
326 SOMEDIALOG=`"$XDIALOG" --stdout --inputbox "$1" 0 0 "$2"`
327 RET="$?"
328 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
329 fi
330 elif [scip-shell system . . `[`. -x "$GTKDIALOG" ] ; then
331 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
332 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
333 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
334 export GTK_DIALOG="
335 <vbox>
336 <hbox>
337 <pixmap><input file stock=\"error\"></input></pixmap>
338 <text><label>$GTKMSG</label></text>
339 </hbox>
340 <hbox>
341 <button ok></button>
342 <button cancel></button>
343 </hbox>
344 </vbox>
345 "
346 "$GTKDIALOG" --program GTK_DIALOG | grepscip-shell system . . grep. -q 'EXIT="OK"'
347 elif [scip-shell system . . `[`. "$TYPE" = "--sorry" ] ; then
348 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
349 export GTK_DIALOG="
350 <vbox>
351 <hbox><pixmap><input file stock=\"sorry\"></input></pixmap>
352 <text><label>$GTKMSG</label></text></hbox>
353 <hbox><button ok></button><button cancel></button></hbox>
354 </vbox>
355 "
356 "$GTKDIALOG" --program GTK_DIALOG | grepscip-shell system . . grep. -q 'EXIT="OK"'
357 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
358 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
359 export GTK_DIALOG="
360 <vbox>
361 <hbox><pixmap><input file stock=\"info\"></input></pixmap>
362 <text><label>$GTKMSG</label></text></hbox>
363 <hbox><button ok></button><button cancel></button></hbox>
364 </vbox>
365 "
366 "$GTKDIALOG" --program GTK_DIALOG | grepscip-shell system . . grep. -q 'EXIT="OK"'
367 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
368 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
369 export GTK_DIALOG="
370 <vbox>
371 <text><label>$GTKMSG</label></text>
372 <hbox><button yes></button><button no></button></hbox>
373 </vbox>
374 "
375 GTK_EXIT=`"$GTKDIALOG" --program GTK_DIALOG | sedscip-shell system . . sed. -n -e 's/^EXIT="\([^"]*\)"/\1/p'`
376 case "$GTK_EXIT" in
377 Yes) RET=0 ;;
378 No) RET=1 ;;
379 *) RET=1 ;;
380 esac
381 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
382 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
383 export GTK_DIALOG="
384 <vbox>
385 <text><label>$GTKMSG</label></text>
386 <hbox><button yes></button><button no></button><button cancel></button></hbox>
387 </vbox>
388 "
389 GTK_EXIT=`"$GTKDIALOG" --program GTK_DIALOG | sedscip-shell system . . sed. -n -e 's/^EXIT="\([^"]*\)"/\1/p'`
390 case "$GTK_EXIT" in
391 Yes) RET=0 ;;
392 No) RET=1 ;;
393 *) RET=2 ;;
394 esac
395 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
396 GTKMSG=`echoscip-shell system . . echo. "$1" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
397 GTKDEFAULT=`echoscip-shell system . . echo. "$2" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
398 # This isn't what is done in gtkdialog examples, however gtkdialog
399 # does *no escaping* of the input, so you can provide input such
400 # as '" ; rm /etc/passwd ; true "' and what you get back is:
401 # SOMEDIALOG="" ; rm /etc/passwd ; true ""
402 export GTK_DIALOG="
403 <vbox><text><label>$GTKMSG</label></text>
404 <entry><default>$GTKDEFAULT</default><variable>SOMEDIALOG</variable></entry>
405 <hbox><button ok></button><button cancel></button></hbox>
406 </vbox>
407 "
408 GTK_LINES=`"$GTKDIALOG" --program GTK_DIALOG`
409 SOMEDIALOG=`sedscip-shell system . . sed. -n -e 's/^SOMEDIALOG="\(.*\)"$/\1/p' <<< "$GTK_LINES"`
410 GTK_EXIT=`sedscip-shell system . . sed. -n -e 's/^EXIT="\([^"]*\)"/\1/p' <<< "$GTK_LINES"`
411 case "$GTK_EXIT" in
412 OK) RET=0 ;;
413 *) SOMEDIALOG="" ; RET=1 ;;
414 esac
415 fi
416 elif [scip-shell system . . `[`. -x "$ZENITY" ] ; then
417 # There is *NO CANCEL* option, so it is depricated
418 # It also has no Yes/No, so the yesno questions come out confusing
419 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
420 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
421 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
422 "$ZENITY" --error --text="$GTKMSG"
423 elif [scip-shell system . . `[`. "$TYPE" = "--sorry" ] ; then
424 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
425 "$ZENITY" --warning --text="$GTKMSG"
426 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
427 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
428 "$ZENITY" --info --text="$GTKMSG"
429 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
430 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
431 "$ZENITY" --question --text="$GTKMSG"
432 RET="$?"
433 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
434 GTKMSG=`echoscip-shell system . . echo. "$*" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
435 "$ZENITY" --question --text="$GTKMSG"
436 RET="$?"
437 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
438 GTKMSG=`echoscip-shell system . . echo. "$1" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
439 GTKDEFAULT=`echoscip-shell system . . echo. "$2" | sedscip-shell system . . sed. -e 's/</[/g' -e 's/>/]/g'`
440 SOMEDIALOG=`"$ZENITY" --entry --text="$GTKMSG" --entry-text="$GTKDEFAULT"`
441 RET="$?"
442 fi
443 elif ttyscip-shell system . . tty. -s && [scip-shell system . . `[`. $AUTOMODE = 0 ] ; then
444 TTY_ABORT=0
445 # trap TTY_ABORT=1 SIGINT
446 if [scip-shell system . . `[`. -x "$DIALOG" ] ; then
447 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
448 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
449 "$DIALOG" --msgbox "Error: $*" 0 0
450 elif [scip-shell system . . `[`. "$TYPE" = "--sorry " ] ; then
451 "$DIALOG" --msgbox "Sorry: $*" 0 0
452 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
453 "$DIALOG" --msgbox "$*" 0 0
454 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
455 "$DIALOG" --yesno "$*" 0 0
456 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
457 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
458 "$DIALOG" --extra-button --ok-label Yes --extra-label No --no-label Cancel --yesno "$*" 0 0
459 if [scip-shell system . . `[`. $RET -eq 1 ] ; then RET=2
460 elif [scip-shell system . . `[`. $RET -eq 2 ] ; then RET=1
461 elif [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=2
462 fi
463 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
464 "$DIALOG" --inputbox "$1" 0 0 "$2" 2>"$TMPFILE"
465 RET="$?"
466 SOMEDIALOG=`catscip-shell system . . cat. "$TMPFILE"`
467 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
468 fi
469 elif [scip-shell system . . `[`. -x "$WHIPTAIL" ] ; then
470 # whiptail doesn't handle 0 0 as nicely as dialog, so it
471 # isn't preferred.
472 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
473 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
474 "$WHIPTAIL" --msgbox "Error: $*" 0 0
475 elif [scip-shell system . . `[`. "$TYPE" = "--sorry " ] ; then
476 "$WHIPTAIL" --msgbox "Sorry: $*" 0 0
477 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
478 "$WHIPTAIL" --msgbox "$*" 0 0
479 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
480 "$WHIPTAIL" --yesno "$*" 0 0
481 RET="$?"
482 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
483 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
484 "$WHIPTAIL" --yesno "$* (ESC to cancel)" 0 0
485 RET="$?"
486 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=2 ; fi
487 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
488 "$WHIPTAIL" --inputbox "$1" 0 0 "$2" 2>"$TMPFILE"
489 RET="$?"
490 SOMEDIALOG=`catscip-shell system . . cat. "$TMPFILE"`
491 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
492 fi
493 elif [scip-shell system . . `[`. -x "$TCDIALOG" ] ; then
494 # tcdialog requires the height/width values
495 # as such, it is depricated
496 if [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then TYPE="--yesnocancel" ; fi
497 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
498 "$TCDIALOG" --msgbox "Error: $*" 20 60
499 elif [scip-shell system . . `[`. "$TYPE" = "--sorry " ] ; then
500 "$TCDIALOG" --msgbox "Sorry: $*" 20 60
501 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
502 "$TCDIALOG" --msgbox "$*" 20 60
503 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
504 "$TCDIALOG" --yesno "$*" 20 60
505 RET="$?"
506 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
507 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
508 "$TCDIALOG" --yesno "$* (ESC to cancel)" 20 60
509 RET="$?"
510 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=2 ; fi
511 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
512 "$TCDIALOG" --inputbox "$1" 20 60 "$2" 2>"$TMPFILE"
513 RET="$?"
514 SOMEDIALOG=`catscip-shell system . . cat. "$TMPFILE"`
515 if [scip-shell system . . `[`. $RET -eq 255 ] ; then RET=1 ; fi
516 fi
517 else
518 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
519 echoscip-shell system . . echo. "Error: $*"
520 read -p "Press <Enter> to continue." RET
521 RET=0
522 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=1 ; fi
523 elif [scip-shell system . . `[`. "$TYPE" = "--sorry " ] ; then
524 echoscip-shell system . . echo. "Sorry: $*"
525 read -p "Press <Enter> to continue." RET
526 RET=0
527 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=1 ; fi
528 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
529 echoscip-shell system . . echo. "Note: $*"
530 read -p "Press <Enter> to continue." RET
531 RET=0
532 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=1 ; fi
533 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
534 read -r -e -p "$* (y/N)?" RET
535 case "$RET" in
536 [yY]|[yY][eE][sS]) RET=0 ;;
537 *) RET=1 ;;
538 esac
539 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=1 ; fi
540 elif [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then
541 read -r -e -p "$* (yes/NO/cancel):" RET
542 if [scip-shell system . . `[`. -z "$RET" ] ; then RET="n" ; fi
543 case "$RET" in
544 [yY]|[yY][eE][sS]) RET=0 ;;
545 [nN]|[nN][oO]) RET=1 ;;
546 *) RET=2 ;;
547 esac
548 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=2 ; fi
549 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
550 read -r -e -p "$* (yes/no/CANCEL):" RET
551 case "$RET" in
552 [yY]|[yY][eE][sS]) RET=0 ;;
553 [nN]|[nN][oO]) RET=1 ;;
554 *) RET=2 ;;
555 esac
556 if [scip-shell system . . `[`. $TTY_ABORT -eq 1 ] ; then RET=2 ; fi
557 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
558 read -r -e -p "$1 ($2): " SOMEDIALOG
559 if [scip-shell system . . `[`. -z "$SOMEDIALOG" ] ; then
560 SOMEDIALOG="$2"
561 fi
562 RET=$TTY_ABORT
563 fi
564 fi
565 # trap - SIGINT
566 else
567 RET=0
568 if [scip-shell system . . `[`. "$TYPE" = "--error" ] ; then
569 echoscip-shell system . . echo. "Error: $*"
570 elif [scip-shell system . . `[`. "$TYPE" = "--sorry " ] ; then
571 echoscip-shell system . . echo. "Sorry: $*"
572 elif [scip-shell system . . `[`. "$TYPE" = "--message" ] ; then
573 echoscip-shell system . . echo. "Message: $*"
574 elif [scip-shell system . . `[`. "$TYPE" = "--yesno" ] ; then
575 echoscip-shell system . . echo. "Yes/No: $* (defaults to NO)"
576 RET=1
577 elif [scip-shell system . . `[`. "$TYPE" = "--yesNOcancel" ] ; then
578 echoscip-shell system . . echo. "Yes/No/Cancel: $* (defaults to NO)"
579 RET=1
580 elif [scip-shell system . . `[`. "$TYPE" = "--yesnocancel" ] ; then
581 echoscip-shell system . . echo. "Yes/No/Cancel: $* (defaults to CANCEL)"
582 RET=2
583 elif [scip-shell system . . `[`. "$TYPE" = "--input" ] ; then
584 echoscip-shell system . . echo. "Input: $1 (defaults to $2)"
585 SOMEDIALOG="$2"
586 fi
587 fi
588 return $RET
589 }
590
591 showversionscip-shell shell shell-project 0.0.0 showversion().() {
592 # Version history:
593 # 0.1 - (yam655) first version
594 # 0.1.1 (2009-05-08):
595 # fix issue with feed://somewhere/...
596 # genre/title dialog order swap (as seen in 0.2 line)
597 # 0.2 - (mostly aborted) added ability to run podget afterwards
598 # 0.3 - added inactivity tag support
599 echoscip-shell system . . echo. "podget-add-feed Version 0.3"
600 }
601
602 showhelpscip-shell shell shell-project 0.0.0 showhelp().() {
603 catscip-shell system . . cat. << FEOF
604 Usage: $0 {Options} <URL>
605 Options may include:
606 -h | --help : show this help message
607 -V | --version : show the version
608 -c | --check : check dialog compatibility
609 -a | --auto : run in non-interactive mode
610 -d | --dialog <dialog> : use a specific dialog program
611 FEOF
612 }
613
614 checkdialogscip-shell shell shell-project 0.0.0 checkdialog().
615 TMPFILE=`tempfilescip-shell system . . tempfile. -p paf.`
616 if [scip-shell system . . `[`. -z "$TMPFILE" ] ; then TMPFILE=`mktempscip-shell system . . mktemp. -t addfeed.XXXXXXXXXX` ; fi
617 if [scip-shell system . . `[`. -z "$TMPFILE" ] ; then TMPFILE="/tmp/podget-add-feed.$$.`hostnamescip-shell system . . hostname.`" ; fi
618
619 while [scip-shell system . . `[`. $# -gt 0 ] ; do
620 case "$1" in
621 --check|-c)
622 dialogcheckscip-shell shell shell-project 0.0.0 dialogcheck(). -v
623 exit 0
624 ;;
625 --help|-h)
626 showhelpscip-shell shell shell-project 0.0.0 showhelp().
627 exit 0
628 ;;
629 --version|-V)
630 showversionscip-shell shell shell-project 0.0.0 showversion().
631 exit 0
632 ;;
633 --auto|-a)
634 unset DISPLAY
635 DIALOG="auto"
636 shift
637 continue
638 ;;
639 --dialog|-d)
640 shift
641 checkdialogscip-shell shell shell-project 0.0.0 checkdialog(). "$1"
642 dialogcheckscip-shell shell shell-project 0.0.0 dialogcheck().
643 shift
644 continue
645 ;;
646 esac
647 URL="$1"
648 shift
649 CUR_GROUP="$EMPTY_GROUP"
650 CUR_TITLE=""
651 CUR_ACTIVATE=0
652
653 # Interestingly, the body of the single-quoted segments is getting
654 # parsed.
655 URL=`sedscip-shell system . . sed. -e 's@^feed://@http://@' -e 's@^feed:\([a-z]\+:\)@\1@' \
656 -e 's/ /%20/g' -e 's/|/%7C/g' -e 's/\\\\/%5C/g' \
657 -e 's/\\$/%24/g' -e 's/"/%34/g' -e "s/'/%39/g" \
658 <<< "$URL"`
659 case "$URL" in
660 http:*)
661 ;;
662 https:*)
663 ;;
664 *)
665 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --error "Unknown protocol in URL: $URL"
666 continue
667 ;;
668 esac
669 FOUNDURL=`grepscip-shell system . . grep. -e "^\(#[a-zA-Z0-9]* \)\?$URL " "$SERVERLIST"`
670 FURL=""
671 FGROUP=""
672 FTITLE=""
673 FACTIVE="inactive"
674 FREASON=""
675 if [scip-shell system . . `[`. ! -z "$FOUNDURL" ] ; then
676 case "$FOUNDURL" in
677 \#*)
678 read FACTIVE FURL FGROUP FTITLE <<< "$FOUNDURL"
679 if [scip-shell system . . `[`. "$FACTIVE" != "#" ] ; then
680 FREASON=" (${FACTIVE:1})"
681 fi
682 FACTIVE="inactive"
683 ;;
684 *)
685 read FURL FGROUP FTITLE <<< "$FOUNDURL"
686 FACTIVE="active"
687 ;;
688 esac
689 if ! somedialogscip-shell shell shell-project 0.0.0 somedialog(). --yesnocancel "Found <$FURL> in $FGROUP as \"$FTITLE\". It is $FACTIVE$FREASON. Change this?" ; then
690 continue
691 fi
692 fi
693 if ! askquestionsscip-shell shell shell-project 0.0.0 askquestions(). "$URL" "$FGROUP" "$FTITLE" ; then
694 continue
695 fi
696 ACTIVE=""
697 if [scip-shell system . . `[`. $CUR_ACTIVATE -ne 0 ] ; then
698 ACTIVE='# '
699 fi
700 if [scip-shell system . . `[`. -z "$FOUNDURL" ] ; then
701 echoscip-shell system . . echo. "$ACTIVE$URL $CUR_GROUP $CUR_TITLE" >> "$SERVERLIST"
702 else
703 OLIBDIR="$LIBRARY_DIR/$FGROUP/$FTITLE"
704 NLIBDIR="$LIBRARY_DIR/$CUR_GROUP/$CUR_TITLE"
705 sedscip-shell system . . sed. -e 's|^\(# \)\?'"$URL"' .*$|'"$ACTIVE$URL $CUR_GROUP $CUR_TITLE"'|g' "$SERVERLIST" > "$SERVERLIST".new
706 mvscip-shell system . . mv. "$SERVERLIST" "$SERVERLIST~"
707 mvscip-shell system . . mv. "$SERVERLIST".new "$SERVERLIST"
708 if [scip-shell system . . `[`. -d "$OLIBDIR" ] ; then
709 if [scip-shell system . . `[`. ! -d "$LIBRARY_DIR/$CUR_GROUP" ] ; then
710 mkdirscip-shell system . . mkdir. -p "$LIBRARY_DIR/$CUR_GROUP"
711 fi
712 if [scip-shell system . . `[`. -d "$NLIBDIR" ] ; then
713 somedialogscip-shell shell shell-project 0.0.0 somedialog(). --sorry "Directory $NLIBDIR already existed. We could not move $OLIBDIR. You will need to move the files by hand."
714 else
715 mvscip-shell system . . mv. -f "$OLIBDIR" "$NLIBDIR"
716 fi
717 fi
718 # if [ -z "$ACTIVE" -a "$FACTIVE" != "active" ] ; then
719 # if somedialog --yesno "Run podget now?" ; then
720 # podget
721 # fi
722 # fi
723 fi
724 done
725