-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathoctopi
executable file
·104 lines (82 loc) · 3.16 KB
/
octopi
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
#!/usr/bin/env bash
# OctoPi generation script
# This script takes a Raspbian image and adds to it octoprint and verions addons
# Written by Guy Sheffer <guysoft at gmail dot com>
# GPL V3
source $OCTOPI_SCRIPT_PATH/common.sh
function execute_chroot_script() {
#move OctoPi filesystem files
cp -vr --preserve=mode,timestamps $1/filesystem .
#black magic of qemu-arm-static
cp `which qemu-arm-static` usr/bin
cp $2 chroot_script
chmod 755 chroot_script
cp $OCTOPI_SCRIPT_PATH/common.sh common.sh
chmod 755 common.sh
chroot . usr/bin/qemu-arm-static /bin/bash /chroot_script
#cleanup
rm chroot_script
rm -rfv filesystem
}
mkdir -p $OCTOPI_WORKSPACE
mkdir -p $OCTOPI_MOUNT_PATH
install_cleanup_trap
install_fail_on_error_trap $OCTOPI_MOUNT_PATH
unmount_image $OCTOPI_MOUNT_PATH force || true
pushd $OCTOPI_WORKSPACE
if [ -e *.img ]; then
rm *.img
fi
unzip $OCTOPI_ZIP_IMG
OCTOPI_IMG_PATH=`ls | grep .img`
export OCTOPI_BUILDBASE=$(basename $OCTOPI_IMG_PATH)
if [ -n "$OCTOPI_IMAGE_ENLARGEROOT" ]
then
# make our image a bit larger so we don't run into size problems...
enlarge_ext $OCTOPI_IMG_PATH 2 $OCTOPI_IMAGE_ENLARGEROOT
fi
# mount root and boot partition
mount_image $OCTOPI_IMG_PATH $OCTOPI_MOUNT_PATH
if [ -n "$OCTOPI_APT_CACHE" ]
then
mkdir -p "$OCTOPI_APT_CACHE"
mount --bind "$OCTOPI_APT_CACHE" $OCTOPI_MOUNT_PATH/var/cache/apt
fi
#Edit pi filesystem
pushd $OCTOPI_MOUNT_PATH
#make QEMU boot (remember to return)
fixLd
#sed -i 's@include /etc/ld.so.conf.d/\*.conf@\#include /etc/ld.so.conf.d/\*.conf@' etc/ld.so.conf
# if an additional pre-script is defined, execute that now
if [ -n "$OCTOPI_PRESCRIPT" ] && [ -f $OCTOPI_PRESCRIPT/chroot_script ]; then
echo "Injecting environment pre script from $OCTOPI_PRESCRIPT..."
execute_chroot_script $OCTOPI_PRESCRIPT $OCTOPI_PRESCRIPT/chroot_script
fi
# if building a variant, execute its pre-chroot script
if [ -n "$VARIANT_BASE" ] && [ -f $VARIANT_BASE/pre_chroot_script ]; then
echo "Injecting variant pre script from $VARIANT_BASE..."
execute_chroot_script $VARIANT_BASE $VARIANT_BASE/pre_chroot_script
fi
# execute the base chroot script
execute_chroot_script $OCTOPI_SCRIPT_PATH $OCTOPI_CHROOT_SCRIPT_PATH
# if building a variant, execute its post-chroot script
if [ -n "$VARIANT_BASE" ] && [ -f $VARIANT_BASE/post_chroot_script ]; then
echo "Injecting variant post script from $VARIANT_BASE..."
execute_chroot_script $VARIANT_BASE $VARIANT_BASE/post_chroot_script
fi
# if an additional post-script is defined, execute that now
if [ -n "$OCTOPI_POSTSCRIPT" ] && [ -f $OCTOPI_POSTSCRIPT/chroot_script ]; then
echo "Injecting environment post script from $OCTOPI_POSTSCRIPT..."
execute_chroot_script $OCTOPI_POSTSCRIPT $OCTOPI_POSTSCRIPT/chroot_script
fi
restoreLd
popd
# unmount first boot, then root partition
unmount_image $OCTOPI_MOUNT_PATH
chmod 777 $OCTOPI_IMG_PATH
if [ -n "$OCTOPI_IMAGE_RESIZEROOT" ]
then
# resize image to minimal size + provided size
minimize_ext $OCTOPI_IMG_PATH 2 $OCTOPI_IMAGE_RESIZEROOT
fi
popd