summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-08-29 17:58:28 +0200
committerFlorian Pritz <bluewind@xinu.at>2014-08-29 17:58:28 +0200
commit0a8145685d8d13da0c12e61b034a2323a22f46e2 (patch)
tree36ecb02b48308a61f92132b71e3b918b5caa852b
parent8e035bd403c155ca8b9a5db960f37a3c054faaa1 (diff)
Support multipastesv1.4
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--fb-helper.c27
-rw-r--r--fb.16
-rw-r--r--fb.in58
3 files changed, 79 insertions, 12 deletions
diff --git a/fb-helper.c b/fb-helper.c
index b550887..261d3b8 100644
--- a/fb-helper.c
+++ b/fb-helper.c
@@ -221,11 +221,12 @@ void display_help()
printf("Usage: fb-helper <options>\n");
printf("\n");
printf("Options:\n");
- printf(" -D Print debugging information\n");
- printf(" -h This help\n");
- printf(" -u <url> URL of pastebin or URL to download\n");
- printf(" -f <file> File to upload to URL\n");
- printf(" -a <file> Path to API key file\n");
+ printf(" -D Print debugging information\n");
+ printf(" -h This help\n");
+ printf(" -u <url> URL of pastebin or URL to download\n");
+ printf(" -f <file> File to upload to URL\n");
+ printf(" -F key=value Post key=value\n");
+ printf(" -a <file> Path to API key file\n");
}
int main(int argc, char *argv[])
@@ -264,7 +265,7 @@ int main(int argc, char *argv[])
exit(0);
}
- while ((opt = getopt(argc, argv, "Du:f:m:a:h")) != -1) {
+ while ((opt = getopt(argc, argv, "Du:f:F:m:a:h")) != -1) {
switch (opt) {
case 'D': options.debug = 1; break;
@@ -272,6 +273,20 @@ int main(int argc, char *argv[])
case 'f': options.file = optarg; break;
+ case 'F':
+ {
+ char *save = NULL;
+ char *key = strtok_r(optarg, "=", &save);
+ char *value = strtok_r(save, "=", &save);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, key,
+ CURLFORM_PTRCONTENTS, value,
+ CURLFORM_END);
+ }
+ break;
+
case 'a': options.apikeyfile = optarg; break;
case 'h':
diff --git a/fb.1 b/fb.1
index 4a07538..918ae84 100644
--- a/fb.1
+++ b/fb.1
@@ -83,6 +83,12 @@ terminal. You can no longer upload files in this mode. If the argument is a
URL,
.Nm
will try to extract the ID.
+.It Fl m
+Create a multipaste of the IDs/files/directories/URLs. This uploads files as
+always, but then creates a multipaste combining all of them. URLs starting with
+the pastebin URL will have their ID extracted and will not be downloaded. Only
+the multipaste URL will be copied to the clipboard, but all URLs will be
+displayed while uploading.
.It Fl h
Display a short help message.
.It Fl t
diff --git a/fb.in b/fb.in
index 3aefba8..930ce1c 100644
--- a/fb.in
+++ b/fb.in
@@ -44,6 +44,8 @@ delete=
extension=""
filename="stdin"
get=
+multipaste=
+multipaste_ids=()
tar=
compress=0
display_history=
@@ -67,13 +69,14 @@ base64_encode() {
}
request_helper() {
+ # available modes are: d, u, m
mode=$1
url=$2
file=$3
# if available use the external helper, else fall back to calling curl
if [ -x "$libdir/fb-helper" ]; then
- helperopts=()
+ helperopts=(-u "$url")
if [ "$debug" ]; then
helperopts+=(-D)
@@ -83,13 +86,16 @@ request_helper() {
helperopts+=(-a $apikey_file)
fi
- if [ "$mode" = "d" ]; then
- $libdir/fb-helper "${helperopts[@]}" -u "$url"
+ if [ "$mode" = "u" ]; then
+ helperopts+=(-f "$file")
fi
- if [ "$mode" = "u" ]; then
- $libdir/fb-helper "${helperopts[@]}" -u "$url" -f "$file"
+ if [ "$mode" = "m" ]; then
+ for id in "${multipaste_ids[@]}"; do
+ helperopts+=(-F "ids[]=$id")
+ done
fi
+ $libdir/fb-helper "${helperopts[@]}"
else
curlopts=(${default_curlopts[@]})
@@ -105,6 +111,12 @@ request_helper() {
curlopts+=("-v")
fi
+ if [ "$mode" = "m" ]; then
+ for id in "${multipaste_ids[@]}"; do
+ curlopts+=(-F "ids[]=$id")
+ done
+ fi
+
if [ "$mode" = "d" ]; then
curlopts+=("-s")
fi
@@ -141,6 +153,14 @@ is_url() {
return 1
}
+is_pastebin_url() {
+ if printf "%s" "$i" | grep -qE "^$pastebin.+"; then
+ return 0
+ fi
+
+ return 1
+}
+
do_tar_upload() {
if [ "$compress" = "1" ]; then
file="$tmpdir/$filename.tar.gz"
@@ -284,6 +304,7 @@ usage: [cat |] `basename "$0"` [switches] [options] [<file(s)|ID(s)|folder(s)>]
Switches:
-d <ID(s)> delete the IDs
-g <ID(s)> download the IDs and output on stdout (use with care!)
+ -m create a multipaste
-h this help
-v show the client version
-H display an upload history
@@ -305,11 +326,12 @@ if ! type getopts >/dev/null 2>&1; then
exit 1
fi
-while getopts "e:n:gdhHatcvD" option; do
+while getopts "e:n:gmdhHatcvD" option; do
case $option in
e) extension="$OPTARG";;
n) filename="$OPTARG";;
g) get=1;;
+ m) multipaste=1;;
c) compress=`expr $compress + 1`;;
t) tar=1;;
d) delete=1;;
@@ -382,6 +404,13 @@ else
else
for i in "$@"; do
if is_url "$i"; then
+ if [ "$multipaste" ]; then
+ if is_pastebin_url "$i"; then
+ multipaste_ids+=("$(id_from_arg "$i")")
+ continue
+ fi
+ fi
+
cd $tmpdir
if ! request_helper d "$i" > "`basename "$i"`"; then
exitcode=1
@@ -398,6 +427,23 @@ else
fi
done
fi
+
+ if [ "$multipaste" ]; then
+ for url in $clipboard; do
+ id="$(id_from_arg "$url")"
+ multipaste_ids+=("$id")
+ done
+
+ tmpfile=`mktemp "$tmpdir/data.XXXXXX"`
+ request_helper m "$pastebin/file/do_multipaste" > $tmpfile || exitcode=1
+
+ sed '$d' $tmpfile >&2
+ url=`tail -1 $tmpfile`"$extension"
+ printf "%s\n" "$url"
+ if printf "%s" "$url" | grep -qE "^https?://"; then
+ clipboard="$url"
+ fi
+ fi
fi
if [ "$clipboard" != "" ]; then