forked from ingmar-k/Allwinner_A10_Debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_functions.sh
1638 lines (1418 loc) · 52.1 KB
/
build_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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Bash script that creates a Debian rootfs or even a complete SD memory card for the Hackberry board
# Should run on current Debian or Ubuntu versions
# Author: Ingmar Klein ([email protected])
# Created in scope of the Master project, winter semester 2012/2013 under the direction of Professor Nik Klever, at the University of Applied Sciences Augsburg.
# This program (including documentation) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 (GPLv3; http://www.gnu.org/licenses/gpl-3.0.html ) for more details.
#####################################
##### MAIN Highlevel Functions: #####
#####################################
### Preparation ###
prep_output()
{
if [ ! -d ${output_dir_base}/cache ]
then
mkdir -p ${output_dir_base}/cache
fi
mkdir -p ${output_dir} # main directory for the build process
if [ "$?" = "0" ]
then
echo "Output directory '${output_dir}' successfully created."
else
echo "ERROR while trying to create the output directory '${output_dir}'. Exiting now!"
exit 5
fi
mkdir ${output_dir}/tmp # subdirectory for all downloaded or local temporary files
if [ "$?" = "0" ]
then
echo "Subfolder 'tmp' of output directory '${output_dir}' successfully created."
else
echo "ERROR while trying to create the 'tmp' subfolder '${output_dir}/tmp'. Exiting now!"
exit 6
fi
}
### Rootfs Creation ###
build_rootfs()
{
check_n_install_prerequisites # see if all needed packages are installed and if the versions are sufficient
create_n_mount_temp_image_file # create the image file that is then used for the rootfs
do_debootstrap # run debootstrap (first and second stage)
# disable_mnt_tmpfs # disable all entries in /etc/init.d trying to mount temporary filesystems (tmpfs), in order to save precious RAM
do_post_debootstrap_config # do some further system configuration
compress_debian_rootfs # compress the resulting rootfs
}
### SD-Card Creation ###
create_sd_card()
{
partition_n_format_disk # SD-card: make partitions and format
finalize_disk # copy the bootloader, rootfs and kernel to the SD-card
}
#######################################
##### MAIN lower level functions: #####
#######################################
# Description: Check if the user calling the script has the necessary priviliges
check_priviliges()
{
if [[ $UID -ne 0 ]]
then
echo "$0 must be run as root/superuser (su, sudo etc.)!
Please try again with the necessary priviliges."
exit 10
fi
}
# Description: Function to log and echo messages in terminal at the same time
fn_my_echo()
{
if [ -d ${output_dir} ]
then
echo "`date`: ${1}" >> ${output_dir}/log.txt
echo "${1}"
else
echo "Output directory '${output_dir}' doesn't exist. Exiting now!"
exit 11
fi
}
# Description: Function that checks if the needed internet connectivity is there.
check_connectivity()
{
fn_my_echo "Checking internet connectivity, which is mandatory for the next step."
for i in debian.org google.com kernel.org
do
ping -c 3 ${i}
if [ "$?" = "0" ]
then
fn_my_echo "Pinging '${i}' worked. Internet connectivity seems fine."
break
else
fn_my_echo "ERROR! Pinging '${i}' did NOT work. Internet connectivity seems bad or you are not connected.
Please check, if in doubt!"
if [ "${i}" = "kernel.org" ]
then
fn_my_echo "ERROR! All 3 ping attempts failed! You do not appear to be connected to the internet.
Exiting now!"
exit 97
else
continue
fi
fi
done
}
# Description: See if the needed packages are installed and if the versions are sufficient
check_n_install_prerequisites()
{
check_connectivity
fn_my_echo "Installing some packages, if needed."
if [ "${host_os}" = "Debian" ]
then
apt_prerequisites=${apt_prerequisites_debian}
elif [ "${host_os}" = "Ubuntu" ]
then
apt_prerequisites=${apt_prerequisites_ubuntu}
else
fn_my_echo "OS-Type '${host_os}' not correct.
Please run 'build_debian_system.sh --help' for more information"
exit 12
fi
set -- ${apt_prerequisites}
while [ $# -gt 0 ]
do
dpkg -l |grep "ii ${1}" >/dev/null
if [ "$?" = "0" ]
then
fn_my_echo "Package '${1}' is already installed. Nothing to be done."
else
fn_my_echo "Package '${1}' is not installed yet.
Trying to install it now!"
if [ ! "${apt_get_update_done}" = "true" ]
then
fn_my_echo "Running 'apt-get update' to get the latest package dependencies."
apt-get update
if [ "$?" = "0" ]
then
fn_my_echo "'apt-get update' ran successfully! Continuing..."
apt_get_update_done="true"
else
fn_my_echo "ERROR while trying to run 'apt-get update'. Exiting now."
exit 13
fi
fi
apt-get install -y ${1}
if [ "$?" = "0" ]
then
fn_my_echo "'${1}' installed successfully!"
else
fn_my_echo "ERROR while trying to install '${1}'."
if [ "${host_os}" = "Ubuntu" ] && [ "${1}" = "qemu-system" ]
then
fn_my_echo "Assuming that you are running this on Ubuntu 10.XX, where the package 'qemu-system' doesn't exist.
If your host system is not Ubuntu 10.XX based, this could lead to errors. Please check!"
else
fn_my_echo "Exiting now!"
exit 14
fi
fi
fi
if [ $1 = "qemu-user-static" ]
then
sh -c "dpkg -l|grep \"qemu-user-static\"|grep \"1.\"" >/dev/null
if [ $? = "0" ]
then
fn_my_echo "Sufficient version of package '${1}' found. Continueing..."
else
fn_my_echo "The installed version of package '${1}' is too old.
You need to install a package with a version of at least 1.0.
For example from the debian-testing ('http://packages.debian.org/search?keywords=qemu&searchon=names&suite=testing§ion=all')
respectively the Ubuntu precise ('http://packages.ubuntu.com/search?keywords=qemu&searchon=names&suite=precise§ion=all') repositiories.
Exiting now!"
exit 15
fi
fi
shift
done
fn_my_echo "Function 'check_n_install_prerequisites' DONE."
}
# Description: Create a image file as root-device for the installation process
create_n_mount_temp_image_file()
{
fn_my_echo "Creating the temporary image file for the debootstrap process."
dd if=/dev/zero of=${output_dir}/${output_filename}.img bs=1M count=${work_image_size_MB}
if [ "$?" = "0" ]
then
fn_my_echo "File '${output_dir}/${output_filename}.img' successfully created with a size of ${work_image_size_MB}MB."
else
fn_my_echo "ERROR while trying to create the file '${output_dir}/${output_filename}.img'. Exiting now!"
exit 16
fi
fn_my_echo "Formatting the image file with the ext4 filesystem."
mkfs.ext4 -F ${output_dir}/${output_filename}.img
if [ "$?" = "0" ]
then
fn_my_echo "ext4 filesystem successfully created on '${output_dir}/${output_filename}.img'."
else
fn_my_echo "ERROR while trying to create the ext4 filesystem on '${output_dir}/${output_filename}.img'. Exiting now!"
exit 17
fi
fn_my_echo "Creating the directory to mount the temporary filesystem."
mkdir -p ${qemu_mnt_dir}
if [ "$?" = "0" ]
then
fn_my_echo "Directory '${qemu_mnt_dir}' successfully created."
else
fn_my_echo "ERROR while trying to create the directory '${qemu_mnt_dir}'. Exiting now!"
exit 18
fi
fn_my_echo "Now mounting the temporary filesystem."
mount ${output_dir}/${output_filename}.img ${qemu_mnt_dir} -o loop
if [ "$?" = "0" ]
then
fn_my_echo "Filesystem correctly mounted on '${qemu_mnt_dir}'."
else
fn_my_echo "ERROR while trying to mount the filesystem on '${qemu_mnt_dir}'. Exiting now!"
exit 19
fi
fn_my_echo "Function 'create_n_mount_temp_image_file' DONE."
}
# Description: Run the debootstrap steps, like initial download, extraction plus configuration and setup
do_debootstrap()
{
check_connectivity
fn_my_echo "Running first stage of debootstrap now."
if [ "${use_cache}" = "yes" ]
then
if [ -d "${output_dir_base}/cache/" ]
then
if [ -e "${output_dir_base}/cache/${base_sys_cache_tarball}" ]
then
fn_my_echo "Using debian debootstrap tarball '${output_dir_base}/cache/${base_sys_cache_tarball}' from cache."
debootstrap --foreign --unpack-tarball="${output_dir_base}/cache/${base_sys_cache_tarball}" --include=${deb_add_packages} --verbose --arch=armhf --variant=minbase "${debian_target_version}" "${qemu_mnt_dir}/" "${debian_mirror_url}"
else
fn_my_echo "No debian debootstrap tarball found in cache. Creating one now!"
debootstrap --foreign --make-tarball="${output_dir_base}/cache/${base_sys_cache_tarball}" --include=${deb_add_packages} --verbose --arch=armhf --variant=minbase "${debian_target_version}" "${output_dir_base}/cache/tmp/" "${debian_mirror_url}"
sleep 3
debootstrap --foreign --unpack-tarball="${output_dir_base}/cache/${base_sys_cache_tarball}" --include=${deb_add_packages} --verbose --arch=armhf --variant=minbase "${debian_target_version}" "${qemu_mnt_dir}/" "${debian_mirror_url}"
fi
fi
else
fn_my_echo "Not using cache, according to the settings. Thus running debootstrap without creating a tarball."
debootstrap --include=${deb_add_packages} --verbose --arch armhf --variant=minbase --foreign "${debian_target_version}" "${qemu_mnt_dir}" "${debian_mirror_url}"
fi
modprobe binfmt_misc
cp /usr/bin/qemu-arm-static ${qemu_mnt_dir}/usr/bin
mkdir -p ${qemu_mnt_dir}/dev/pts
fn_my_echo "Mounting both /dev/pts and /proc on the temporary filesystem."
mount devpts ${qemu_mnt_dir}/dev/pts -t devpts
mount -t proc proc ${qemu_mnt_dir}/proc
fn_my_echo "Entering chroot environment NOW!"
apt_get_helper "write_script"
fn_my_echo "Starting the second stage of debootstrap now."
echo "#!/bin/bash
/debootstrap/debootstrap --second-stage 2>>/debootstrap_stg2_errors.txt
cd /root 2>>/debootstrap_stg2_errors.txt
cat <<END > /etc/apt/sources.list 2>>/debootstrap_stg2_errors.txt
deb ${debian_mirror_url} ${debian_target_version} ${debian_repositories}
deb-src ${debian_mirror_url} ${debian_target_version} ${debian_repositories}
END
if [ \"${debian_target_version}\" = \"stable\" ] || [ \"${debian_target_version}\" = \"wheezy\" ] || [ \"${debian_target_version}\" = \"testing\" ] || [ \"${debian_target_version}\" = \"jessie\" ]
then
cat <<END >>/etc/apt/sources.list 2>>/debootstrap_stg2_errors.txt
deb ${debian_mirror_url} ${debian_target_version}-updates ${debian_repositories}
deb-src ${debian_mirror_url} ${debian_target_version}-updates ${debian_repositories}
deb http://security.debian.org/ ${debian_target_version}/updates ${debian_repositories}
deb-src http://security.debian.org/ ${debian_target_version}/updates ${debian_repositories}
END
fi
apt-get update 2>>/debootstrap_stg2_errors.txt
mknod /dev/ttyS0 c 4 64 # for the serial console 2>>/debootstrap_stg2_errors.txt
mknod /dev/mmcblk0 b 179 0 2>>/debootstrap_stg2_errors.txt
#mknod /dev/mmcblk0p1 b 179 1 2>>/debootstrap_stg2_errors.txt
cat <<END > /etc/network/interfaces 2>>/debootstrap_stg2_errors.txt
#auto lo eth0
auto lo
iface lo inet loopback
iface eth0 inet dhcp
END
echo A10-debian > /etc/hostname 2>>/debootstrap_stg2_errors.txt
echo \"127.0.0.1 localhost\" >> /etc/hosts 2>>/debootstrap_stg2_errors.txt
echo \"127.0.0.1 A10-debian\" >> /etc/hosts 2>>/debootstrap_stg2_errors.txt
echo \"nameserver ${nameserver_addr}\" > /etc/resolv.conf 2>>/debootstrap_stg2_errors.txt
cat <<END > /etc/rc.local 2>>/debootstrap_stg2_errors.txt
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will exit 0 on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/post_debootstrap_setup.sh 2>>/post_debootstrap_setup_log.txt && rm /post_debootstrap_setup.sh
if [ -e /zram_setup.sh ]
then
/zram_setup.sh 2>>/zram_setup_log.txt && rm /zram_setup.sh
fi
exit 0
END
rm /debootstrap_pt1.sh
exit" > ${qemu_mnt_dir}/debootstrap_pt1.sh
chmod +x ${qemu_mnt_dir}/debootstrap_pt1.sh
/usr/sbin/chroot ${qemu_mnt_dir} /bin/bash /debootstrap_pt1.sh 2>${output_dir}/debootstrap_pt1_errors.txt
if [ "$?" = "0" ]
then
fn_my_echo "First part of chroot operations done successfully!"
else
fn_my_echo "Errors while trying to run the first part of the chroot operations."
fi
if [ "${use_cache}" = "yes" ]
then
if [ -e ${output_dir_base}/cache/additional_packages.tar.gz ]
then
if [ "${mali_graphics_choice}" = "none" ] #[ ! "${mali_graphics_choice}" = "copy" ] && [ ! "${mali_graphics_choice}" = "build" ]
then
fn_my_echo "Extracting the additional packages 'additional_packages.tar.gz' from cache. now."
tar_all extract "${output_dir_base}/cache/additional_packages.tar.gz" "${qemu_mnt_dir}/var/cache/apt/"
fi
elif [ ! -e "${output_dir}/cache/additional_packages.tar.gz" ]
then
add_pack_create="yes"
fi
if [ -e ${output_dir_base}/cache/additional_desktop_packages.tar.gz ] && [ "${mali_graphics_choice}" = "copy" ]
then
fn_my_echo "Extracting the additional desktop packages 'additional_desktop_packages.tar.gz' from cache. now."
tar_all extract "${output_dir_base}/cache/additional_desktop_packages.tar.gz" "${qemu_mnt_dir}/var/cache/apt/"
elif [ ! -e "${output_dir}/cache/additional_desktop_packages.tar.gz" ] && [ "${mali_graphics_choice}" = "build" ] #[ ! "${mali_graphics_choice}" = "copy" ]
then
add_desk_pack_create="yes"
fi
if [ -e ${output_dir_base}/cache/additional_dev_packages.tar.gz ] && [ "${mali_graphics_choice}" = "build" ]
then
fn_my_echo "Extracting the additional dev packages 'additional_dev_packages.tar.gz' from cache. now."
tar_all extract "${output_dir_base}/cache/additional_dev_packages.tar.gz" "${qemu_mnt_dir}/var/cache/apt/"
elif [ ! -e "${output_dir}/cache/additional_dev_packages.tar.gz" ] && [ "${mali_graphics_choice}" = "build" ]
then
add_dev_pack_create="yes"
fi
fi
mount devpts ${qemu_mnt_dir}/dev/pts -t devpts
mount -t proc proc ${qemu_mnt_dir}/proc
echo "#!/bin/bash
source apt_helper.sh
export LANG=C 2>>/debootstrap_stg2_errors.txt
for k in ${locale_list}
do
sed -i 's/# '\${k}'/'\${k}'/g' /etc/locale.gen # enable locale
done
locale-gen 2>>/debootstrap_stg2_errors.txt
export LANG=${std_locale} 2>>/debootstrap_stg2_errors.txt # language settings
export LC_ALL=${std_locale} 2>>/debootstrap_stg2_errors.txt
export LANGUAGE=${std_locale} 2>>/debootstrap_stg2_errors.txt
apt_get_helper \"download\" \"${additional_packages}\"
if [ \"${mali_graphics_choice}\" = \"copy\" ]
then
apt_get_helper \"download\" \"${additional_desktop_packages}\"
elif [ \"${mali_graphics_choice}\" = \"build\" ]
then
apt_get_helper \"download\" \"${additional_desktop_packages}\"
apt_get_helper \"download\" \"${additional_dev_packages}\"
fi
if [ \"${compile_accel_vlc}\" = \"yes\" ]
then
apt_get_helper \"dep_download\" \"vlc\"
fi
if [ \"${compile_accel_xbmc}\" = \"yes\" ]
then
apt_get_helper \"dep_download\" \"xbmc\"
apt_get_helper \"download\" \"${xbmc_prereq}\"
fi
dd if=/dev/zero of=/swapfile bs=1024 count=1048576 ### 512MB swapfile
mkswap /swapfile
chown root:root /swapfile
chmod 0600 /swapfile
cat <<END > /etc/fstab 2>>/debootstrap_stg2_errors.txt
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/root / ext4 noatime,errors=remount-ro 0 1
#/dev/mmcblk0p3 none swap defaults 0 0
/swapfile swap swap defaults 0 0
END
echo '#T0:2345:respawn:/sbin/mingetty ttyS0 115200 vt102' >> /etc/inittab 2>>/debootstrap_stg2_errors.txt # enable serial consoles
rm /debootstrap_pt2.sh
exit" > ${qemu_mnt_dir}/debootstrap_pt2.sh
chmod +x ${qemu_mnt_dir}/debootstrap_pt2.sh
/usr/sbin/chroot ${qemu_mnt_dir} /bin/bash /debootstrap_pt2.sh 2>${output_dir}/debootstrap_pt2_errors.txt
if [ "$?" = "0" ]
then
fn_my_echo "Second part of chroot operations done successfully!"
else
fn_my_echo "Errors while trying to run the second part of the chroot operations."
fi
#fn_my_echo "Debug: add_pack_create='${add_pack_create}' ."
#fn_my_echo "Debug: add_desk_pack_create='${add_desk_pack_create}' ."
#fn_my_echo "Debug: add_dev_pack_create='${add_dev_pack_create}' ."
#fn_my_echo "Debug: mali_graphics_choice='${mali_graphics_choice}' ."
if [ "${add_pack_create}" = "yes" ]
then
if [ "${mali_graphics_choice}" = "none" ] #[ ! "${mali_graphics_choice}" = "copy" ] && [ ! "${mali_graphics_choice}" = "build" ]
then
fn_my_echo "Compress choice 1. Only additional packages."
cd ${qemu_mnt_dir}/var/cache/apt/
tar_all compress "${output_dir_base}/cache/additional_packages.tar.gz" .
cd ${output_dir}
fi
fi
if [ "${add_dev_pack_create}" = "yes" ] && [ "${mali_graphics_choice}" = "build" ] # case of both desk- and dev-packages already downloaded into the /var/cache dir
then
fn_my_echo "Compress choice 2. Desktop and dev packages together (including additional packages)."
fn_my_echo "Trying to create cache archive for dev-packages (includes desktop-packages!)."
cd ${qemu_mnt_dir}/var/cache/apt/
tar_all compress "${output_dir_base}/cache/additional_dev_packages.tar.gz" .
cd ${output_dir}
fi
if [ "${add_desk_pack_create}" = "yes" ] && [ "${mali_graphics_choice}" = "copy" ] # case of only desk-packages already downloaded into the /var/cache dir
then
fn_my_echo "Compress choice 3. Desktop packages, including additional packages."
fn_my_echo "Trying to create cache archive for desktop-packages."
cd ${qemu_mnt_dir}/var/cache/apt/
tar_all compress "${output_dir_base}/cache/additional_desktop_packages.tar.gz" .
cd ${output_dir}
fi
sleep 5
umount_img sys
fn_my_echo "Just exited chroot environment."
fn_my_echo "Base debootstrap steps 1&2 are DONE!"
}
# Description: Do some further configuration of the system, after debootstrap has finished
do_post_debootstrap_config()
{
fn_my_echo "Now starting the post-debootstrap configuration steps."
mkdir -p ${output_dir}/qemu-kernel
get_n_check_file "${std_kernel_pkg}" "standard_kernel" "${output_dir}/tmp"
get_n_check_file "${qemu_kernel_pkg}" "qemu_kernel" "${output_dir}/tmp"
tar_all extract "${output_dir}/tmp/${qemu_kernel_pkg##*/}" "${output_dir}/qemu-kernel"
sleep 3
tar_all extract "${output_dir}/tmp/${std_kernel_pkg##*/}" "${qemu_mnt_dir}"
if [ -d ${output_dir}/qemu-kernel/lib/ ]
then
cp -ar ${output_dir}/qemu-kernel/lib/ ${qemu_mnt_dir} # copy the qemu kernel modules intot the rootfs
fi
if [ "${use_zram}" = "yes" ]
then
fn_my_echo "Usage of ZRAM activated!"
echo "#!/bin/sh
mv /etc/rc.local /etc/rc.local.bak
cat <<END > /etc/rc.local 2>>/zram_setup_errors.txt
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will exit 0 on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
modprobe ${zram_kernel_module_name} num_devices=1
sleep 2
echo ${zram_size_B} > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon -p 100 /dev/zram0
if [ -e /dev/ump ]
then
chmod 777 /dev/ump
fi
if [ -e /dev/mali ]
then
chmod 777 /dev/mali
fi
chmod 777 /dev/disp
chmod 777 /dev/cedar_dev
echo 0 > /sys/class/graphics/fb0/blank # disable framebuffer blanking
echo 0 > /sys/module/8192cu/parameters/rtw_power_mgnt # disable wlan power management
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # set cpufreq governor to 'ondemand'
exit 0
END
chmod +x /etc/rc.local
exit 0" > ${qemu_mnt_dir}/zram_setup.sh
#cp ${qemu_mnt_dir}/zram_setup.sh ${qemu_mnt_dir}/zram_setup.sh.bak
chmod +x ${qemu_mnt_dir}/zram_setup.sh
fi
git_branch_name="${mali_xserver_2d_git##*.git -b }"
if [ ! -z "${git_branch_name}" ]
then
xf86_version="${git_branch_name:0:4}"
#fn_my_echo "DEBUG: xf86_version='${xf86_version}' ."
else
xf86_version="r3p0" # default value
#fn_my_echo "DEBUG: xf86_version='${xf86_version}' ."
fi
date_cur=`date` # needed further down as a very important part to circumvent the PAM Day0 change password problem
echo "#!/bin/bash
source apt_helper.sh
date -s \"${date_cur}\" 2>>/post_debootstrap_errors.txt # set the system date to prevent PAM from exhibiting its nasty DAY0 forced password change
apt_get_helper \"install\" \"${additional_packages}\"
if [ \"${mali_graphics_choice}\" = \"copy\" ]
then
apt_get_helper \"install\" \"${additional_desktop_packages}\"
elif [ \"${mali_graphics_choice}\" = \"build\" ]
then
apt_get_helper \"install\" \"${additional_desktop_packages}\"
apt_get_helper \"install\" \"${additional_dev_packages}\"
fi
if [ \"${compile_accel_vlc}\" = \"yes\" ]
then
apt-get remove -y vlc vlc-data
apt_get_helper \"dep_install\" \"vlc\"
apt-get remove -y lua5.2
fi
if [ \"${compile_accel_xbmc}\" = \"yes\" ]
then
apt-get remove -y xbmc xbmc-data xbmc-bin
apt_get_helper \"dep_install\" \"xbmc\"
apt_get_helper \"install\" \"${xbmc_prereq}\"
apt-get remove -y ${xbmc_nogos}
fi
#apt-get autoremove
apt-get clean
dpkg -l > /installed_packages.txt
ldconfig -v
if [ \"${i2c_hwclock}\" = \"yes\" ]; then update-rc.d -f i2c_hwclock.sh start 02 S . stop 07 0 6 . 2>>/post_debootstrap_errors.txt;fi;
if [ \"${use_zram}\" = \"yes\" ]; then echo vm.swappiness=${vm_swappiness} >> /etc/sysctl.conf; fi;
if [ ! -z `grep setup.sh /etc/rc.local` ]
then
cat <<END > /etc/rc.local 2>>/post_debootstrap_errors.txt
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will exit 0 on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
END
fi
sh -c \"echo '${root_password}
${root_password}
' | passwd root\" 2>>/post_debootstrap_errors.txt
passwd -u root 2>>/post_debootstrap_errors.txt
passwd -x -1 root 2>>/post_debootstrap_errors.txt
passwd -w -1 root 2>>/post_debootstrap_errors.txt
sh -c \"echo '${user_password}
${user_password}
' | adduser ${username}\" 2>>/post_debootstrap_errors.txt
if [ \"${mali_graphics_choice}\" = \"copy\" -o \"${mali_graphics_choice}\" = \"build\" ]
then
echo \"Writing '/etc/modules' and '/etc/X11/xorg.conf' for mali graphics usage.\"
cat << END >> /etc/modules
8192cu
lcd
hdmi
ump
disp
mali
mali_drm
END
if [ \"${mali_graphics_choice}\" = \"copy\" ]
then
echo \"Downloaded mali graphics driver. Driver should already work. Please check!\"
elif [ \"${mali_graphics_choice}\" = \"build\" ]
then
echo \"Downloaded sources for mali graphics. Trying to compile the driver, now.\"
cd /root/mali_2d_build 2>>/mali_drv_compile.txt
if [ \"\${?}\" = \"0\" ]
then
echo \"Successfully changed into directory '/root/mali_2d_build'.\"
cd /root/mali_2d_build/libdri2 2>>/mali_drv_compile.txt
if [ \"\${?}\" = \"0\" ]
then
echo \"Successfully changed into directory '/root/mali_2d_build/libdri2/'.\"
./autogen.sh 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 3\" && echo \"Successfully ran the 'autogen.sh' (libdri2) command.\"
./configure --prefix=/usr --x-includes=/usr/include --x-libraries=/usr/lib 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 4\" && echo \"Successfully ran the configuration for libdri2.\"
make 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 5\" && echo \"Successfully ran the 'make' (libdri2) command.\"
make install 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 6\" && echo \"Successfully ran the 'make install' (libdri2) command.\"
fi
cd /root/mali_2d_build/sunxi-mali 2>>/mali_drv_compile.txt
if [ \"\${?}\" = \"0\" ]
then
echo \"Changed directory to 'sunxi-mali'.\"
make config VERSION=${mali_module_version} ABI=armhf EGL_TYPE=x11
make
make install 2>>/mali_drv_compile.txt && echo \"Successfully ran the 'make install' (sunxi-mali) command.\"
#cp -f ./xorg.conf /etc/X11/ && echo \"Successfully copied the 'xorg.conf' (xf86-video-mali).\"
cd lib/sunxi-mali-proprietary
make VERSION=${mali_module_version} ABI=armhf EGL_TYPE=x11
make install
cd ../../test
make test
fi
cd /root/mali_2d_build/xf86-video-mali 2>>/mali_drv_compile.txt
if [ \"\${?}\" = \"0\" ]
then
echo \"Changed directory to 'xf86-video-mali'.\"
autoreconf -vi 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 8\" && echo \"Successfully ran autoreconf.\"
./configure --prefix=/usr --x-includes=/usr/include --x-libraries=/usr/lib 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 9\" && echo \"Successfully ran the configuration for the xf86 driver.\"
make 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 10\" && echo \"Successfully ran the 'make' (xf86-video-mali) command.\"
make install 2>>/mali_drv_compile.txt && xserver_build_log=\"$xserver_build_log 11\" && echo \"Successfully ran the 'make install' (xf86-video-mali) command.\"
cp -f ./xorg.conf /etc/X11/xorg.conf && echo \"Successfully copied the 'xorg.conf' (xf86-video-mali).\"
fi
else
echo \"ERROR: Couldn't change into directory '/root/mali_2d_build/'!\" >>/post_debootstrap_errors.txt
fi
if [ \"xserver_build_log\" = \"1 2 3 4 5 6 7 8 9 10 11\" ]
then
echo \"Xserver mali400 driver build process completed successfully!\"
echo \"Xserver mali400 driver build process completed successfully!\" >> /mali_drv_compile.txt
fi
cat <<END > /etc/rc.local 2>>/debootstrap_stg2_errors.txt
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will exit 0 on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
if [ -e /zram_setup.sh ]
then
/zram_setup.sh 2>>/zram_setup_error.txt && rm /zram_setup.sh
fi
if [ -e /dev/ump ]
then
chmod 777 /dev/ump
fi
if [ -e /dev/mali ]
then
chmod 777 /dev/mali
fi
echo 0 > /sys/class/graphics/fb0/blank # disable framebuffer blanking
echo 0 > /sys/module/8192cu/parameters/rtw_power_mgnt # disable wlan power management
echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor # set cpufreq governor to 'ondemand'
exit 0
END
fi
elif [ \"${mali_graphics_choice}\" = \"none\" ]
then
echo \"No graphics driver and no graphical user interface wanted.\"
else
echo \"No valid option. Only copy|build|none are accepted. Doing nothing.\"
fi
if [ \"${compile_accel_vlc}\" = \"yes\" ]
then
if [ -d /root/libcedarx ]
then
cd /root/libcedarx 2>>/vlc_compile_errors.txt
./autogen.sh 2>>/vlc_compile_errors.txt && echo \"Successfully ran libcedarx autogen.sh.\" >>/vlc_compile.txt
./configure --host=arm-linux-gnueabihf --prefix=/usr 2>>/vlc_compile_errors.txt && echo \"Successfully ran libcedarx configure.\" >>/vlc_compile.txt
make 2>>/vlc_compile_errors.txt && echo \"Successfully ran libcedarx make.\" >>/vlc_compile.txt
make install 2>>/vlc_compile_errors.txt && echo \"Successfully ran libcedarx make install.\" >>/vlc_compile.txt
if [ -d /root/vlc ]
then
cd /root/vlc 2>>/vlc_compile_errors.txt
./bootstrap 2>>/vlc_compile_errors.txt && echo \"Successfully ran vlc bootstrap.\" >>/vlc_compile.txt
./configure --host=arm-linux-gnueabihf --prefix=/usr --enable-cedar 2>>/vlc_compile_errors.txt && echo \"Successfully ran vlc configure.\" >>/vlc_compile.txt
make 2>>/vlc_compile_errors.txt && echo \"Successfully ran vlc make.\" >>/vlc_compile.txt
make install 2>>/vlc_compile_errors.txt && echo \"Successfully ran vlc make install.\" >>/vlc_compile.txt
else
echo \"ERROR! Directory '/root/vlc' not found! Please check!\" >>/vlc_compile_errors.txt
fi
else
echo \"ERROR! Directory '/root/libcedarx' not found! Please check!\" >>/vlc_compile_errors.txt
fi
fi
if [ \"${compile_accel_xbmc}\" = \"yes\" ]
then
if [ -d /root/xbmca10/tools/a10/depends ]
then
cd /root/xbmca10/tools/a10/depends 2>>/xbmc_compile_errors.txt
sed -i 's<mkdir<mkdir -p<g' /root/xbmca10/tools/a10/depends/Makefile 2>>/xbmc_compile_errors.txt
mkdir -p /opt/a10hacking/xbmctmp/tarballs 2>>/xbmc_compile_errors.txt
make 2>>/xbmc_compile_errors.txt && echo \"Successfully ran xbmc-depends make.\" >>/xbmc_compile.txt
echo -e \"\nA10HWR=1\" >> /etc/environment 2>>/xbmc_compile_errors.txt
echo -e \"\nexport A10HWR=1\" >> /home/${username}/.bashrc 2>>/xbmc_compile_errors.txt
make -C xbmc 2>>/xbmc_compile_errors.txt && echo \"Successfully ran xbmc make.\" >>/xbmc_compile.txt
cd /root/xbmca10/ 2>>/xbmc_compile_errors.txt
make install 2>>/xbmc_compile_errors.txt && echo \"Successfully ran xbmc make install.\" >>/xbmc_compile.txt
else
echo \"ERROR! Directory '/root/xbmca10' not found! Please check!\" >>/xbmc_compile_errors.txt
fi
fi
ldconfig -v
if [ -e /apt_helper.sh ]
then
rm /apt_helper.sh
fi
sed -i 's<#/dev/mmcblk0p3</dev/mmcblk0p3<g' /etc/fstab
sed -i 's</swapfile<#&<g' /etc/fstab
sed -i 's<#T0:2345:respawn:/sbin/mingetty<T0:2345:respawn:/sbin/mingetty<g' /etc/inittab
df -ah >> /disk_usage.txt
reboot 2>>/post_debootstrap_errors.txt
exit 0" > ${qemu_mnt_dir}/post_debootstrap_setup.sh
chmod +x ${qemu_mnt_dir}/post_debootstrap_setup.sh
if [ "${mali_graphics_opengl}" = "yes" ]
then
get_n_check_file "${mali_opengl_bin}" "mali_opengl_driver" "${output_dir}/tmp"
tar_all extract "${output_dir}/tmp/${mali_opengl_bin##*/}" "${qemu_mnt_dir}"
fi
if [ "${mali_graphics_choice}" = "copy" ]
then
get_n_check_file "${mali_2d_bin}" "mali_2d_driver" "${output_dir}/tmp"
tar_all extract "${output_dir}/tmp/${mali_2d_bin##*/}" "${qemu_mnt_dir}"
elif [ "${mali_graphics_choice}" = "build" ]
then
mkdir -p ${qemu_mnt_dir}/root/mali_2d_build && fn_my_echo "Directory for graphics driver build successfully created."
get_n_check_file "${mali_xserver_2d_git}" "xf86-video-mali" "${qemu_mnt_dir}/root/mali_2d_build"
get_n_check_file "${mali_2d_libdri2_git}" "libdri2" "${qemu_mnt_dir}/root/mali_2d_build"
get_n_check_file "${mali_2d_mali_git}" "mali" "${qemu_mnt_dir}/root/mali_2d_build"
cd ${qemu_mnt_dir}/root/mali_2d_build/sunxi-mali
git submodule init
git submodule update
get_n_check_file "${mali_2d_proprietary_git}" "mali-proprietary" "${qemu_mnt_dir}/root/mali_2d_build/sunxi-mali/lib/"
fi
if [ "${compile_accel_vlc}" = "yes" ]
then
if [ "${use_cache}" = "yes" ]
then
if [ -d "${output_dir_base}/cache/" ]
then
### libcedarx first
if [ -e "${output_dir_base}/cache/${libcedarx_git_tarball}" ]
then
fn_my_echo "Using libcedarx_git tarball '${output_dir_base}/cache/${libcedarx_git_tarball}' from cache."
tar_all extract "${output_dir_base}/cache/${libcedarx_git_tarball}" "${qemu_mnt_dir}/root/"
else
fn_my_echo "No libcedarx git tarball found in cache. Creating one now!"
get_n_check_file "${libcedarx_git}" "libcedarx" "${qemu_mnt_dir}/root/"
if [ "$?" = "0" ]
then
cd ${qemu_mnt_dir}/root/
tar_all compress "${output_dir_base}/cache/${libcedarx_git_tarball}" ./libcedarx
else
fn_my_echo "ERROR! Something seems to have gone wrong while trying to get 'libcedarx' via git."
fi
fi
### then VLC
if [ -e "${output_dir_base}/cache/${vlc_git_tarball}" ]
then
fn_my_echo "Using vlc_git tarball '${output_dir_base}/cache/${vlc_git_tarball}' from cache."
tar_all extract "${output_dir_base}/cache/${vlc_git_tarball}" "${qemu_mnt_dir}/root/"
else
fn_my_echo "No vlc_git tarball found in cache. Creating one now!"
get_n_check_file "${vlc_git}" "vlc" "${qemu_mnt_dir}/root/"
if [ "$?" = "0" ]
then
cd ${qemu_mnt_dir}/root/
tar_all compress "${output_dir_base}/cache/${vlc_git_tarball}" ./vlc
else
fn_my_echo "ERROR! Something seems to have gone wrong while trying to get 'vlc' via git."
fi
fi
else
fn_my_echo "ERROR! Cache directory '${output_dir_base}/cache/' does not seem to exist. Please check
Exiting now!"
exit 98
fi
else
fn_my_echo "Not using cache, according to the settings. Thus running git clone without creating a tarball."
get_n_check_file "${libcedarx_git}" "libcedarx" "${qemu_mnt_dir}/root/"
get_n_check_file "${vlc_git}" "vlc" "${qemu_mnt_dir}/root/"
fi
fi
if [ "${compile_accel_xbmc}" = "yes" ]
then
if [ "${use_cache}" = "yes" ]
then
if [ -d "${output_dir_base}/cache/" ]
then
### XBMC
if [ -e "${output_dir_base}/cache/${xbmc_git_tarball}" ]
then
fn_my_echo "Using xbmc_git tarball '${output_dir_base}/cache/${xbmc_git_tarball}' from cache."
tar_all extract "${output_dir_base}/cache/${xbmc_git_tarball}" "${qemu_mnt_dir}/root/"
else
fn_my_echo "No xbmc git tarball found in cache. Creating one now!"
get_n_check_file "${xbmc_git}" "xbmc" "${qemu_mnt_dir}/root/"
if [ "$?" = "0" ]
then
cd ${qemu_mnt_dir}/root/
tar_all compress "${output_dir_base}/cache/${xbmc_git_tarball}" ./xbmca10
else
fn_my_echo "ERROR! Something seems to have gone wrong while trying to get 'xbmc' via git."
fi
fi
else
fn_my_echo "ERROR! Cache directory '${output_dir_base}/cache/' does not seem to exist. Please check
Exiting now!"
exit 99
fi
else
fn_my_echo "Not using cache, according to the settings. Thus running git clone without creating a tarball."
get_n_check_file "${xbmc_git}" "xbmc" "${qemu_mnt_dir}/root/"
fi
fi
sleep 3
umount_img all
if [ "$?" = "0" ]
then
fn_my_echo "Filesystem image file successfully unmounted. Ready to continue."
else
fn_my_echo "Error while trying to unmount the filesystem image. Exiting now!"
exit 22
fi
sleep 5
mount |grep "${qemu_mnt_dir}" > /dev/null
if [ ! "$?" = "0" ]
then
fn_my_echo "Starting the qemu environment now!"
##qemu-system-arm -M versatilepb -cpu cortex-a8 -no-reboot -kernel ${output_dir}/qemu-kernel/vmlinuz -hda ${output_dir}/${output_filename}.img -m 256 -append "root=/dev/sda rootfstype=ext4 mem=256M devtmpfs.mount=0 rw ip=dhcp" 2>qemu_error_log.txt # TODO: Image name
qemu-system-arm -M realview-pb-a8 -cpu cortex-a8 -no-reboot -serial stdio -kernel ${output_dir}/qemu-kernel/zImage -drive file=${output_dir}/${output_filename}.img,if=sd,cache=writeback -m 512 -append "root=/dev/mmcblk0 rw rootfstype=ext4 mem=512M devtmpfs.mount=0 ip=dhcp" 2>qemu_error_log.txt # TODO: Image name
else
fn_my_echo "ERROR! Filesystem is still mounted. Can't run qemu!"
exit 23
fi
fn_my_echo "Additional chroot system configuration successfully finished!"
}
# Description: Compress the resulting rootfs
compress_debian_rootfs()
{
fn_my_echo "Compressing the rootfs now!"
mount |grep ${output_dir}/${output_filename}.img 2>/dev/null
if [ ! "$?" = "0" ]
then
fsck.ext4 -fy ${output_dir}/${output_filename}.img
if [ "$?" = "0" ]
then
fn_my_echo "Temporary filesystem checked out, OK!"