-
Notifications
You must be signed in to change notification settings - Fork 6
/
fabrik-arm64.sh
executable file
·272 lines (239 loc) · 8.27 KB
/
fabrik-arm64.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
#!/bin/sh
set -e
# ----------------------------------------------------------------------------
# fabrik.sh - All in one script to create the disk.raw image
# ----------------------------------------------------------------------------
NUMBER_OF_CORES=`sysctl -n hw.ncpu`
FREEBSD_VERSION=12
USER=devops
PASSWORD=fabrik
ZPOOL=zroot
WRKDIR=/fabrik/arm64
KERNEL=GENERIC
ARCH=arm64
# ----------------------------------------------------------------------------
# no need to edit below this
# ----------------------------------------------------------------------------
START=$(date +%s)
write() {
echo -e '\e[0;32m'
echo \#----------------------------------------------------------------------------
echo \# $1
echo -e \#----------------------------------------------------------------------------'\e[0m'
}
write "Checking out and updating sources FreeBSD: ${FREEBSD_VERSION}"
svnlite co svn://svn.freebsd.org/base/stable/${FREEBSD_VERSION} /usr/src
write "Fetching src.conf, src-jail.conf, make.conf, fabrik.kernel"
fetch --no-verify-peer -a https://rawgit.com/fabrik-red/images/master/src.conf -o /etc/fabrik-src.conf
fetch --no-verify-peer -a https://rawgit.com/fabrik-red/images/master/src-jail.conf -o /etc/src-jail.conf
fetch --no-verify-peer -a https://rawgit.com/fabrik-red/images/master/make-arm64.conf -o /etc/fabrik-arm64-make.conf
# fetch --no-verify-peer -a https://rawgit.com/fabrik-red/images/master/fabrik-aws.kernel -o /usr/src/sys/amd64/conf/${KERNEL}
write "Creating ${WRKDIR} dir"
mkdir -p ${WRKDIR}/host
mkdir -p ${WRKDIR}/jail
write "building world, kernel and jail world"
cd /usr/src
env MAKEOBJDIRPREFIX=${WRKDIR}/host/obj SRCCONF=/etc/fabrik-src.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make -DNO_CLEAN -j${NUMBER_OF_CORES} TARGET_ARCH=${ARCH} buildworld
env MAKEOBJDIRPREFIX=${WRKDIR}/host/obj SRCCONF=/etc/fabrik-src.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make -DNO_CLEAN -j${NUMBER_OF_CORES} TARGET_ARCH=${ARCH} buildkernel KERNCONF=${KERNEL}
# env MAKEOBJDIRPREFIX=${WRKDIR}/jail/obj SRCCONF=/etc/src-jail.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make -DNO_CLEAN -j${NUMBER_OF_CORES} buildworld
# ----------------------------------------------------------------------------
# Creating disk.raw
# ----------------------------------------------------------------------------
cd ${WRKDIR}
IMAGE=arm64
VMSIZE=1g
SWAPSIZE=1G
LOGDIR=${WRKDIR}/tmp
mkdir -p ${LOGDIR}
rm -f ${IMAGE}
rm -f ${IMAGE}.raw
truncate -s ${VMSIZE} ${IMAGE}
mddev=$(mdconfig -a -t vnode -f ${IMAGE})
newfs /dev/${mddev}
mount /dev/${mddev} /mnt
write "Installing world, kernel and jail world"
cd /usr/src;
env MAKEOBJDIRPREFIX=${WRKDIR}/host/obj SRCCONF=/etc/fabrik-src.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make DESTDIR=/mnt TARGET_ARCH=${ARCH} installworld 2>&1 | tee ${LOGDIR}/host-installworld.log &&
env MAKEOBJDIRPREFIX=${WRKDIR}/host/obj SRCCONF=/etc/fabrik-src.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make DESTDIR=/mnt TARGET_ARCH=${ARCH} installkernel KERNCONF=${KERNEL} 2>&1 | tee ${LOGDIR}/host-installkernel.log &&
env MAKEOBJDIRPREFIX=${WRKDIR}/host/obj SRCCONF=/etc/fabrik-src.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make DESTDIR=/mnt TARGET_ARCH=${ARCH} distribution 2>&1 | tee ${LOGDIR}/host-distribution.log
# create jails dir
#mkdir -p /mnt/jails/base
# installworld & distribution for jail
#env MAKEOBJDIRPREFIX=${WRKDIR}/jail/obj SRCCONF=/etc/src-jail.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make DESTDIR=/mnt/jails/base installworld 2>&1 | tee ${LOGDIR}/jail-installworld.log && \
#env MAKEOBJDIRPREFIX=${WRKDIR}/jail/obj SRCCONF=/etc/src-jail.conf __MAKE_CONF=/etc/fabrik-aws-make.conf make DESTDIR=/mnt/jails/base distribution 2>&1 | tee ${LOGDIR}/jail-distribution.log
mkdir -p /mnt/dev
mount -t devfs devfs /mnt/dev
chroot /mnt /etc/rc.d/ldconfig forcestart
umount /mnt/dev
write "Creating user ${USER} with password ${PASSWORD}"
chroot /mnt pw useradd ${USER} -m -G wheel -s /bin/csh -h 0 <<EOP
${PASSWORD}
EOP
cp /etc/resolv.conf /mnt/etc/resolv.conf
write "Installing curl"
yes | chroot /mnt /usr/bin/env ASSUME_ALWAYS_YES=yes pkg install -qy curl > /dev/null 2>&1
chroot /mnt /usr/bin/env ASSUME_ALWAYS_YES=yes pkg clean -qya > /dev/null 2>&1
rm -rf /mnt/var/db/pkg/repo*
write "Creating firstboot scripts"
chroot /mnt mkdir -p /usr/local/etc/rc.d
touch /mnt/firstboot
touch /mnt/firstboot-reboot
# ----------------------------------------------------------------------------
# .cshrc
# ----------------------------------------------------------------------------
sed 's/^X//' >/mnt/root/.cshrc << 'CSHRC'
Xalias h history 25
Xalias j jobs -l
Xalias la ls -aF
Xalias lf ls -FA
Xalias ll ls -lAF
Xalias rm rm -i
Xalias mv mv -i
Xalias cp cp -i
X
X# A righteous umask
Xumask 22
X
Xset path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
X
Xsetenv EDITOR vi
Xsetenv PAGER less
Xsetenv BLOCKSIZE K
Xsetenv CLICOLOR
Xsetenv LSCOLORS gxfxcxdxbxegedabagacad
X
Xset COLOR1="%{\e[0;32m%}"
Xset COLOR2="%{\e[0;33m%}"
Xset COLOR3="%{\e[0;36m%}"
Xset COLOR4="%{\e[0;0m%}"
Xset COLOR5="%{\e[0;33m%}"
X
Xif ($?prompt) then
X if ($uid == 0) then
X set COLOR3="%{\e[1;31m%}"
X set user = root
X endif
X set prompt="$COLOR2\[$COLOR3%n@%M$COLOR2\:$COLOR1%~$COLOR2\] [%p %d]\n$COLOR5>$COLOR4 "
X set promptchars = "%#"
X
X set filec
X set history = 1000
X set savehist = (1000 merge)
X set autolist = ambiguous
X set autoexpand
X set autorehash
X set mail = (/var/mail/$USER)
X if ( $?tcsh ) then
X bindkey "^W" backward-delete-word
X bindkey -k up history-search-backward
X bindkey -k down history-search-forward
X endif
X
Xendif
CSHRC
cp -f /mnt/root/.cshrc /mnt/usr/home/devops/.cshrc
# /etc/fstab
cat << EOF > /mnt/etc/fstab
/dev/gpt/rootfs / ufs rw 1 1
/dev/gpt/swapfs none swap sw 0 0
EOF
# /boot/loader.conf
cat << EOF > /mnt/boot/loader.conf
autoboot_delay="-1"
beastie_disable="YES"
boot_multicons="YES"
console="comconsole,vidconsole"
hw.broken_txfifo="1"
hw.memtest.test="0"
hw.vtnet.mq_disable="1"
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
EOF
# /etc/rc.conf
cat << EOF > /mnt/etc/rc.conf
aws_firstboot_enable="YES"
growfs_enable="YES"
hostname="fabrik" # change to your desired hostname
ifconfig_DEFAULT="SYNCDHCP -tso"
clear_tmp_enable="YES"
dumpdev="NO"
ntpd_enable="YES"
ntpdate_enable="YES"
sendmail_enable="NONE"
sshd_enable="YES"
syslogd_flags="-ssC"
#-----------------------------------------------------------------------
# jails
#-----------------------------------------------------------------------
jail_enable="NO"
jail_list="base"
EOF
# /etc/pf.conf
cat << EOF > /mnt/etc/pf.conf
ext_if = "xn0"
set skip on lo
scrub in all
nat on \$ext_if from lo1:network to any -> (\$ext_if)
pass all
EOF
# /etc/sysctl.conf
cat << EOF > /mnt/etc/sysctl.conf
debug.debugger_on_panic=0
debug.trace_on_panic=1
kern.panic_reboot_wait_time=0
net.inet.tcp.tso=0
security.bsd.see_other_gids=0
security.bsd.see_other_uids=0
security.bsd.stack_guard_page=1
security.bsd.unprivileged_proc_debug=0
security.bsd.unprivileged_read_msgbuf=0
EOF
# /etc/jail.conf
cat << EOF > /mnt/etc/jail.conf
exec.start = "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.clean;
mount.devfs;
allow.raw_sockets;
securelevel=3;
host.hostname="\$name.fabrik"; # change to your desired hostname
path="/jails/\$name";
base {
jid = 10;
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/MultipleIP.html
# ip4.addr = 172.16.13.2;
}
EOF
# jail rc.conf
#cat << EOF > /mnt/jails/base/etc/rc.conf
#sshd_enable="YES"
#sshd_flags="-4"
#syslogd_flags="-ssC"
#clear_tmp_enable="YES"
#sendmail_enable="NONE"
#cron_flags="\$cron_flags -J 60"
#EOF
# jail /etc/resolv.conf
#cat << EOF > /mnt/jails/base/etc/resolv.conf
#nameserver 84.200.70.40
#nameserver 208.67.222.222
#nameserver 4.2.2.2
#nameserver 2001:4860:4860::8888
#nameserver 2001:1608:10:25::1c04:b12f
#EOF
umount /dev/${mddev}
tunefs -j enable /dev/${mddev}
mdconfig -d -u ${mddev}
chflags -R noschg /mnt
rm -rf /mnt/*
# create raw
BOOTFILES=${WRKDIR}/host/obj/usr/src/sys/boot
mkimg -s gpt -f raw \
-b ${BOOTFILES}/i386/pmbr/pmbr \
-p freebsd-boot/bootfs:=${BOOTFILES}/i386/gptboot/gptboot \
-p freebsd-swap/swapfs::${SWAPSIZE} \
-p freebsd-ufs/rootfs:=${WRKDIR}/${IMAGE} \
-o ${WRKDIR}/${IMAGE}.raw
END=$(date +%s)
DIFF=$(echo "$END - $START" | bc)
write "Done! build in $DIFF seconds."