| [06dcdf6] | 1 | #!/bin/bash | 
|---|
|  | 2 | # Create a Bash Patch | 
|---|
|  | 3 |  | 
|---|
|  | 4 | # Get Version # | 
|---|
|  | 5 | # | 
|---|
|  | 6 | VERSION=$1 | 
|---|
|  | 7 |  | 
|---|
|  | 8 | # Check Input | 
|---|
|  | 9 | # | 
|---|
|  | 10 | if [ "${VERSION}" = "" ]; then | 
|---|
| [9676bac] | 11 | echo "$0 - Bash_Version" | 
|---|
|  | 12 | echo "This will Create a Patch for Bash Bash_Version" | 
|---|
|  | 13 | exit 255 | 
|---|
| [06dcdf6] | 14 | fi | 
|---|
|  | 15 |  | 
|---|
|  | 16 | # Get the # of Patches | 
|---|
|  | 17 | # | 
|---|
| [d8a9d8b] | 18 | install -d ~/tmp | 
|---|
|  | 19 | cd ~/tmp | 
|---|
| [06dcdf6] | 20 | wget ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}-patches/ --no-remove-listing | 
|---|
|  | 21 | VERSION2=$(echo ${VERSION} | sed -e 's/\.//g') | 
|---|
|  | 22 | FILES=$(cat index.html | grep "${VERSION2}" | cut -f2 -d'"' | cut -f4 -d. | cut -f3 -d- | tail -n 1) | 
|---|
|  | 23 | rm -f .listing | 
|---|
|  | 24 | rm -f index.html | 
|---|
|  | 25 | SKIPPATCH="" | 
|---|
|  | 26 | SKIPPED="" | 
|---|
|  | 27 |  | 
|---|
|  | 28 | # Download BASH Source | 
|---|
|  | 29 | # | 
|---|
|  | 30 | if ! [ -e bash-${VERSION}.tar.gz ]; then | 
|---|
| [9676bac] | 31 | wget ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}.tar.gz | 
|---|
| [06dcdf6] | 32 | fi | 
|---|
|  | 33 |  | 
|---|
| [c7ef534] | 34 | # Set Patch Number | 
|---|
|  | 35 | # | 
|---|
| [d8a9d8b] | 36 | cd ~/tmp | 
|---|
| [29f6db3] | 37 | wget http://svn.cross-lfs.org/svn/repos/patches/bash/ --no-remove-listing | 
|---|
|  | 38 | for num in $(seq 1 99); do | 
|---|
| [4648865] | 39 | PATCH_NUM=$(cat index.html | grep "${VERSION}" | grep branch_update-${num}.patch | cut -f2 -d'"' | cut -f1 -d'"'| cut -f4 -d- | cut -f1 -d. | tail -n 1) | 
|---|
| [29f6db3] | 40 | if [ "${PATCH_NUM}" = "0" -a "${num}" = "1" ]; then | 
|---|
|  | 41 | PATCH_NUM=$(expr ${PATCH_NUM} + 1) | 
|---|
|  | 42 | break | 
|---|
|  | 43 | fi | 
|---|
|  | 44 | if [ "${PATCH_NUM}" != "${num}" ]; then | 
|---|
|  | 45 | PATCH_NUM=$(expr ${num}) | 
|---|
|  | 46 | break | 
|---|
|  | 47 | fi | 
|---|
|  | 48 | done | 
|---|
| [c7ef534] | 49 | rm -f index.html | 
|---|
|  | 50 |  | 
|---|
| [06dcdf6] | 51 | # Cleanup Directory | 
|---|
|  | 52 | # | 
|---|
| [d8a9d8b] | 53 | cd ~/tmp | 
|---|
| [06dcdf6] | 54 | rm -rf bash-${VERSION} bash-${VERSION}.orig | 
|---|
|  | 55 | tar xvf bash-${VERSION}.tar.gz | 
|---|
|  | 56 | cp -ar bash-${VERSION} bash-${VERSION}.orig | 
|---|
|  | 57 |  | 
|---|
|  | 58 | # Download and Apply Patches | 
|---|
|  | 59 | # | 
|---|
| [d8a9d8b] | 60 | install -d ~/tmp/bash-${VERSION}-patches | 
|---|
|  | 61 | cd ~/tmp/bash-${VERSION} | 
|---|
|  | 62 | CURRENTDIR=$(pwd -P) | 
|---|
| [06dcdf6] | 63 | PATCHURL=ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}-patches | 
|---|
|  | 64 | COUNT=1 | 
|---|
|  | 65 | while [ ${COUNT} -le ${FILES} ]; do | 
|---|
| [d8a9d8b] | 66 | cd ~/tmp/bash-${VERSION} | 
|---|
| [9676bac] | 67 | DLCOUNT="${COUNT}" | 
|---|
|  | 68 | SKIPME=no | 
|---|
|  | 69 | if [ "${COUNT}" -lt "100" ]; then | 
|---|
|  | 70 | DLCOUNT="0${COUNT}" | 
|---|
|  | 71 | fi | 
|---|
|  | 72 | if [ "${COUNT}" -lt "10" ]; then | 
|---|
|  | 73 | DLCOUNT="00${COUNT}" | 
|---|
|  | 74 | fi | 
|---|
|  | 75 | for skip in ${SKIPPATCH} ; do | 
|---|
|  | 76 | if [ "${DLCOUNT}" = "$skip" ]; then | 
|---|
|  | 77 | echo "Patch bash${VERSION2}-${DLCOUNT} skipped" | 
|---|
|  | 78 | SKIPPED="${SKIPPED} ${DLCOUNT}" | 
|---|
|  | 79 | SKIPME=yes | 
|---|
|  | 80 | fi | 
|---|
|  | 81 | done | 
|---|
|  | 82 | if [ "${SKIPME}" != "yes" ]; then | 
|---|
|  | 83 | if ! [ -e ${VERSION}.${DLCOUNT} ]; then | 
|---|
| [d8a9d8b] | 84 | cd ~/tmp/bash-${VERSION}-patches | 
|---|
| [9676bac] | 85 | wget --quiet ${PATCHURL}/bash${VERSION2}-${DLCOUNT} | 
|---|
|  | 86 | fi | 
|---|
|  | 87 | cd ${CURRENTDIR} | 
|---|
| [d8a9d8b] | 88 | patch --dry-run -s -f -Np0 -i ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT} | 
|---|
| [9676bac] | 89 | if [ "$?" = "0" ]; then | 
|---|
|  | 90 | echo "Patch bash${VERSION2}-${DLCOUNT} applied" | 
|---|
| [d8a9d8b] | 91 | patch -s -Np0 -i ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT} | 
|---|
| [9676bac] | 92 | else | 
|---|
|  | 93 | echo "Patch bash${VERSION2}-${DLCOUNT} not applied" | 
|---|
| [d8a9d8b] | 94 | rm -f ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT} | 
|---|
| [9676bac] | 95 | SKIPPED="${SKIPPED} ${DLCOUNT}" | 
|---|
|  | 96 | fi | 
|---|
|  | 97 | fi | 
|---|
|  | 98 | COUNT=`expr ${COUNT} + 1` | 
|---|
| [06dcdf6] | 99 | done | 
|---|
|  | 100 |  | 
|---|
|  | 101 | # Cleanup Directory | 
|---|
|  | 102 | # | 
|---|
| [d8a9d8b] | 103 | cd ~/tmp/bash-${VERSION} | 
|---|
| [c0d5090] | 104 | for dir in $(find * -type d); do | 
|---|
| [d8a9d8b] | 105 | cd ~/tmp/bash-${VERSION}/${dir} | 
|---|
| [9676bac] | 106 | for file in $(find . -name '*~'); do | 
|---|
|  | 107 | rm -f ${file} | 
|---|
|  | 108 | done | 
|---|
|  | 109 | for file in $(find . -name '*.orig'); do | 
|---|
|  | 110 | rm -f ${file} | 
|---|
|  | 111 | done | 
|---|
| [06dcdf6] | 112 | done | 
|---|
| [d8a9d8b] | 113 | cd ~/tmp/bash-${VERSION} | 
|---|
| [2803d79] | 114 | rm -f *~ *.orig | 
|---|
| [06dcdf6] | 115 |  | 
|---|
|  | 116 | # Create Patch | 
|---|
|  | 117 | # | 
|---|
| [d8a9d8b] | 118 | cd ~/tmp | 
|---|
|  | 119 | install -d ~/patches | 
|---|
|  | 120 | echo "Submitted By: Jim Gifford (jim at cross-lfs dot org)" > ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 121 | echo "Date: `date +%m-%d-%Y`" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 122 | echo "Initial Package Version: ${VERSION}" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 123 | echo "Origin: Upstream" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 124 | echo "Upstream Status: Applied" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 125 | echo "Description: Contains all upstream patches up to ${VERSION}-${FILES}" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
| [06dcdf6] | 126 | if [ -n "${SKIPPED}" ]; then | 
|---|
| [d8a9d8b] | 127 | echo "             The following patches were skipped" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 128 | echo "            ${SKIPPED}" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
| [06dcdf6] | 129 | fi | 
|---|
| [d8a9d8b] | 130 | echo "" >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 131 | diff -Naur bash-${VERSION}.orig bash-${VERSION} >> ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch | 
|---|
|  | 132 | echo "Created ~/patches/bash-${VERSION}-branch_update-${PATCH_NUM}.patch." | 
|---|
|  | 133 |  | 
|---|
|  | 134 | # Cleanup Directory | 
|---|
|  | 135 | # | 
|---|
|  | 136 | cd ~/tmp | 
|---|
|  | 137 | rm -rf bash-${VERSION} bash-${VERSION}.orig | 
|---|