| 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
|
|---|
| 11 | echo "$0 - Bash_Version"
|
|---|
| 12 | echo "This will Create a Patch for Bash Bash_Version"
|
|---|
| 13 | exit 255
|
|---|
| 14 | fi
|
|---|
| 15 |
|
|---|
| 16 | # Get the # of Patches
|
|---|
| 17 | #
|
|---|
| 18 | cd /usr/src
|
|---|
| 19 | wget ftp://ftp.cwru.edu/pub/bash/bash-${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 BASH Source
|
|---|
| 28 | #
|
|---|
| 29 | if ! [ -e bash-${VERSION}.tar.gz ]; then
|
|---|
| 30 | wget ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}.tar.gz
|
|---|
| 31 | fi
|
|---|
| 32 |
|
|---|
| 33 | # Cleanup Directory
|
|---|
| 34 | #
|
|---|
| 35 | rm -rf bash-${VERSION} bash-${VERSION}.orig
|
|---|
| 36 | tar xvf bash-${VERSION}.tar.gz
|
|---|
| 37 | cp -ar bash-${VERSION} bash-${VERSION}.orig
|
|---|
| 38 | cd bash-${VERSION}
|
|---|
| 39 | CURRENTDIR=$(pwd -P)
|
|---|
| 40 |
|
|---|
| 41 | # Download and Apply Patches
|
|---|
| 42 | #
|
|---|
| 43 | PATCHURL=ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}-patches
|
|---|
| 44 | mkdir /tmp/bash-${VERSION}
|
|---|
| 45 | COUNT=1
|
|---|
| 46 | while [ ${COUNT} -le ${FILES} ]; do
|
|---|
| 47 | cd /tmp/bash-${VERSION}
|
|---|
| 48 | DLCOUNT="${COUNT}"
|
|---|
| 49 | SKIPME=no
|
|---|
| 50 | if [ "${COUNT}" -lt "100" ]; then
|
|---|
| 51 | DLCOUNT="0${COUNT}"
|
|---|
| 52 | fi
|
|---|
| 53 | if [ "${COUNT}" -lt "10" ]; then
|
|---|
| 54 | DLCOUNT="00${COUNT}"
|
|---|
| 55 | fi
|
|---|
| 56 | for skip in ${SKIPPATCH} ; do
|
|---|
| 57 | if [ "${DLCOUNT}" = "$skip" ]; then
|
|---|
| 58 | echo "Patch bash${VERSION2}-${DLCOUNT} skipped"
|
|---|
| 59 | SKIPPED="${SKIPPED} ${DLCOUNT}"
|
|---|
| 60 | SKIPME=yes
|
|---|
| 61 | fi
|
|---|
| 62 | done
|
|---|
| 63 | if [ "${SKIPME}" != "yes" ]; then
|
|---|
| 64 | if ! [ -e ${VERSION}.${DLCOUNT} ]; then
|
|---|
| 65 | wget --quiet ${PATCHURL}/bash${VERSION2}-${DLCOUNT}
|
|---|
| 66 | fi
|
|---|
| 67 | cd ${CURRENTDIR}
|
|---|
| 68 | patch --dry-run -s -f -Np0 -i /tmp/bash-${VERSION}/bash${VERSION2}-${DLCOUNT}
|
|---|
| 69 | if [ "$?" = "0" ]; then
|
|---|
| 70 | echo "Patch bash${VERSION2}-${DLCOUNT} applied"
|
|---|
| 71 | patch -s -Np0 -i /tmp/bash-${VERSION}/bash${VERSION2}-${DLCOUNT}
|
|---|
| 72 | else
|
|---|
| 73 | echo "Patch bash${VERSION2}-${DLCOUNT} not applied"
|
|---|
| 74 | rm -f /tmp/bash-${VERSION}/bash${VERSION2}-${DLCOUNT}
|
|---|
| 75 | SKIPPED="${SKIPPED} ${DLCOUNT}"
|
|---|
| 76 | fi
|
|---|
| 77 | fi
|
|---|
| 78 | COUNT=`expr ${COUNT} + 1`
|
|---|
| 79 | done
|
|---|
| 80 |
|
|---|
| 81 | # Cleanup Directory
|
|---|
| 82 | #
|
|---|
| 83 |
|
|---|
| 84 | for dir in $(find * -type d); do
|
|---|
| 85 | cd /usr/src/bash-${VERSION}/${dir}
|
|---|
| 86 | for file in $(find . -name '*~'); do
|
|---|
| 87 | rm -f ${file}
|
|---|
| 88 | done
|
|---|
| 89 | for file in $(find . -name '*.orig'); do
|
|---|
| 90 | rm -f ${file}
|
|---|
| 91 | done
|
|---|
| 92 | done
|
|---|
| 93 | cd /usr/src/bash-${VERSION}
|
|---|
| 94 | rm -f *~ *.orig
|
|---|
| 95 |
|
|---|
| 96 | # Create Patch
|
|---|
| 97 | #
|
|---|
| 98 | cd /usr/src
|
|---|
| 99 | echo "Submitted By: Jim Gifford (jim at cross-lfs dot org)" > bash-${VERSION}-branch_update-x.patch
|
|---|
| 100 | echo "Date: `date +%m-%d-%Y`" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 101 | echo "Initial Package Version: ${VERSION}" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 102 | echo "Origin: Upstream" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 103 | echo "Upstream Status: Applied" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 104 | echo "Description: Contains all upstream patches up to ${VERSION}-${FILES}" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 105 | if [ -n "${SKIPPED}" ]; then
|
|---|
| 106 | echo " The following patches were skipped" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 107 | echo " ${SKIPPED}" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 108 | fi
|
|---|
| 109 | echo "" >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 110 | diff -Naur bash-${VERSION}.orig bash-${VERSION} >> bash-${VERSION}-branch_update-x.patch
|
|---|
| 111 | echo "Created /usr/src/bash-${VERSION}-branch_update-x.patch."
|
|---|