Advertisement
metalx1000

BASH Upload Image to Magaimg.net

Aug 14th, 2018
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.11 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. function main(){
  21.   check $@
  22.   upload
  23. }
  24.  
  25. function check(){
  26.   local OPTIND opt i
  27.   while getopts ":qcni:" opt; do
  28.     case $opt in
  29.       i) img="$OPTARG";;
  30.       c) c=true;; #put link in clipboard
  31.       q) qr=true;; # display qrcode (qrencode needed)
  32.       n) n=true ;; # Send notification to desktop
  33.       \?) help;exit 1 ;; # Handle error: unknown option or missing required argument.
  34.     esac
  35.   done
  36.   shift $((OPTIND -1))
  37.  
  38.   if [ "$img" = "" ]
  39.   then
  40.     echo "No input file"
  41.     exit 1
  42.   fi
  43.   mime="$(file --mime-type $img|awk '{print $2}')"
  44.   url="http://magaimg.net/"
  45. }
  46.  
  47. function upload(){
  48.   link="$(curl -s -F "img[]=@$img;type=$mime" -D - "$url"|grep '^Location'|awk '{print $2}')"
  49.   echo "$link"
  50.  
  51.   [ $qr ] && qrencode "$link" -t UTF8
  52.   [ $n ] && notify-send -t 3000 "Image uploaded" "$link"
  53.  
  54.   #put link in clipboards
  55.   if [ $c ];
  56.   then
  57.     echo "$link"|xclip
  58.     echo "$link"|xclip -selection clipboard
  59.   fi
  60.  
  61.   exit 0
  62. }
  63.  
  64. function help(){
  65.   cat << EOF
  66.   Uploads an image to http://magaimg.net
  67.   Usage: $0 -cnqi <file>
  68.   Example: $0 -cnqi file.jpg
  69.  
  70.   -i <file>   Input image file
  71.   -c          Copy link to clipboard
  72.   -q          Display link qrcode (qrencode required)
  73.   -n          Send Notification to Desktop
  74. EOF
  75. }
  76.  
  77. main $@
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement