sfeed_opml_export (1318B)
1 #!/bin/sh 2 3 # load config (evaluate shellscript). 4 # loadconfig(configfile) 5 loadconfig() { 6 # allow to specify config via argv[1]. 7 if [ "$1" != "" ]; then 8 # get absolute path of config file required for including. 9 config="$1" 10 path=$(readlink -f "${config}" 2>/dev/null) 11 else 12 # default config location. 13 config="$HOME/.sfeed/sfeedrc" 14 path="${config}" 15 fi 16 17 # config is loaded here to be able to override $sfeedpath or functions. 18 if [ -r "${path}" ]; then 19 . "${path}" 20 else 21 printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 22 echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2 23 exit 1 24 fi 25 } 26 27 # override feed function to output OPML XML. 28 # feed(name, feedurl, [basesiteurl], [encoding]) 29 feed() { 30 # uses the characters 0x1f and 0x1e as a separator. 31 printf '%s\037%s\036' "$1" "$2" 32 } 33 34 # load config file. 35 loadconfig "$1" 36 37 cat <<! 38 <?xml version="1.0" encoding="UTF-8"?> 39 <opml version="1.0"> 40 <head> 41 <title>OPML export from sfeed</title> 42 </head> 43 <body> 44 ! 45 46 feeds | LC_ALL=C awk ' 47 BEGIN { 48 FS = "\x1f"; RS = "\x1e"; 49 } 50 { 51 gsub("&", "\\&"); 52 gsub("\"", "\\""); 53 gsub("'"'"'", "\\'"); 54 gsub("<", "\\<"); 55 gsub(">", "\\>"); 56 57 print "\t<outline type=\"rss\" title=\"" $1 "\" text=\"" $1 "\" xmlUrl=\"" $2 "\"/>"; 58 }' 59 60 cat <<! 61 </body> 62 </opml> 63 !