Guest User

publish

a guest
Nov 19th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.24 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. MAXW=800
  4. GETW="%w"
  5. SOURCE=""
  6. TARGETDIR="$HOME/upload/public"
  7. LINKS="$HOME/.publish/links.js"
  8. TARGET=""
  9. FNAME=""
  10. FORCE=""
  11. PRESERVE=""
  12. SUBDIR=""
  13. OPTION="-auto-orient"
  14.  
  15.  
  16. ## publish <files>
  17.  
  18.  
  19. #publish -ccw <file>
  20. #publish -cw  <file>
  21.  
  22. if [ ${#} -lt 1 ]
  23. then
  24.     echo "Usage: publish [options] <image>"
  25.     echo ""
  26.     echo "Options:  -cw         rotate clockwise"
  27.     echo "          -ccw        rotate counterclockwise"
  28.     echo "          -d <dir>    publish to a subdirectory"
  29.     echo "          -as <name>  set target filename (extension is the same as the source)"
  30.     echo "          -f          force (never prompt)"
  31.     echo "          -p          preserve size"
  32.     echo ""
  33.    
  34.     exit 1
  35. fi
  36.  
  37.  
  38. while [ ${#} -gt 0 ]
  39. do
  40.     if [ "$1" = "-d" ]
  41.     then
  42.         SUBDIR="$2"
  43.         shift 2
  44.  
  45.     elif [ "$1" = "-cw" ]
  46.     then
  47.         OPTION="-rotate 90"
  48.         GETW="%h"
  49.         shift 1
  50.    
  51.     elif [ "$1" = "-ccw" ]
  52.     then
  53.         OPTION="-rotate 270"
  54.         GETW="%h"
  55.         shift 1
  56.        
  57.     elif [ "$1" = "-as" ]
  58.     then
  59.         FNAME="$2"
  60.         shift 2
  61.  
  62.         elif [ "$1" = "-p" ]
  63.         then
  64.                 PRESERVE=1
  65.                 shift 1
  66.     elif [ "$1" = "-f" ]
  67.     then
  68.         FORCE=1
  69.         shift 1
  70.     else
  71.         if [ ! "$SOURCE" ]
  72.         then
  73.             SOURCE="$1"
  74.         fi
  75.         shift 1
  76.     fi
  77. done
  78.  
  79.  
  80.  
  81. if [ "$FNAME" ]
  82. then
  83.     FNAME=${FNAME}.${SOURCE##*.}
  84. else
  85.     FNAME=$(basename "$SOURCE")
  86. fi
  87.  
  88. TARGETDIR=${TARGETDIR}/${SUBDIR}${SUBDIR:+/}
  89. TARGET=${TARGETDIR}${FNAME}
  90. H=0
  91. W=0
  92.  
  93. $(identify -format "let W=$GETW" "$SOURCE" 2>/dev/null)
  94. if [ ${?} = 0 ]
  95. then
  96.     if [ ${W} -gt ${MAXW} -a ! "$PRESERVE" ]
  97.     then
  98.         OPTION="$OPTION -resize $MAXW"
  99.     fi
  100.  
  101.     if [ -e "$TARGET" -a ! "$FORCE" ]
  102.     then
  103.         echo -n "File already exists! Overwrite? y/[n] "
  104.         read answer
  105.         if [ "${answer:-n}" != "y" ]
  106.         then
  107.             exit 2
  108.         fi
  109.     fi
  110.  
  111.  
  112.     mkdir -p "$TARGETDIR"
  113.     convert ${OPTION} "$SOURCE" "$TARGET"
  114.     cd "$TARGETDIR"
  115.     URL=$(dropbox puburl "$FNAME")
  116.     DESC=$(date +"%F %H:%M")
  117.     echo 'links.push({"desc":"'"$DESC"'", "src":"'"$URL"'"})' >> "$LINKS"
  118.     echo "$URL"
  119. fi
Advertisement
Add Comment
Please, Sign In to add comment