-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabd
executable file
·394 lines (327 loc) · 10.2 KB
/
abd
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/bin/bash
initfs()
{
echo Creating initfs
rm -rf /root/initfs 2> /dev/null
mkdir -p /root/initfs 2> /dev/null
pushd /root/initfs > /dev/null || return 1
mkdir -p {bin,sbin,sys,dev,proc,etc,lib,mount/cdrom}
mknod dev/console c 5 1
mknod dev/ram0 b 1 1
mknod dev/null c 1 3
mknod dev/tty1 c 4 1
mknod dev/tty2 c 4 2
mknod dev/sda b 8 0
mknod dev/sda1 b 8 1
mknod dev/sda2 b 8 2
mknod dev/sda3 b 8 3
mknod dev/sda4 b 8 4
mknod dev/sda5 b 8 5
mknod dev/sda6 b 8 6
mknod dev/sda7 b 8 7
mknod dev/sda8 b 8 8
mknod dev/sdb b 8 16
mknod dev/sdb1 b 8 17
mknod dev/sdb2 b 8 18
mknod dev/sdb3 b 8 19
mknod dev/sdb4 b 8 20
mknod dev/sdb5 b 8 21
mknod dev/sdb6 b 8 22
mknod dev/sdb7 b 8 23
mknod dev/sdb8 b 8 24
mknod dev/sr0 b 11 0
mknod dev/sr1 b 11 1
# Create symbolic links in bin for BusyBox
pushd bin > /dev/null || return 1
# If this fails then you need to copy a statically linked
# BusyBox to /root/bin/busybox
cp /root/bin/busybox . || return 1
for b in $(/root/bin/busybox --list); do
ln -s busybox ${b}
done
# Copy the binaries and their dependencies
cp /lib/ld-linux.so.2 ../lib
cp /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 ../lib
bins=(ld cfdisk ldd bash nano)
for f in "${bins[@]}"
do
file=`which ${f}`
echo "${file}"
cp ${file} .
ldd ${file} | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' ../lib
done
popd > /dev/null
# Populate sbin
pushd sbin > /dev/null || return 1
cp /usr/sbin/grub-install .
popd > /dev/null
# ln -s bin sbin
# Create the init script
#TODO Eventually this gets replaced with a real init
cat <<EOF >> init
#!/bin/ash
mount -t proc /proc /proc
mount -t sysfs none /sys
mount /dev/sr0 /mount/cdrom
echo
echo "initrd is running"
echo "Using BusyBox..."
echo
exec /bin/ash
EOF
chmod a+x init
# Now create the gzipped initrd.img
find . | cpio -o -H newc | gzip > ../CD_root/boot/initrd.img
cp /root/linux-4.5.3/arch/x86_64/boot/bzImage /root/CD_root/boot/
popd > /dev/null
echo Done!
}
mkiso()
{
pushd /root > /dev/null || return 1
#TODO Externalize this variable
export AETHOS_VERSION=0.0.12
mkisofs -o aethos-$AETHOS_VERSION-amd64.iso -b isolinux/isolinux.bin \
-c isolinux/boot.txt -no-emul-boot -boot-load-size 4 \
-boot-info-table CD_root
popd > /dev/null
}
mkinstall()
{
pushd /root/CD_root/install > /dev/null || return 1
# Create the bin and lib folder
rm -rf bin 2> /dev/null
mkdir -p bin 2> /dev/null
rm -rf lib 2> /dev/null
mkdir -p lib 2> /dev/null
# Copy the binaries and their dependencies
bins=(systemd bash nano grep awk xargs tar cat wget cfdisk fdisk mkfs mkswap mkdir mount swapon ifup ifdown ifconfig)
for f in "${bins[@]}"
do
file=`which ${f}`
echo "${file}"
cp ${file} bin
ldd ${file} | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' lib
done
# Initial install.sh
# This sets up networking
cat <<EOF > install.sh
#!/bin/ash
# Create the partition and file systems
#cfdisk
fdisk -l /dev/sda
echo "Press ENTER to continue if you created /dev/sda1 (boot) and /dev/sda5 (swap)"
echo ctrl-c aborts
read x
#mkfs -v -t ext4 /dev/sda1
#mkswap /dev/sda5
# Mount the new partitions
export AETHOS=/aethos
mkdir -pv $AETHOS
mount -v -t ext4 /dev/sda1 $AETHOS
swapon -v /dev/sda5
cd $AETHOS
echo Making directories
mkdir -p {bin,sbin,sys,dev,proc,etc,lib}
echo Make devices
mknod dev/console c 5 1
mknod dev/ram0 b 1 1
mknod dev/null c 1 3
mknod dev/tty1 c 4 1
mknod dev/tty2 c 4 2
mknod dev/sda b 8 0
mknod dev/sda1 b 8 1
mknod dev/sda2 b 8 2
mknod dev/sda3 b 8 3
mknod dev/sda4 b 8 4
mknod dev/sda5 b 8 5
mknod dev/sda6 b 8 6
mknod dev/sda7 b 8 7
mknod dev/sda8 b 8 8
mknod dev/sdb b 8 16
mknod dev/sdb1 b 8 17
mknod dev/sdb2 b 8 18
mknod dev/sdb3 b 8 19
mknod dev/sdb4 b 8 20
mknod dev/sdb5 b 8 21
mknod dev/sdb6 b 8 22
mknod dev/sdb7 b 8 23
mknod dev/sdb8 b 8 24
mknod dev/sr0 b 11 0
mknod dev/sr1 b 11 1
echo -n Networking must be started by now; if not, the following will fail
read x
wget https://raw.githubusercontent.com/aethosio/aethos-build-dist/master/install2.sh
./install2.sh
chmod a+x install2.sh
./install2.sh
EOF
# Second installation script
cat <<EOF > install2.sh
#!/bin/ash
echo Error downloading install2.sh from GitHub. Are you connected to the Internet?
EOF
popd > /dev/null
}
getBuildRoot()
{
pushd /root > /dev/null || return 1
git clone https://git.buildroot.net/buildroot
popd > /dev/null
cd /root/buildroot || return 1
#git checkout tags/2016.05-rc2
git checkout master
}
build()
{
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
folders=(target images host build staging graphs)
for f in "${folders[@]}"
do
mkdir -p ${BR2_OUTPUT}/${f} 2> /dev/null
done
mkdir -p /root/rootfs/${arch}/min/install
mkdir -p /root/rootfs/${arch}/full
pushd /root/buildroot > /dev/null || getBuildRoot
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} $build_target
if [ "$size" == "full" ] && [ "$build_target" == "all" ]
then
echo Copying the output file system to the min overlay file sytem
cp ${BR2_OUTPUT}/images/rootfs.tar.gz /root/rootfs/${arch}/min/install
cp /root/abd/install.sh /root/rootfs/${arch}/min/install
fi
popd > /dev/null
}
config()
{
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
pushd /root/buildroot > /dev/null || getBuildRoot
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} menuconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} savedefconfig BR2_DEFCONFIG=${BR2_EXTERNAL}/configs/aethos_${arch}_${size}_defconfig
popd > /dev/null
}
config_kernel()
{
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
pushd /root/buildroot > /dev/null || getBuildRoot
#make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} linux-menuconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} linux-update-defconfig
popd > /dev/null
}
configall()
{
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
pushd /root/buildroot > /dev/null || getBuildRoot
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} nconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} busybox-menuconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} linux-menuconfig
echo Building new defconfig and busybox configs
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} savedefconfig BR2_DEFCONFIG=${BR2_EXTERNAL}/configs/aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} busybox-update-config
popd > /dev/null
}
clean()
{
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
pushd /root/buildroot > /dev/null || getBuildRoot
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} clean all
#make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} golang-dirclean
popd > /dev/null
}
runMake()
{
target=$1
shift 1
export BR2_EXTERNAL=/root/abd/br2_external
export BR2_OUTPUT=/root/buildroot-${arch}-${size}-build
pushd /root/buildroot > /dev/null || getBuildRoot
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} aethos_${arch}_${size}_defconfig
make BR2_EXTERNAL=${BR2_EXTERNAL} O=${BR2_OUTPUT} ${target} $1 $2 $3
popd > /dev/null
}
usage()
{
cat <<EOF
$1 command
Available commands:
build Executes the Buildroot make
This builds the Linux Kernel as well as
all of the host and target packages.
config Configures the Buildroot system
This is where you would add target packages
kconfig Configures the Linux Kernel
This is where you make custom kernel tweaks
Note that config and kconfig will modify the aethos-build-dist
files, so make sure that you're working in your own personal fork of
this git project if you intend on saving the changes.
Deprecated commands (retained for reference):
initfs Creates the initfs in /root/initfs
mkiso Creates the iso of CD_root
mkinstall Create the installation script
all Executes all of the buid steps
Additional options:
-h|--help Displays this help
-x|--x86_64 Set the architecture to x86_64 (default)
-r|--rpi Set the architecture to arm/Raspberry Pi
-t|--tk1 Set the architecture to arm/NVidia TK1
-f|--full Set the size to be full (default)
-m|--min Set the size to be min
--target Used in conjunction with build command
Sets the target of the make command.
(default = all)
EOF
}
arch="x86_64"
size="full"
build_target="all"
# Verify the command was set.
if [ -z $1 ]; then
echo Command must be specified.
usage $(basename $0)
exit 1
fi
options=$(getopt -o hxrtfm -l help x86_64 rpi tk1 full min -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
cmd=$1
shift 1
while true
do
case "$1" in
-h|--help) usage $(basename $0) && exit 0;;
-x|--x86_64) shift 1; arch="x86_64";;
-r|--rpi) shift 1; arch="rpi";;
-t|--tk1) shift 1; arch="tk1";;
-f|--full) shift 1; size="full";;
-m|--min) shift 1; size="min";;
--target) shift 1; build_target=$1; shift 1;;
--) shift 1; break;;
*) break ;;
esac
done
# Process the command
case ${cmd} in
initfs) initfs; exit 0;;
mkiso) mkiso; exit 0;;
mkinstall) mkinstall; exit 0;;
all) initfs; mkiso; mkinstall; exit 0;;
build) build; exit 0;;
config) config; exit 0;;
kconfig) config_kernel; exit 0;;
clean) clean; exit 0;;
make) runMake; exit 0;;
goenv) export GOLANG_ENV=$(</root/GOLANG_ENV); export $(</root/GOLANG_ENV);;
*) echo Bad command && usage $0 && exit 0;;
esac