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 | install -d ~/tmp
|
---|
19 | cd ~/tmp
|
---|
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
|
---|
31 | wget ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}.tar.gz
|
---|
32 | fi
|
---|
33 |
|
---|
34 | # Set Patch Number
|
---|
35 | #
|
---|
36 | cd ~/tmp
|
---|
37 | wget http://svn.cross-lfs.org/svn/repos/patches/bash/ --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 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 | #
|
---|
60 | install -d ~/tmp/bash-${VERSION}-patches
|
---|
61 | cd ~/tmp/bash-${VERSION}
|
---|
62 | CURRENTDIR=$(pwd -P)
|
---|
63 | PATCHURL=ftp://ftp.cwru.edu/pub/bash/bash-${VERSION}-patches
|
---|
64 | COUNT=1
|
---|
65 | while [ ${COUNT} -le ${FILES} ]; do
|
---|
66 | cd ~/tmp/bash-${VERSION}
|
---|
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
|
---|
84 | cd ~/tmp/bash-${VERSION}-patches
|
---|
85 | wget --quiet ${PATCHURL}/bash${VERSION2}-${DLCOUNT}
|
---|
86 | fi
|
---|
87 | cd ${CURRENTDIR}
|
---|
88 | patch --dry-run -s -f -Np0 -i ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT}
|
---|
89 | if [ "$?" = "0" ]; then
|
---|
90 | echo "Patch bash${VERSION2}-${DLCOUNT} applied"
|
---|
91 | patch -s -Np0 -i ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT}
|
---|
92 | else
|
---|
93 | echo "Patch bash${VERSION2}-${DLCOUNT} not applied"
|
---|
94 | rm -f ~/tmp/bash-${VERSION}-patches/bash${VERSION2}-${DLCOUNT}
|
---|
95 | SKIPPED="${SKIPPED} ${DLCOUNT}"
|
---|
96 | fi
|
---|
97 | fi
|
---|
98 | COUNT=`expr ${COUNT} + 1`
|
---|
99 | done
|
---|
100 |
|
---|
101 | # Cleanup Directory
|
---|
102 | #
|
---|
103 | cd ~/tmp/bash-${VERSION}
|
---|
104 | for dir in $(find * -type d); do
|
---|
105 | cd ~/tmp/bash-${VERSION}/${dir}
|
---|
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
|
---|
112 | done
|
---|
113 | cd ~/tmp/bash-${VERSION}
|
---|
114 | rm -f *~ *.orig
|
---|
115 |
|
---|
116 | # Create Patch
|
---|
117 | #
|
---|
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
|
---|
126 | if [ -n "${SKIPPED}" ]; then
|
---|
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
|
---|
129 | fi
|
---|
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
|
---|