-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathimport-src.sh
More file actions
executable file
·228 lines (201 loc) · 7.04 KB
/
import-src.sh
File metadata and controls
executable file
·228 lines (201 loc) · 7.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#
# import-src.sh - Import specific release of OpenBSD source in to
# this tree. Primarily for maintenance use when
# a new version of OpenBSD comes out.
#
# Author: David Cantrell <david.l.cantrell@gmail.com>
# Author: Diego Magdaleno <diegomagdaleno@protonmail.com>
#
# Segitt our fail exist function, this is useful for Downdalos
function fail_exit() {
cd ${CWD}
rm -rf ${TMPDIR}
exit 1
}
OS="$(uname)"
if [ "$OS" = "Darwin" ]; then
PATH=/bin:/usr/bin:/usr/local/bin
else
PATH=/bin:/usr/bin
fi
if [ "$OS" = "Darwin" ]; then
if hash greadlink 2>/dev/null; then
CWD="$(dirname "$(greadlink -f "$0")")"
else
echo "You need GNU coreutils to run this script on Darwin"
exit 1
fi
else
CWD="$(dirname "$(readlink -f "$0")")"
fi
if [ "$OS" = "Darwin" ]; then
if hash gmktemp 2>/dev/null; then
TMPDIR="$(gmktemp -d --tmpdir=${CWD})"
else
echo "You need GNU coreutils to run this script"
exit 1
fi
else
TMPDIR="$(mktemp -d --tmpdir=${CWD})"
fi
if [ "$OS" = "Darwin" ]; then
if hash greadlink 2>/dev/null; then
FILE_SOURCE_LIST=($(find $CWD/configurations -type f \( -name "*.conf" \) -exec greadlink -f {} \;))
else
echo "You need GNU coreutils to run this script on Darwin"
exit 1
fi
else
FILE_SOURCE_LIST=($(find $CWD/configurations -type f \( -name "*.conf" \) -exec readlink -f {} \;))
fi
for configuration in "${FILE_SOURCE_LIST[@]}"
do
. $configuration
done
for sub in compat src ; do
[ -d ${CWD}/${sub} ] || mkdir -p ${CWD}/${sub}
done
# While it doesn't really make sense we are copying and pasting the code
# for the same operating and this could be a function
# the problem is, this is bash, so positional paremeters just suck, so its better
# to write a few lines and just avoid problems.
# Note for Diego of the future if you screw up, you did this to yourself.
cd ${TMPDIR}
curl -L --retry 3 --ftp-pasv -O ${SRC} || fail_exit
if [ "$OS" = "Darwin" ]; then
SHA256OFSRC="$(shasum -a 256 src.tar.gz | awk '{print $1}')"
else
SHA256OFSRC="$(sha256sum src.tar.gz | awk '{print $1}')"
fi
if [ "$SHA256OFSRC" != ${SHA256SRC} ]; then
echo "Error, the integrity of the file failed, operating is unsafe and cannot continue."
exit 1
fi
gzip -dc src.tar.gz | tar -xvf -
curl -L --retry 3 --ftp-pasv -O ${SYS} || fail_exit
if [ "$OS" = "Darwin" ]; then
SHA256OFSYS="$(shasum -a 256 sys.tar.gz | awk '{print $1}')"
else
SHA256OFSYS="$(sha256sum sys.tar.gz | awk '{print $1}')"
fi
if [ "$SHA256OFSYS" != ${SHA256SYS} ]; then
echo "Error, the integrity of the file failed, operating is unsafe and cannot continue."
exit 1
fi
gzip -dc sys.tar.gz | tar -xvf -
for p in ${CMDS} ; do
sp="$(basename ${p})"
find ${p} -type d -name CVS | xargs rm -rf
# Rename the upstream Makefile for later manual checking. We don't
# commit these to our tree, but just look at them when rebasing and
# pick up any rule changes to put in our Makefile.am files.
if [ -f "${p}/Makefile" ]; then
mv ${p}/Makefile ${p}/Makefile.bsd
fi
# Copy in the upstream files
[ -d ${CWD}/src/${p} ] || mkdir -p ${CWD}/src/${sp}
for source_f in ${p}/*; do
ssource_f="$(basename ${source_f})"
cp -p $source_f "${CWD}/src/${sp}/${ssource_f}"
done
done
for file in "${COMPAT_TOOLS_C[@]}"
do
file_base="$(basename ${file})"
cp -p $file ${CWD}/compat/src/${file_base}
done
for header in "${COMPAT_TOOLS_HEADERS[@]}"
do
if [ ! -d ${CWD}/compat/src ]; then
mkdir -p ${CWD}/compat/src/
fi
header_base="$(basename ${header})"
cp -p $header ${CWD}/compat/src/${header_base}
done
for filef in "${FACTOR_C[@]}"
do
filef_base=file_base="$(basename ${file})"
cp -p $filef ${CWD}/src/factor/${file_base}
done
for headerf in "${FACTOR_HEADER[@]}"
do
headerf_base=file_base="$(basename ${headerf})"
cp -p $filef ${CWD}/src/factor/${filef}
done
################
# COMMON EDITS #
################
# Perform some common compatibility edits on the imported source
for cfile in ${CWD}/compat/src/*.c ; do
# This macro does not exist and we don't want it #TODO: Does this exist on Darwin?
if [ "$OS" = "Darwin" ]; then
gsed -i -e '/DEF_WEAK/d' ${cfile}
else
sed -i -e '/DEF_WEAK/d' ${cfile}
fi
# Include our 'compat.h' header before other includes
# TODO: Redo this to look better currently a nested if depending on the operating system
# is not a very clean solution!
if [ "$OS" = "Darwin" ]; then
if ! ggrep -q "compat\.h" ${cfile} 2>&1 ; then
linenum=$(($(ggrep -n ^#include ${cfile} | gsort -n | ghead -n 1 | gcut -d ':' -f 1) - 1))
[ ${linenum} = 0 ] && linenum=1
gsed -i -e "${linenum}i #include \"compat.h\"" ${cfile}
fi
else
if ! grep -q "compat\.h" ${cfile} 2>&1 ; then
linenum=$(($(grep -n ^#include ${cfile} | sort -n | head -n 1 | cut -d ':' -f 1) - 1))
[ ${linenum} = 0 ] && linenum=1
sed -i -e "${linenum}i #include \"compat.h\"" ${cfile}
fi
fi
done
# Remove unnecessary declarations in compat/util.h
if [ "$OS" = "Darwin" ]; then
strtline=$(ggrep -n "^__BEGIN_DECLS" ${CWD}/compat/src/util.h | gcut -d ':' -f 1)
lastline=$(ggrep -n "^__END_DECLS" ${CWD}/compat/src/util.h | gcut -d ':' -f 1)
sed -i -e "${strtline},${lastline}d" ${CWD}/compat/src/util.h
else
strtline=$(grep -n "^__BEGIN_DECLS" ${CWD}/compat/src/util.h | cut -d ':' -f 1)
lastline=$(grep -n "^__END_DECLS" ${CWD}/compat/src/util.h | cut -d ':' -f 1)
sed -i -e "${strtline},${lastline}d" ${CWD}/compat/src/util.h
fi
# Common edits needed for src/ files
for cfile in $(find ${CWD}/src -type f -name '*.c' -print) ; do
# remove __dead
if [ "$OS" = "Darwin" ]; then
gsed -i -r 's|\s+__dead\s+| |g' ${cfile}
gsed -i -r 's|^__dead\s+||g' ${cfile}
gsed -i -r 's|\s+__dead$||g' ${cfile}
gsed -i -r 's|\s+__dead;|;|g' ${cfile}
else
sed -i -r 's|\s+__dead\s+| |g' ${cfile}
sed -i -r 's|^__dead\s+||g' ${cfile}
sed -i -r 's|\s+__dead$||g' ${cfile}
sed -i -r 's|\s+__dead;|;|g' ${cfile}
fi
done
#####################
# APPLY ANY PATCHES #
#####################
if [ -d ${CWD}/patches/compat ]; then
for patchfile in ${CWD}/patches/compat/*.patch ; do
destfile="$(basename ${patchfile} .patch)"
[ -f "${CWD}/compat/src/${destfile}.orig" ] && rm -f "${CWD}/compat/src/${destfile}.orig"
patch -d ${CWD}/compat/src -p0 -b -z .orig < ${patchfile}
done
fi
if [ -d ${CWD}/patches/src ]; then
cd ${CWD}/patches/src
for subdir in * ; do
[ -d ${subdir} ] || continue
for patchfile in ${CWD}/patches/src/${subdir}/*.patch ; do
destfile="$(basename ${patchfile} .patch)"
[ -f "${CWD}/src/${subdir}/${destfile}.orig" ] && rm -f "${CWD}/src/${subdir}/${destfile}.orig"
patch -d ${CWD}/src/${subdir} -p0 -b -z .orig < ${patchfile}
done
done
fi
#Clean up
rm -rf ${TMPDIR}