Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 14th, 2012  |  syntax: Bash  |  size: 1.77 KB  |  views: 34  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/sh
  2.  
  3. ###
  4. #Just a boilerplate shell script preamble that I use
  5. usage()
  6. {
  7.         cat <<-USAGE
  8.         Create new Debian package version of updated WordPress package
  9.  
  10.         usage: ${0##*/} FILE
  11.  
  12.         positional arguments:
  13.           FILE   .zip-file of WordPress package
  14.         USAGE
  15.         exit 1
  16. }
  17.  
  18. #Enable -h. Mostly a placeholder for potential future switches.
  19. while getopts "h" option; do
  20.         case ${option} in
  21.                 h|\? )  usage;;
  22.         esac
  23. done
  24. shift $((${OPTIND}-1))
  25.  
  26. #If exactly one argument is not given to the script, show usage instructions.
  27. [ ${#} -ne 1 ] && usage
  28. ###
  29.  
  30. set -e
  31. REPOSITORY=/home/whatever
  32.  
  33. #unzip does not have a -- construct, it seems. This is a workaround.
  34. unzip "$(readlink -f -- "${1}")"
  35.  
  36. #Instead of forking wc, cut and sed (along with the unicode troubles they all
  37. #inherit), all simple matchings can be done POSIXly consistent and forkless
  38. #with parameter expansion.
  39. #
  40. #Strip everything up to and including last directory separator
  41. FILE=${1##*/}
  42. #Strip everything including and after first dot
  43. PACKAGE=${FILE%%\.*}
  44. #Pick out the remainder of the $FILE string from the above expression,
  45. #excluding the separating dot
  46. ENDING=${FILE#${PACKAGE}\.}
  47. #Strip trailing .zip
  48. VER=${ENDING%\.zip}
  49. DIRNAME="wordpress-${PACKAGE}-${VER}"
  50.  
  51. mv -- "${PACKAGE}" "${DIRNAME}"
  52. tar czf "wordpress-${PACKAGE}_${VER}.orig.tar.gz" -- "${DIRNAME}"
  53. cd -- "${DIRNAME}"
  54. #No need to reverse ls output and picking the last line - don't reverse and
  55. #just pick the first (head -1 closes the pipe when the first line has been
  56. #read, so it is also infinitesimally faster, yay :-) ).
  57. tar xzf -- "$(ls -t -- "${REPOSITORY}/wordpress-${PACKAGE}"_*.debian.tar.gz | head -1)"
  58. dch -i
  59. dpkg-buildpackage
  60. #Change directory back to where the script was called (and don't bother the
  61. #user with details)
  62. cd - >/dev/null
clone this paste RAW Paste Data