title: Idempotent Bash Script for a Patch and requirements file
body: <p>I have a python project with its own requirements file. The project also has its own virtualenv, with one of the packages being 'pyPdf'. The library has a bug and I wrote a patch to fix the bug. </p>
  
  <pre><code>--- venv/local/lib/python2.7/site-packages/pyPdf/pdf.py 2014-07-17 17:04:57.000000000 +0530
  +++ pypdf_fixer.py  2014-07-19 01:19:53.176877332 +0530
  @@ -1726,7 +1726,10 @@
       m.update(p_entry)
       # 5. Pass the first element of the file's file identifier array to the MD5
       # hash function.
  -    m.update(id1_entry)
  +    if isinstance(id1_entry, str):
  +        m.update(id1_entry)
  +    else:
  +        m.update(id1_entry.original_bytes)
       # 6. (Revision 3 or greater) If document metadata is not being encrypted,
       # pass 4 bytes with the value 0xFFFFFFFF to the MD5 hash function.
       if rev &gt;= 3 and not metadata_encrypt:
  </code></pre>
  
  <p>Lets call this file as pypdf.patch. I run the patch using the Linux patch command.</p>
  
  <pre><code>$ patch venv/local/lib/python2.7/site-packages/pyPdf/pdf.py &lt; pypdf.patch
  </code></pre>
  
  <p>I need to write a bash script to do 2 things with Idempotent property(meaning running the script multiple times should be the same as running it a single time)</p>
  
  <p>1) Run through the requirements file with various library requirements(example Flask==0.10.1 etc, including a git+ssh requirement) and do a pip install for all the libraries.</p>
  
  <p>2) Apply the patch to the pypdf library.</p>
  
  <p>Appreciate any leads on this front. Kindly take note of 'Idempotency'.</p>
  
  <p>PS: My requirements.txt file looks like this.(I do a pip install - r requirements.txt under the virtualenv to install the libraries)</p>
  
  <pre><code>Flask==0.10.1
  Jinja2==2.7.3
  ...
  pyPdf==1.13
  git+ssh://git@something.co.uk/some-production-library.git
  </code></pre>
  
  <p>Thanks</p>