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