-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·134 lines (112 loc) · 3.86 KB
/
build.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
#!/bin/sh
JAILNAME=vppb
FBSDTARGET=11.1-RELEASE
FBSDARCH=amd64
PORTSMETHOD=portsnap
ARTIFACTS=artifacts
WORK=work
SSHCONFIG=${WORK}/ssh_config
# Vagrant refuses to do anything if provisioners don't exist (even `vagrant destroy` doesn't work)
mkdir -p ${WORK}/options
touch ${WORK}/ports.list
# When build.sh is called by a human
if [ "$1" = "" ]; then
if [ ! -s ${WORK}/ports.list ]; then
echo "Can't find ${WORK}/ports.list. Run '$0 configure' first."
exit 1
fi
if [ ! -e ${WORK}/options ]; then
echo "Can't find ${WORK}/options. Run '$0 configure' first."
exit 1
fi
vagrant up --no-provision
if [ $? != 0 ]; then
echo 'Build failed!'
exit 1
fi
vagrant provision
if [ $? != 0 ]; then
echo 'Build failed!'
exit 1
fi
echo '==> Build complete!'
echo "==> Copying artifacts to ${ARTIFACTS}"
vagrant ssh-config --host poudriere > $SSHCONFIG
if [ ! -e "${ARTIFACTS}" ]; then
mkdir ${ARTIFACTS}
fi
# Copy packages using tar to easily preserve symlinks
# Try to work around ssh instability with the cipher/mac settings
ssh -m hmac-sha1 -c aes128-cbc -F $SSHCONFIG poudriere "tar -C /usr/local/poudriere/data/packages -cf - ." | tar -C ${ARTIFACTS} -xf -
if [ $? != 0 ]; then
echo 'Copying artifacts failed!'
exit 1
fi
echo '==> Done!'
echo
echo "Artifacts are in: ${ARTIFACTS}"
echo "Don't forget to run 'vagrant destroy' if you're done with the build VM."
# Clean up
elif [ "$1" = "clean" ]; then
read -p "This will delete the artifacts directory and the vagrant VM. Hit enter to continue." OK
rm -rf $SSHCONFIG artifacts
vagrant destroy -f
elif [ "$1" = "configure" ]; then
> ${WORK}/ports.list
echo "Enter the ports you want to build, one per line. Enter a blank line to stop."
while read line; do
if [ -z "$line" ]; then break; fi
echo $line >> ${WORK}/ports.list
done
for port in `cat ${WORK}/ports.list`;
do
curl --output /dev/null --silent --head --fail https://raw.githubusercontent.com/freebsd/freebsd-ports/master/${port}/Makefile
if [ $? != 0 ]; then
echo "Cannot find port $port"
exit 1
fi
done
if [ ! -e ${WORK}/repo.key ]; then
echo "Can't find a signing key. Enter a path to a private key, or press enter to generate one."
read line
if [ -z "$line" ]; then
openssl genrsa -out ${WORK}/repo.key 2048
chmod 0400 ${WORK}/repo.key
openssl rsa -in ${WORK}/repo.key -out ${WORK}/repo.pub -pubout
else
if [ ! -e $line ]; then
echo "Can't find private key file: $line"
exit 1
fi
ln -s $line ${WORK}/repo.key
fi
fi
vagrant up --provision-with portsfile,installonly
if [ $? != 0 ]; then
echo 'Configuration failed!'
exit 1
fi
vagrant ssh -- -t "sudo poudriere options -f /usr/local/etc/poudriere.d/ports.list"
if [ $? != 0 ]; then
echo 'Configuration failed!'
exit 1
fi
vagrant ssh-config --host poudriere > $SSHCONFIG
rm -rf ${WORK}/options/*
scp -r -F $SSHCONFIG "poudriere:/usr/local/etc/poudriere.d/options/*" ${WORK}/options/ &>/dev/null
echo "==> Configuration done. Ready to run $0."
# Only install poudriere and set up files for running 'options'
elif [ "$1" = "installonly" ]; then
env ASSUME_ALWAYS_YES=YES pkg install ports-mgmt/poudriere
poudriere ports -c -m $PORTSMETHOD
mv /tmp/ports.list /usr/local/etc/poudriere.d/ports.list
rm -rf /usr/local/etc/poudriere.d/options/*
# When build.sh is called by vagrant ("poudriere" matches the arg to this script in Vagrantfile)
elif [ "$1" = "poudriere" ]; then
mkdir -p /usr/ports/distfiles
poudriere jail -c -j $JAILNAME -v $FBSDTARGET -a $FBSDARCH
echo "WITH_PKGNG=yes" >> /usr/local/etc/poudriere.d/make.conf
echo "PKG_REPO_SIGNING_KEY=/tmp/repo.key" >> /usr/local/etc/poudriere.conf
mv /tmp/options /usr/local/etc/poudriere.d/
poudriere bulk -j $JAILNAME -f /usr/local/etc/poudriere.d/ports.list
fi