a2cloud/setup/a2news

61 lines
1.5 KiB
Plaintext
Raw Normal View History

2015-10-30 12:34:48 +00:00
#! /bin/bash
2016-10-25 17:42:29 +00:00
# vim: set tabstop=4 shiftwidth=4 noexpandtab filetype=sh:
2015-10-30 11:47:35 +00:00
defaultNNTP="news.aioe.org"
defaultGroups="comp.emulators.apple2:\ncomp.sys.apple2:\ncomp.sys.apple2.comm:\ncomp.sys.apple2.marketplace:\ncomp.sys.apple2.programmer:\ncomp.sys.apple2.usergroups:"
if [[ ! $(dpkg -l tin 2> /dev/null | grep '^ii') ]]; then
2016-10-25 17:42:29 +00:00
echo "Installing Tin newsreader..."
sudo apt-get -y update
sudo apt-get -y install tin &> /dev/null
sudo apt-get -y clean
2015-10-30 12:38:31 +00:00
fi
2015-10-30 11:47:35 +00:00
if [[ $1 == "-h" || $1 == "--help" ]]; then
2016-10-25 17:42:29 +00:00
echo "Usage: a2news [-s nntpServerAddress] [-m postingEmailAddress] [otherTinOptions]"
echo " note: for full options, instead use 'tin'"
exit 1
2015-10-30 11:47:35 +00:00
fi
2015-10-30 12:38:31 +00:00
while [[ $1 == "-s" || $1 == "-m" ]]; do
2016-10-25 17:42:29 +00:00
if [[ $1 == "-s" && $2 ]]; then
nntpServer=$2
shift
shift
fi
if [[ $1 == "-m" && $2 ]]; then
emailAddress=$2
shift
shift
fi
2015-10-30 11:47:35 +00:00
done
mkdir -p ~/.tin
if [[ ! -f ~/.newsrc ]]; then
2016-10-25 17:42:29 +00:00
IFS=''; echo -e "$defaultGroups" > ~/.newsrc
2015-10-30 11:47:35 +00:00
fi
if [[ $nntpServer || ! -f ~/.tin/nntp.server ]]; then
2016-10-25 17:42:29 +00:00
[[ ! $nntpServer ]] && nntpServer="$defaultNNTP"
echo "$nntpServer" > ~/.tin/nntp.server
2015-10-30 11:47:35 +00:00
else
2016-10-25 17:42:29 +00:00
nntpServer=$(cat ~/.tin/nntp.server)
2015-10-30 11:47:35 +00:00
fi
if [[ $emailAddress || ! -f ~/.tin/tinrc ]]; then
2016-10-25 17:42:29 +00:00
while [[ ! $emailAddress || ! $(grep "@" <<< $emailAddress) || ! $(grep "\." <<< $emailAddress) ]]; do
echo -n "Enter the email address you want to post as: "
read
emailAddress=$REPLY
done
if [[ -f ~/.tin/tinrc ]]; then
sed -i "s/^mail_address=.*$/mail_address=$emailAddress/" ~/.tin/tinrc
else
echo "mail_address=$emailAddress" > ~/.tin/tinrc
fi
2015-10-30 11:47:35 +00:00
fi
NNTPSERVER=$nntpServer tin -r "$@"