Tools to interface with Teknik Services.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

teknik.sh 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. #
  3. # teknik - Upload files/scrots/urls to teknik.io (rip pomf & uguu ;_;7)
  4. # requires maim / slop
  5. # By onodera, modified by SirCmpwn
  6. # Further modified by alusion
  7. ## CONFIGURATION
  8. # Copy links to clipboard after upload (requires xclip)
  9. clipboard=true
  10. # Send a notification when done
  11. notify=true
  12. # Open URL in browser
  13. browser=false
  14. # Log URLs
  15. log=false
  16. # Log file location
  17. logfile="$HOME/.teknik"
  18. ## FUNCTIONS
  19. # This function sets $file to a selection scrot
  20. selection() {
  21. uploadme="/tmp/scrot.png"
  22. maim --hidecursor -s -b 3 -c 250,250,250 "$uploadme" 2> "/dev/null"
  23. if [[ "$?" -ge 1 ]]; then
  24. echo "Selection cancelled."
  25. exit 1
  26. fi
  27. word=selection
  28. }
  29. # This function sets $file to your clipboard contents
  30. clipboard() {
  31. uploadme="/tmp/scrot.txt"
  32. xclip -o > "$uploadme"
  33. word=clipboard
  34. }
  35. # This function sets $file an url
  36. url() {
  37. type="$(echo "$location" | rev | cut -d "." -f 1 | rev)"
  38. uploadme="/tmp/url.$type"
  39. wget --quiet "$location" -O "$uploadme"
  40. word=url
  41. }
  42. # This function sets $file a file
  43. file() {
  44. if [[ -f "$location" ]]; then
  45. uploadme="$location"
  46. else
  47. echo "File not found."
  48. exit 1
  49. fi
  50. word=file
  51. }
  52. # This function sets $file to a full screen scrot
  53. desktop() {
  54. uploadme="/tmp/scrot.png"
  55. maim --hidecursor "$uploadme"
  56. word=desktop
  57. }
  58. # This function uploads the $file
  59. upload() {
  60. url=$(curl --silent -F file="@$uploadme" "https://api.teknik.io/upload/post")
  61. if [[ "${url}" =~ "error" ]]; then
  62. printf 'error uploading file!\n'
  63. exit 1
  64. else
  65. url="${url##*name\":\"}"
  66. url="https://u.teknik.io/${url%%\"*}"
  67. fi
  68. }
  69. # This function logs the url, copies the url to the clipboard, and/or opens the url in your browser
  70. feedback() {
  71. # Copy url to clipboard
  72. if [[ "$clipboard" == true ]]; then
  73. echo "$url" | xclip -selection primary
  74. echo "$url" | xclip -selection clipboard
  75. fi
  76. # Log url
  77. if [[ "$log" == true ]]; then
  78. echo "$url" >> "$logfile"
  79. fi
  80. # Open url in browser
  81. if [[ "$browser" == true ]]; then
  82. xdg-open "$url"
  83. fi
  84. # Send notification
  85. if [[ "$notify" == true ]]; then
  86. notify-send "Upload complete: $url"
  87. fi
  88. echo "${url}"
  89. }
  90. ## EXECUTE
  91. if [[ "$#" -ge 1 ]]; then
  92. case "$@" in
  93. -h|--help)
  94. echo "usage: teknik [options] [file/url]"
  95. echo "options:"
  96. echo " -h, --help print help and exit"
  97. echo " -p, --paste upload your clipboard as text"
  98. echo " -s, --selection upload selection scrot"
  99. echo " -v, --version print version and exit"
  100. exit 0
  101. ;;
  102. -s|--selection)
  103. selection
  104. ;;
  105. -v|--version)
  106. echo "teknik 0.1.1"
  107. exit 0
  108. ;;
  109. -p|--paste)
  110. clipboard
  111. ;;
  112. http*)
  113. location="$@"
  114. url
  115. ;;
  116. *)
  117. location="$@"
  118. file
  119. ;;
  120. esac
  121. else
  122. desktop
  123. fi
  124. if [[ "$#" -eq 0 ]]; then
  125. desktop
  126. fi
  127. upload
  128. feedback