This repository has been archived on 2021-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
rsstube-bash-old/scripts/options

130 lines
2.2 KiB
Plaintext

# specify arbitrary curl arguments - passed directly to curl
c() {
curl_args="$1"
}
# help
h() {
echo "Usage: rsstube [OPTIONS] URL"
echo "Do 'man rsstube' to see the manual for rsstube."
exit
}
# non-network mode (do not download page)
n() {
network="false"
}
# proxy
p() {
proxy="-x $1 "
}
# quiet (use curl in silent mode)
q() {
quiet="--silent "
}
# curl options for Tor (to avoid Cloudflare blocks)
t() {
tor_header=""
while read line
do
tor_header="${tor_header}${line} "
done < conf/tor-browser-header
curl_args="${curl_args} ${tor_header}"
}
# update rsstube
U() {
update="true"
}
# display version
V() {
version=`cat docs/version`
echo "rsstube v${version}"
exit
}
global_config="/etc/rsstube/config"
local_config="$HOME/.config/rsstube/config"
config_file=""
# local_config takes precedence over global_config, and only one (at most) will be used
if [[ -f "$local_config" ]]
then
config_file=${local_config}
elif [[ -f "$global_config" ]]
then
config_file=${global_config}
fi
# default assume we're not using Tor mode
tor_mode=""
if [[ -n "$config_file" ]]
then
while read line
do
# cut whitespace from beginning of line
line=${line##*( )}
# ignore commented out lines
if [[ -n $line && ${line:0:1} != "#" ]]
then
# get just argument
cmd=${line%% *}
case $cmd in
-c|--curl-args) c "${line#* }" ;;
-h|--help|help) h ;;
-n|--non-network) n ;;
-p|--proxy) p "${line#* }" ;;
-q|--quiet) q ;;
-t|--tor-mode) tor_mode="true" ;;
-U|--update) U ;;
-V|--version) V ;;
*) error "Unsupported option."; exit ;;
esac
fi
done < "$config_file"
fi
# options from method call take precedence over config file options
while [[ $# -gt 0 ]]
do
cmd="${1}"
case $cmd in
-c|--curl-args) shift; c "${1}" ;;
-h|--help|help) h ;;
-n|--non-network) n ;;
-p|--proxy) shift; p "${1}" ;;
-q|--quiet) q ;;
-t|--tor-mode) tor_mode="true" ;;
-U|--update) U ;;
-V|--version) V ;;
*) url="${1}" ;;
esac
# finish with this command
shift
done
if [[ "${update}" == "true" ]]
then
source scripts/update
exit
fi
if [[ -n "${tor_mode}" ]]
then
t
fi
if [[ ! -n "${url}" ]]
then
error "No URL supplied!"
exit
fi