Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ssup - upload screenshot
  4.  
  5. # brew install pngpaste imagemagick
  6.  
  7. set -x # Show commands as they are run.
  8. set -e # Exit on error.
  9.  
  10. # Generate random file name for image.
  11. IMAGE_NAME=$(head -c 40 /dev/urandom | base64 | perl -pe 's~\W~~g' | head -c 15)
  12.  
  13. TEMP_FILE="/tmp/${IMAGE_NAME}.png"
  14. pngpaste "$TEMP_FILE"
  15.  
  16. DIMENSIONS=$(half-image-dimensions $TEMP_FILE)
  17.  
  18. URL="https://curi.us/img/$IMAGE_NAME-${DIMENSIONS}.png"
  19. UPLOAD_PATH="/home/curi/img/${IMAGE_NAME}-${DIMENSIONS}.png"
  20.  
  21. chmod 444 "$TEMP_FILE"
  22. if scp -P 44222 "$TEMP_FILE" "curi@ssh.curi.us:${UPLOAD_PATH}"
  23. then chmod 644 "$TEMP_FILE"
  24. else
  25. chmod 644 "$TEMP_FILE"
  26. say "oh my god the file name was a duplicate"
  27. exit 1
  28. fi
  29.  
  30. echo -n "$URL" | pbcopy
  31.  
  32. say "image uploaded"
  33.  
  34.  
  35.  
  36. # half-image-dimensions script:
  37.  
  38. # #!/usr/bin/env ruby
  39. #
  40. # # input: image file name
  41. # # output: image dimensions string like: 1920x1080
  42. # # output is half the real dimensions, rounded down, for getting retina stuff scaled down
  43. #
  44. # results = `sips -g pixelHeight -g pixelWidth #{ARGV[0]}`
  45. #
  46. # results =~ /pixelHeight: (\d+)/
  47. # h = ($1.to_f/2.0).to_i
  48. # results =~ /pixelWidth: (\d+)/
  49. # w = ($1.to_f/2.0).to_i
  50. #
  51. # print "#{w}x#{h}"
  52.  
  53.  
  54.  
  55. # old script that makes a 50% size image and a retina image
  56.  
  57. # Make sure a file with this name doesn't already exist.
  58. # Shouldn't happen with the length of random name we're using.
  59. # if curl --head "$URL" | head -1 | grep "200 OK" >/dev/null; then
  60. # say "duplicate file name"
  61. # exit 1
  62. # fi
  63. #
  64. # ORIGINAL_FILE="/tmp/${IMAGE_NAME}-has2x@2x.png"
  65. # CONVERTED_FILE="/tmp/${IMAGE_NAME}-has2x.png"
  66. #
  67. # # Copy image from clipboard to temp directory.
  68. # pngpaste "$ORIGINAL_FILE"
  69. #
  70. # # convert -resize 50% "$ORIGINAL_FILE" "$CONVERTED_FILE"
  71. #
  72. # # scp won't copy over read-only files
  73. # chmod 444 "$ORIGINAL_FILE" "$CONVERTED_FILE"
  74. #
  75. # ## CHANGE THE LINE BELOW to use the upload command of your choice.
  76. # if scp -P 44222 "$ORIGINAL_FILE" "$CONVERTED_FILE" curi@ssh.curi.us:/home/curi/img/
  77. # then chmod 644 "$ORIGINAL_FILE" "$CONVERTED_FILE"
  78. # else
  79. # chmod 644 "$ORIGINAL_FILE" "$CONVERTED_FILE"
  80. # say "oh my god the file name was a duplicate"
  81. # exit 1
  82. # fi
  83. #
  84. # # Copy URL to clipboard.
  85. # echo -n "$URL" | pbcopy
  86. #
  87. # say "image uploaded"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement