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