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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/bash
  2. #
  3. # teknik - Upload files/scrots/urls to teknik.io (rip pomf & uguu ;_;7)
  4. # This script requires maim / xclip / wget be installed.
  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=true
  16. # Log file location
  17. logfile="$HOME/.teknik"
  18. ## FUNCTIONS
  19. bin_there() {
  20. if ! type "$@" >/dev/null 2>&1 ; then
  21. echo "$@ not installed."
  22. exit 1
  23. fi
  24. }
  25. # This function sets $file to a selection scrot
  26. selection() {
  27. bin_there "maim"
  28. uploadme="/tmp/scrot.png"
  29. maim --hidecursor -s -b 3 -c 250,250,250 "$uploadme" 2> "/dev/null"
  30. if [[ "$?" -ge 1 ]]; then
  31. echo "Selection cancelled.">&2
  32. exit 1
  33. fi
  34. word=selection
  35. }
  36. # This function sets $file to your clipboard contents
  37. clipboard() {
  38. bin_there "xclip"
  39. uploadme="/tmp/scrot.txt"
  40. xclip -o > "$uploadme"
  41. word=clipboard
  42. }
  43. # This function sets $file an url
  44. url() {
  45. bin_there "wget"
  46. type="$(echo "$location" | rev | cut -d "." -f 1 | rev)"
  47. uploadme="/tmp/url.$type"
  48. wget --quiet "$location" -O "$uploadme"
  49. word=url
  50. }
  51. # This function sets $file a file
  52. file() {
  53. if [[ -f "$location" ]]; then
  54. uploadme="$location"
  55. else
  56. echo "File not found.">&2
  57. exit 1
  58. fi
  59. word=file
  60. }
  61. # This function sets $file to a full screen scrot
  62. desktop() {
  63. bin_there "maim"
  64. uploadme="/tmp/scrot.png"
  65. maim --hidecursor "$uploadme"
  66. word=desktop
  67. }
  68. # This function uploads the $file
  69. upload(){
  70. if
  71. [[ ${uploadme} =~ png ]]
  72. then
  73. url=$(curl -silent -F file="@$uploadme;type=image/png" "https://api.teknik.io/v1/Upload")
  74. if
  75. [[ "${url}" =~ "error" ]]; then
  76. printf 'error uploading file!\n'
  77. exit 1
  78. else
  79. url="${url##*fileName\":\"}"
  80. url="https://u.teknik.io/${url%%\"*}"
  81. fi
  82. else
  83. url=$(curl -silent -F file="@$uploadme" "https://api.teknik.io/v1/Upload")
  84. if
  85. [[ "${url}" =~ "error" ]]; then
  86. printf 'error uploading file!\n'
  87. exit 1
  88. else
  89. url="${url##*fileName\":\"}"
  90. url="https://u.teknik.io/${url%%\"*}"
  91. fi
  92. fi
  93. }
  94. # This function logs the url, copies the url to the clipboard, and/or opens the url in your browser
  95. feedback() {
  96. # Copy url to clipboard
  97. if [[ "$clipboard" == true ]]; then
  98. bin_there "xclip"
  99. echo "$url" | xclip -selection primary
  100. echo "$url" | xclip -selection clipboard
  101. fi
  102. # Log url
  103. if [[ "$log" == true ]]; then
  104. echo "$url" >> "$logfile"
  105. fi
  106. # Open url in browser
  107. if [[ "$browser" == true ]]; then
  108. xdg-open "$url"
  109. fi
  110. # Send notification
  111. if [[ "$notify" == true ]]; then
  112. notify-send "Upload complete: $url"
  113. fi
  114. echo "${url}"
  115. }
  116. ## EXECUTE
  117. if [[ "$#" -ge 1 ]]; then
  118. case "$@" in
  119. -h|--help)
  120. echo "usage: teknik [options] [file/url]"
  121. echo "options:"
  122. echo " -h, --help print help and exit"
  123. echo " -p, --paste upload your clipboard as text"
  124. echo " -s, --selection upload selection scrot"
  125. echo " -v, --version print version and exit"
  126. exit 0
  127. ;;
  128. -s|--selection)
  129. selection
  130. ;;
  131. -v|--version)
  132. echo "teknik 0.1.1"
  133. exit 0
  134. ;;
  135. -p|--paste)
  136. clipboard
  137. ;;
  138. http*)
  139. location="$@"
  140. url
  141. ;;
  142. *)
  143. location="$@"
  144. file
  145. ;;
  146. esac
  147. else
  148. desktop
  149. fi
  150. if [[ "$#" -eq 0 ]]; then
  151. desktop
  152. fi
  153. upload
  154. feedback