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