-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpostFiles.sh
executable file
·137 lines (108 loc) · 2.76 KB
/
postFiles.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
#
# Script to upload a file on Usenet using ngPost (https://github.com/mbruel/ngPost)
# it's goal it's to do the split and the par2 generation in a temp folder prior to upload it
#
UUID_NAME=1
GEN_UUID=dbus-uuidgen
QT_VERSION=5.12.6
SCRIPT=`readlink -f "$0"`
SCRIPT_PATH=`dirname "$SCRIPT"`
LIBS="$SCRIPT_PATH/libs"
export QT_PLUGIN_PATH=$LIBS/plugins/
NG_POST="$SCRIPT_PATH/src/ngPost"
NZB_PATH="$SCRIPT_PATH/nzb"
TMP_FOLDER=/tmp
if [ ! -d $NZB_PATH ]; then
mkdir $NZB_PATH
fi
# Uncomment the line below in case there is an issue loading the plugins
#export QT_DEBUG_PLUGINS=1
export LD_LIBRARY_PATH=$LIBS:$LD_LIBRARY_PATH
# 0.: if using RAR obfuscation, generate RAR_NAME
if [ "$UUID_NAME" -eq 1 ]; then
RAR_NAME=`$GEN_UUID`
if [ "$?" -ne 0 ]; then
echo "can't find the '$GEN_UUID' command to generate the RAR name..."
exit -1
# could try using pwgen instead ;)
else
echo "using RAR obfuscation: $RAR_NAME.rar"
fi
fi
syntax()
{
echo "syntax: $0 (-c <ngPost config file>)? (-i <input file>)+ (-o <nzb file>)?"
}
#1.: parse the options
while getopts "hc:i:o:" opt
do
case $opt in
"i")
# FILE="$OPTARG"
FILES+=("$OPTARG")
;;
"o")
NZBFILE="$NZB_PATH/$OPTARG"
;;
"c")
CONFIG="$OPTARG"
;;
"h")
syntax
exit 0
;;
"?")
echo "Invalid option: -$OPTARG"
syntax
exit 1
;;
esac
done
MAIN_FILE=$FILES
echo "Nb files: ${#FILES[@]}, main one: $MAIN_FILE, all files: ${FILES[@]}"
#2.: validate the options
#if [ -z $CONFIG ] || [ ! -f $CONFIG ] ; then
# echo "you need to provide ngPost configuration file (-c option)"
# exit 1
#fi
if [ -z $MAIN_FILE ] || [ ! -f $MAIN_FILE ] ; then
echo "you need to provide at least one input file..."
exit 1
fi
#3.: create the TMP_FOLDER
echo "File to upload: $MAIN_FILE"
FILENAME=$(basename "${MAIN_FILE%.*}")
TMP_FOLDER="$TMP_FOLDER/$FILENAME"
if [ -e $TMP_FOLDER ]; then
echo "Folder $TMP_FOLDER already exist..."
rm -rf $TMP_FOLDER
fi
mkdir $TMP_FOLDER
#4.: if no RAR_NAME (no obfuscation) use real FILENAME
if [ -z "$RAR_NAME" ]; then
RAR_NAME=$FILENAME
fi
#4.: create the archives and par2
PASS=$(pwgen -cBsn 13 1)
echo "RAR pass: $PASS"
rar a -v50m -ed -ep1 -m0 -hp"$PASS" "$TMP_FOLDER/$RAR_NAME.rar" "${FILES[@]}"
cd $TMP_FOLDER
par2 c -s768000 -r8 *.rar
#5.: create the NZBFILE if not provided (using main FILENAME)
if [ -z "$NZBFILE" ]; then
NZBFILE="$NZB_PATH/$FILENAME"
fi
#6.: generate random from
FROM="$(pwgen -cBsn 11 1)@ngPost.com"
echo "RAR_NAME: $RAR_NAME, PASS: $PASS, NZBFILE: $NZBFILE, FROM: $FROM"
#7.: post TMP_FOLDER
#echo "$NG_POST -m "password=$PASS" -i $TMP_FOLDER"
if [ -z $CONFIG ] ; then
$NG_POST -m "password=$PASS" -i $TMP_FOLDER -o $NZBFILE -f $FROM
else
$NG_POST -m "password=$PASS" -c "$CONFIG" -i $TMP_FOLDER -o $NZBFILE -f $FROM
fi
#8.: clean TMP_FOLDER
rm -rf $TMP_FOLDER
exit 0