I bet you can figure out how to install: ksh, rar, par2, newspost.
Code:
#!/usr/bin/ksh
# tousenet
#---------- begin config ----------
SERVER=my.news.server.com
PORT=119
USERNAME=colemar
PASSWORD=password
NEWSGROUP=alt.binaries.test
EMAIL=colemarc@gmail.moc
NICKNAME=colemar
WORKBASE=/tmp/tousenet
RARVOLSIZE=50m
PARPERCENT=5
NFOMASK=*.nfo
SAMPLEMASK=*.sample.*
LISTFILESUFFIX=list.nfo
#---------- end config ----------
function errorexit {
print -u2 "ERROR: $1"
exit 1
}
function usage {
print "
tousenet <what> [<where>] [<subject>]
<what> a directory containing the binary files you want posted to usenet.
<where> an optional comma separated list of newsgroup names (maximum 5).
Default is alt.binaries.test.
<subject> an optional string to be used to build the articles subject.
Default is directory name of <what>.
Files contained in <what> (and subdirs) are assembled in a set of rar/par
files located in a work dir under the configured temp directory.
The common <prefix> for rar/par filenames is the directory name of <what>.
This program attempts to recognize whether a given <what> has already been
assembled for posting. To detect this situation, the work dir is named after
a fingerprint made from the first 8 characters of the md5 digest of <what>
contents and a helper listfile is created in the work directory.
"[fingerprint]" is also inserted at the beginning of articles subject; it
can be used later to search and track the post via binsearch.info or
other services.
If *.nfo and/or *.sample.* files exist in <what> directory, they will be
posted as such (besides in rar archive).
To let binsearch.info report these files together with rar/par files, you
should name them with the common prefix: <prefix>.nfo <prefix>.sample.mkv
The first *.nfo file is automatically renamed to <prefix>.nfo in the
work dir and posted as file number 0.
Example: tousenet ~/media/W.La.Foca alt.binaries.movies.divx 'W la foca! (1982) IMDB:tt0084880 avi divx 720x576 italiano-mp3'
"
exit
}
WHAT=$1
[[ $WHAT = "" ]] && usage
WHERE=${2:-$NEWSGROUP}
[[ $WHAT = /* ]] || WHAT=$PWD/$WHAT
[[ -d $WHAT ]] || errorexit "$WHAT should be a directory"
[[ -r $WHAT ]] || errorexit "$WHAT is not readable"
print "Source is $WHAT"
PREFIX=$(basename $WHAT)
[[ $PREFIX = *\ * ]] && errorexit "I don't like blanks in common prefix [$PREFIX]"
LISTFILE=$PREFIX.$LISTFILESUFFIX
SUBJECT="${3:-$PREFIX}"
cd $WHAT
what=$(find . -type f -printf '%P %s %T+\n')
typeset -L8 FINGERPRINT
print -- "$what" | md5sum | read FINGERPRINT junk
print "Fingerprint is $FINGERPRINT"
WORKDIR=$WORKBASE/$FINGERPRINT
print "Work dir is $WORKDIR"
mkdir -p $WORKDIR
cd $WORKDIR
if [[ $(print *) = "*" ]]; then
rar a $PREFIX -r -v$RARVOLSIZE -m0 $WHAT || errorexit "RAR archiver failed"
eval cp $WHAT/$NFOMASK $WHAT/$SAMPLEMASK .
par2 c -r$PARPERCENT $PREFIX * || errorexit "PAR file creation failed"
print -- "$what" > $LISTFILE
else
print "Work dir is not empty"
if [[ -f $LISTFILE ]]; then
print "Post already assembled in the work dir"
read answer?"Do you want to repost it? [Y/n] "
[[ $answer = @(n|N) ]] && errorexit "Aborted"
else
errorexit "The work dir contains something unexpected"
fi
fi
NFO=""
ls *.nfo | fgrep -v $LISTFILE | read infofile
if [[ $infofile > "" ]]; then
[[ -f $PREFIX.nfo ]] || mv $infofile $PREFIX.nfo
NFO="-e $PREFIX.nfo"
fi
newspost -T 3 -y -i $SERVER -z $PORT -u $USERNAME -p $PASSWORD -f $EMAIL -F $NICKNAME -n $WHERE -s "[$FINGERPRINT] $SUBJECT" $NFO *
print "Done. The assembled post is still in work dir $WORKDIR"
Bookmarks