64 lines
1.3 KiB
Bash
Executable File
64 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# load config (evaluate shellscript).
|
|
# loadconfig(configfile)
|
|
loadconfig() {
|
|
# allow to specify config via argv[1].
|
|
if [ "$1" != "" ]; then
|
|
# get absolute path of config file required for including.
|
|
config="$1"
|
|
path=$(readlink -f "${config}" 2>/dev/null)
|
|
else
|
|
# default config location.
|
|
config="$HOME/.sfeed/sfeedrc"
|
|
path="${config}"
|
|
fi
|
|
|
|
# config is loaded here to be able to override $sfeedpath or functions.
|
|
if [ -r "${path}" ]; then
|
|
. "${path}"
|
|
else
|
|
printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2
|
|
echo "See sfeedrc.example for an example." >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# override feed function to output OPML XML.
|
|
# feed(name, feedurl, [basesiteurl], [encoding])
|
|
feed() {
|
|
# uses the characters 0x1f and 0x1e as a separator.
|
|
printf '%s\037%s\036' "$1" "$2"
|
|
}
|
|
|
|
# load config file.
|
|
loadconfig "$1"
|
|
|
|
cat <<!
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<opml version="1.0">
|
|
<head>
|
|
<title>OPML export from sfeed</title>
|
|
</head>
|
|
<body>
|
|
!
|
|
|
|
feeds | LC_ALL=C awk '
|
|
BEGIN {
|
|
FS = "\x1f"; RS = "\x1e";
|
|
}
|
|
{
|
|
gsub("&", "\\&");
|
|
gsub("\"", "\\"");
|
|
gsub("'"'"'", "\\'");
|
|
gsub("<", "\\<");
|
|
gsub(">", "\\>");
|
|
|
|
print "\t<outline type=\"rss\" title=\"" $1 "\" text=\"" $1 "\" xmlUrl=\"" $2 "\"/>";
|
|
}'
|
|
|
|
cat <<!
|
|
</body>
|
|
</opml>
|
|
!
|