127 lines
3.3 KiB
Bash
Executable File
127 lines
3.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Simplest user client for 0xff.i2p
|
|
# by acetone, 2021
|
|
#
|
|
VERSION="0.0.4"
|
|
|
|
######################################
|
|
############### CONFIG ###############
|
|
I2P_PROXY_ADDRESS=127.0.0.1:4444
|
|
# Localization
|
|
upload=upload
|
|
shorten=shorten
|
|
message=message
|
|
fromurl=fromurl
|
|
download=download
|
|
######################################
|
|
######################################
|
|
|
|
BOLD="\033[1m"
|
|
END="\033[0m"
|
|
|
|
usage() {
|
|
echo -e "version: $VERSION\n
|
|
u$BOLD $upload $END /path/to/local/file upload local file (128MiB max)
|
|
f$BOLD $fromurl $END http://example.org/file upload file from URL (128MiB max)
|
|
s$BOLD $shorten $END http://example.com/link link shortener
|
|
|
|
d$BOLD $download $END http://file [output file] download file from I2P
|
|
m$BOLD $message $END <no arguments> create and upload small text file
|
|
|
|
$BOLD<any STDOUT> | 0xff.sh$END upload any STDOUT via text file"
|
|
}
|
|
|
|
error() {
|
|
echo -e "Error: $1 command requires an argument\nUse '-h' or '--help' for usage information"
|
|
exit 2
|
|
}
|
|
|
|
main() {
|
|
case "$1" in
|
|
"$upload")
|
|
if [ -n "$2" ]; then
|
|
curl --proxy $I2P_PROXY_ADDRESS -# -T "$2" http://0xff.i2p | tee
|
|
else error $1; fi
|
|
;;
|
|
"$shorten")
|
|
if [ -n "$2" ]; then
|
|
curl --proxy $I2P_PROXY_ADDRESS -F"shorten=$2" http://0xff.i2p
|
|
else error $1; fi
|
|
;;
|
|
"$fromurl")
|
|
if [ -n "$2" ]; then
|
|
curl --proxy $I2P_PROXY_ADDRESS -F"url=$2" http://0xff.i2p
|
|
else error $1; fi
|
|
;;
|
|
"$download")
|
|
if [ -n "$2" ]; then
|
|
if [ -n "$3" ]; then
|
|
curl --proxy $I2P_PROXY_ADDRESS -# $2 -o $3 # to file explicitily
|
|
if [ $? != 0 ]; then exit 3; fi
|
|
else
|
|
autoname=${2#*http://0xff.i2p/}
|
|
curl --proxy $I2P_PROXY_ADDRESS -# $2 -o ./$autoname
|
|
if [ $? != 0 ]; then exit 3; fi
|
|
if [[ $(echo $autoname | grep -e "\.txt$") != "" ]]; then
|
|
# Display and deleting a text file that was downloaded without explicitly saving
|
|
echo ""
|
|
cat ./$autoname
|
|
rm ./$autoname
|
|
else
|
|
echo -e "File $BOLD$autoname$END was saved"
|
|
fi
|
|
fi
|
|
else error $1; fi
|
|
;;
|
|
"$message")
|
|
echo -n "Message: "
|
|
read message
|
|
echo -e -n "\nUploading...\n> "
|
|
echo $message | curl -s --proxy $I2P_PROXY_ADDRESS -T - http://0xff.i2p
|
|
;;
|
|
|
|
# short arguments
|
|
"u")
|
|
main $upload $2 ;;
|
|
"f")
|
|
main $fromurl $2 ;;
|
|
"s")
|
|
main $shorten $2 ;;
|
|
"d")
|
|
main $download $2 $3 ;;
|
|
"m")
|
|
main $message ;;
|
|
|
|
* )
|
|
echo -e "Invalid argument: $1\nUse '-h' or '--help' for usage information"
|
|
exit 1
|
|
;;
|
|
esac
|
|
exit 0
|
|
}
|
|
|
|
fromSTDIN() {
|
|
TMP_FILE="/tmp/0xff_$(date '+%H-%M-%S')"
|
|
while read LINE; do
|
|
echo $LINE | tee -a $TMP_FILE
|
|
done
|
|
echo -e -n "\nUploading...\n> "
|
|
curl -s --proxy $I2P_PROXY_ADDRESS -T "$TMP_FILE" http://0xff.i2p
|
|
rm $TMP_FILE
|
|
}
|
|
|
|
# start
|
|
if [ -n "$1" ]
|
|
then
|
|
if [ "$1" != "-h" ] && [ "$1" != "--help" ]
|
|
then
|
|
main $1 $2 $3
|
|
else
|
|
usage
|
|
fi
|
|
else
|
|
echo -e "Use '-h' or '--help' for usage information\nRead from STDIN...\n"
|
|
fromSTDIN
|
|
fi
|