-
Notifications
You must be signed in to change notification settings - Fork 7
/
functions.sh
executable file
·314 lines (251 loc) · 7.48 KB
/
functions.sh
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
#!/bin/sh
# Most of these dont need to be modified
#########################################################
# Where is the pcbsd-build program installed
PROGDIR="`realpath | sed 's|/scripts||g'`" ; export PROGDIR
# Source vars
. ${PROGDIR}/pcbsd.cfg
# Where on disk is the PCBSD GIT branch
GITBRANCH="${PROGDIR}/git/pcbsd"
export GITBRANCH
# Where are the dist files
DISTDIR="${PROGDIR}/fbsd-dist" ; export DISTDIR
# Set the dist files
BASEDIST="$DISTDIR/base.txz"
KERNDIST="$DISTDIR/kernel.txz"
L32DIST="$DISTDIR/lib32.txz"
export BASEDIST KERNDIST L32DIST
# Kernel Config
PCBSDKERN="GENERIC" ; export PCBSDKERN
# Set where we wish to copy our checked out FreeBSD source
WORLDSRC="${PROGDIR}/git/freebsd"
export WORLDSRC
# Where to build the world directory
PDESTDIR="${PROGDIR}/buildworld" ; export PDESTDIR
PDESTDIR9="${PROGDIR}/buildworld9" ; export PDESTDIR9
PDESTDIRFBSD="${PROGDIR}/buildworld-fbsd" ; export PDESTDIRFBSD
PDESTDIRSERVER="${PROGDIR}/buildworld-server" ; export PDESTDIRSERVER
# Set the PC-BSD Version
export PCBSDVER="${TARGETREL}"
# Where are the config files
PCONFDIR="${GITBRANCH}/build-files/conf" ; export PCONFDIR
# Where do we place the log files
PLOGFILES="${PROGDIR}/log" ; export PLOGFILES
REALARCH="`uname -m`"
export REALARCH
case $ARCH in
i386) FARCH="x86" ; export FARCH ;;
amd64) FARCH="x64" ; export FARCH ;;
*) FARCH="x86" ; export FARCH ;;
esac
# Set the location of packages needed for our Meta-Packages
export METAPKGDIR="${PROGDIR}/tmp/All"
# Poudriere Ports tag, change to use multiple ports trees
if [ -z "$POUDPORTS" ] ; then
POUDPORTS="pcbsdports" ; export POUDPORTS
fi
# Poudriere Ports tag, change to use multiple ports trees
if [ -z "$POUDPORTS" ] ; then
POUDPORTS="pcbsdports" ; export POUDPORTS
fi
# Poudriere variables
PBUILD="pcbsd-`echo $TARGETREL | sed 's|\.||g'`"
PJDIR="$POUD/jails/$PBUILD"
PPKGDIR="$POUD/data/packages/$PBUILD-$POUDPORTS"
PJPORTSDIR="$POUD/ports/$POUDPORTS"
export PBUILD PJDIR PJPORTSDIR PPKGDIR
# Check for required dirs
rDirs="/log /git /iso /fbsd-dist /tmp"
for i in $rDirs
do
if [ ! -d "${PROGDIR}/${i}" ] ; then
mkdir -p ${PROGDIR}/${i}
fi
done
################
# Functions
################
exit_err() {
echo "ERROR: $@"
exit 1
}
clean_wrkdir()
{
if [ -z "$1" ] ; then exit_err "Missing wrkdir..."; fi
if [ -e "${1}" ]; then
echo "Cleaning up ${1}"
umount -f ${1}/dev >/dev/null 2>/dev/null
umount -f ${1}/mnt >/dev/null 2>/dev/null
umount -f ${1}/usr/src >/dev/null 2>/dev/null
umount -f ${1} >/dev/null 2>/dev/null
rmdir ${1}
fi
}
mk_tmpfs_wrkdir()
{
if [ -z "$1" ] ; then exit_err "Missing wrkdir..."; fi
clean_wrkdir "$1"
mkdir -p "${1}"
mount -t tmpfs tmpfs "${1}"
}
extract_dist()
{
if [ -z "$1" -o -z "$2" ] ; then exit_err "Missing variables..." ; fi
if [ ! -e "$1" ] ; then exit_err "Invalid DISTFILE $1" ; fi
if [ ! -d "$2" ] ; then exit_err "Invalid DESTDIR $2" ; fi
echo "Extracting $1 to $2"
tar xvf $1 -C $2 2>/dev/null
}
cp_overlay()
{
echo "Copying overlay $1 -> $2"
tar cvf - --exclude .svn -C ${1} . 2>/dev/null | tar xvmf - -C ${2} 2>/dev/null
}
git_fbsd_up()
{
local lDir=${1}
local rDir=${2}
local oDir=`pwd`
cd "${lDir}"
echo "GIT checkout $GITFBSDBRANCH"
git checkout ${GITFBSDBRANCH}
echo "GIT pull: ${GITFBSDBRANCH}"
git pull origin ${GITFBSDBRANCH}
if [ $? -ne 0 ] ; then
exit_err "Failed doing a git pull"
fi
cd "${oDir}"
return 0
}
git_up()
{
local lDir=${1}
local rDir=${2}
local oDir=`pwd`
cd "${lDir}"
local gbranch="$GITPCBSDBRANCH"
if [ -z "$gbranch" ] ; then
gbranch="master"
fi
echo "GIT checkout: ${gbranch}"
git checkout ${gbranch}
if [ $? -ne 0 ] ; then
exit_err "Failed doing a git checkout"
fi
echo "GIT pull: ${1}"
git pull
if [ $? -ne 0 ] ; then
exit_err "Failed doing a git pull"
fi
cd "${oDir}"
return 0
}
# Run-command, don't halt if command exits with non-0
rc_nohalt()
{
local CMD="$1"
if [ -z "${CMD}" ]
then
exit_err "Error: missing argument in rc_nohalt()"
fi
${CMD} 2>/dev/null >/dev/null
};
# Run-command, halt if command exits with non-0
rc_halt()
{
local CMD="$1"
if [ -z "${CMD}" ]; then
exit_err "Error: missing argument in rc_halt()"
fi
echo "Running command: $CMD"
${CMD}
if [ $? -ne 0 ]; then
exit_err "Error ${STATUS}: ${CMD}"
fi
};
rtn()
{
echo "Press ENTER to continue"
read tmp
};
create_pkg_conf()
{
cp ${PROGDIR}/pkg.conf ${PROGDIR}/tmp/pkg.conf
cp ${PROGDIR}/pkg-pubkey.cert ${PROGDIR}/tmp/pkg-pubkey.cert
sed -i '' "s|%RELVERSION%|$TARGETREL|g" ${PROGDIR}/tmp/pkg.conf
sed -i '' "s|%ARCH%|$ARCH|g" ${PROGDIR}/tmp/pkg.conf
sed -i '' "s|%PROGDIR%|$PROGDIR|g" ${PROGDIR}/tmp/pkg.conf
if [ "$PKGREPO" = "local" ]; then
cat ${PROGDIR}/tmp/pkg.conf | grep -v "packagesite:" > ${PROGDIR}/tmp/pkg.conf.local
mv ${PROGDIR}/tmp/pkg.conf.local ${PROGDIR}/tmp/pkg.conf
echo "packagesite: file://${PPKGDIR}" >> ${PROGDIR}/tmp/pkg.conf
fi
}
# Copy the ISO package files to a new location
cp_iso_pkg_files()
{
if [ ! -d "$METAPKGDIR" ] ; then
mkdir ${METAPKGDIR}
fi
create_pkg_conf
echo "Fetching PC-BSD ISO packages... Please wait, this may take several minutes..."
haveWarn=0
# Pkgs to skip for now
skipPkgs="misc/pcbsd-meta-gnome-games misc/pcbsd-meta-kde-education misc/pcbsd-meta-kde-games misc/pcbsd-meta-kde-toys misc/pcbsd-meta-kde-webdevkit misc/pcbsd-meta-mythtv misc/pcbsd-meta-xbmc misc/pcbsd-meta-kde-calligra misc/pcbsd-meta-kde-sdk misc/pcbsd-meta-rekonq misc/pcbsd-meta-development-embedded misc/pcbsd-meta-development-science"
# Build a list of packages we need to fetch
cd ${GITBRANCH}/build-files/ports-overlay
local pkgList="ports-mgmt/pkg sysutils/pcbsd-utils sysutils/pcbsd-utils-qt4 `ls -d misc/pcbsd*` `ls -d misc/trueos*`"
# Now fetch these packages
for pkgName in $pkgList
do
# See if this is something we can skip for now
skip=0
for j in $skipPkgs
do
if [ "$pkgName" = "${j}" ] ; then skip=1; break; fi
done
if [ $skip -eq 1 ] ; then echo "Skipping $pkgBase.."; continue ; fi
# Fetch the packages
rc_halt "pkg -C ${PROGDIR}/tmp/pkg.conf fetch -y -d ${pkgName}"
done
# Copy pkgng
cp ${PROGDIR}/tmp/All/pkg-*.txz ${PROGDIR}/tmp/All/pkg.txz
}
update_poudriere_jail()
{
# Setup fake poudriere file URL
mkdir -p /fakeftp/pub/FreeBSD/releases/${ARCH}/${ARCH}/$PCBSDVER >/dev/null 2>/dev/null
dfiles="src.txz base.txz doc.xz games.txz kernel.txz"
if [ "$ARCH" = "amd64" ] ; then dfiles="$dfiles lib32.txz" ; fi
for i in $dfiles
do
ln -sf "${DISTDIR}/$i" /fakeftp/pub/FreeBSD/releases/${ARCH}/${ARCH}/${PCBSDVER}/$i
done
echo "FREEBSD_HOST=file:///fakeftp/" >> /usr/local/etc/poudriere.conf
# Clean old poudriere dir
poudriere jail -d -j $PBUILD >/dev/null 2>/dev/null
poudriere jail -c -j $PBUILD -v ${PCBSDVER} -a $ARCH
if [ $? -ne 0 ] ; then
cat /usr/local/etc/poudriere.conf | grep -v "^FREEBSD_HOST=file:///fakeftp/" >/tmp/.pconf.$$
mv /tmp/.pconf.$$ /usr/local/etc/poudriere.conf
echo "Failed to create poudriere jail"
exit 1
fi
# Cleanup the hostname
cat /usr/local/etc/poudriere.conf | grep -v "^FREEBSD_HOST=file:///fakeftp/" >/tmp/.pconf.$$
mv /tmp/.pconf.$$ /usr/local/etc/poudriere.conf
rm -rf /fakeftp
}
get_last_rev()
{
oPWD=`pwd`
rev=0
cd "$1"
rev=`git log -n 1 --date=raw ${1} | grep 'Date:' | awk '{print $2}'`
cd $oPWD
if [ $rev -ne 0 ] ; then
echo "$rev"
return 0
fi
return 1
}