-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathcustompios
executable file
·216 lines (177 loc) · 7.14 KB
/
custompios
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
#!/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
set -e
export LC_ALL=C
source "${CUSTOM_PI_OS_PATH}"/common.sh
echo_green -e "\nBUILD STARTED @ $(date)!\n"
function execute_chroot_script() {
# In docker, these extra commands are required to enable this black-magic
if [ -f /.dockerenv ] && [ "$(uname -m)" != "armv7l" ] && [ "$(uname -m)" != "aarch64" ] ; then
if [ "$BASE_ARCH" == "armv7l" ] || [ "$BASE_ARCH" == "armhf" ]; then
update-binfmts --enable qemu-arm
elif [ "$BASE_ARCH" == "aarch64" ] || [ "$BASE_ARCH" == "arm64" ]; then
update-binfmts --enable qemu-aarch64
fi
if ! mount | grep -q "/proc/sys/fs/binfmt_misc"; then
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc || true
fi
fi
#move filesystem files
if [ -d "$1/filesystem" ]; then
cp -vr --preserve=mode,timestamps "$1/filesystem" .
fi
#black magic of qemu-arm-static
# cp `which qemu-arm-static` usr/bin
if [ "$(uname -m)" != "armv7l" ] || [ "$(uname -m)" != "aarch64" ] ; then
if [ "$BASE_ARCH" == "armv7l" ] || [ "$BASE_ARCH" == "armhf" ]; then
if (grep -q gentoo /etc/os-release);then
ROOT="`realpath .`" emerge --usepkgonly --oneshot --nodeps qemu
else
cp `which qemu-arm-static` usr/bin/qemu-arm-static
fi
elif [ "$BASE_ARCH" == "aarch64" ] || [ "$BASE_ARCH" == "arm64" ]; then
if (grep -q gentoo /etc/os-release);then
ROOT="`realpath .`" emerge --usepkgonly --oneshot --nodeps qemu
else
cp `which qemu-aarch64-static` usr/bin/qemu-aarch64-static
fi
fi
fi
cp $2 chroot_script
chmod 755 chroot_script
cp "${CUSTOM_PI_OS_PATH}"/common.sh common.sh
chmod 755 common.sh
chroot_correct_qemu "$(uname -m)" "$BASE_ARCH" "$2" "${CUSTOM_PI_OS_PATH}"
# Handle exported items
if [ -d "custompios_export" ]; then
echo "Exporting files from chroot"
echo "List of archies to create:"
ls custompios_export
# Tar files listed in export
for export_list in custompios_export/* ; do
tar --absolute-names -czvf "${BASE_WORKSPACE}/$(basename ${export_list}).tar.gz" -T ${export_list}
done
rm -rf custompios_export
fi
#cleanup
rm chroot_script
if [ -d "filesystem" ]; then
rm -rfv "filesystem"
fi
}
# check prerequisites
if [ -n "$BASE_IMAGE_ENLARGEROOT" ] || [ -n "$BASE_IMAGE_RESIZEROOT" ]; then
# resizing the root partition requires 'sfdisk' in our path
which sfdisk >/dev/null 2>/dev/null || \
die "'sfdisk' not found in PATH; did you mean to run the script as root?"
fi
# start!
mkdir -p $BASE_WORKSPACE
mkdir -p $BASE_MOUNT_PATH
# This is already genrated at "build" sourced in "config", but copying here mostly for debug
if [ -f "${EXTRA_BAORD_CONFIG}" ]; then
mv -v "${EXTRA_BAORD_CONFIG}" "${BASE_WORKSPACE}"/extra_board_config
fi
# Clean exported artifacts from other builds
rm -rf "${BASE_WORKSPACE}"/*.tar.gz
install_cleanup_trap
install_fail_on_error_trap
unmount_image $BASE_MOUNT_PATH force || true
pushd "${BASE_WORKSPACE}"
if [ -e *.img ]; then
rm *.img
fi
if [ ! -f "$BASE_ZIP_IMG" ] || [ "$BASE_ZIP_IMG" == "" ]; then
echo "Error: could not find image: $BASE_ZIP_IMG"
echo "On CustomPiOS v2 you can provide -d to download the latest image of your board automatically"
exit 1
fi
if [[ $BASE_ZIP_IMG =~ \.img$ ]]; then
# if the image is already extracted copy over
cp "$BASE_ZIP_IMG" .
else
7za x -aoa "$BASE_ZIP_IMG"
fi
BASE_IMG_PATH=`ls | grep '.img$\|.raw$' | head -n 1`
if [ ! -f "$BASE_IMG_PATH" ]; then
echo "Error, can't find image path, did you place an image in the image folder?"
exit 1
fi
export CUSTOM_PI_OS_BUILDBASE=$(basename "$BASE_IMG_PATH")
if [ -n "$BASE_IMAGE_ENLARGEROOT" ]
then
# make our image a bit larger so we don't run into size problems...
enlarge_ext $BASE_IMG_PATH $BASE_ROOT_PARTITION $BASE_IMAGE_ENLARGEROOT
fi
# mount root and boot partition
mount_image "${BASE_IMG_PATH}" "${BASE_ROOT_PARTITION}" "${BASE_MOUNT_PATH}" "${BASE_BOOT_MOUNT_PATH}" "${BASE_BOOT_PARTITION}"
if [ -n "$BASE_APT_CACHE" ] && [ "$BASE_APT_CACHE" != "no" ]
then
mkdir -p "$BASE_APT_CACHE"
mount --bind "$BASE_APT_CACHE" $BASE_MOUNT_PATH/var/cache/apt
fi
#Edit pi filesystem
pushd $BASE_MOUNT_PATH
#make QEMU boot (remember to return)
if [ "$BASE_IMAGE_RASPBIAN" == "yes" ]; then
fixLd
fi
#sed -i 's@include /etc/ld.so.conf.d/\*.conf@\#include /etc/ld.so.conf.d/\*.conf@' etc/ld.so.conf
### Execute chroot scripts ###
# if an additional pre-script is defined, execute that now
if [ -n "$BASE_PRESCRIPT" ] && [ -f $BASE_PRESCRIPT/chroot_script ]; then
echo "Injecting environment pre script from $BASE_PRESCRIPT..."
execute_chroot_script $BASE_PRESCRIPT $BASE_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 $BASE_SCRIPT_PATH $BASE_CHROOT_SCRIPT_PATH
CHROOT_SCRIPT=${BASE_WORKSPACE}/chroot_script
MODULES_AFTER_PATH=${BASE_WORKSPACE}/modules_after
MODULES_BEFORE="${MODULES}"
${CUSTOM_PI_OS_PATH}/custompios_core/execution_order.py "${MODULES}" "${CHROOT_SCRIPT}" "${MODULES_AFTER_PATH}" "${REMOTE_AND_META_CONFIG}"
if [ -f "${REMOTE_AND_META_CONFIG}" ]; then
echo "Sourcing remote and submodules config"
source "${REMOTE_AND_META_CONFIG}" ${@}
MODULES_AFTER=$(cat "${MODULES_AFTER_PATH}")
load_module_config "${MODULES_AFTER}"
else
echo "No remote and submodules config detected"
fi
echo $ARMBIAN_CONFIG_TXT_FILE
# if you need anything from common running in execute_chroot_script, export it here
export -f chroot_correct_qemu
export -f execute_chroot_script
bash -x "${CHROOT_SCRIPT}"
# 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 "$BASE_POSTSCRIPT" ] && [ -f $BASE_POSTSCRIPT/chroot_script ]; then
echo "Injecting environment post script from $BASE_POSTSCRIPT..."
execute_chroot_script $BASE_POSTSCRIPT $BASE_POSTSCRIPT/chroot_script
fi
### End Execute chroot scripts ###
if [ "$BASE_IMAGE_RASPBIAN" == "yes" ]; then
restoreLd
fi
popd
# unmount first boot, then root partition
unmount_image $BASE_MOUNT_PATH
chmod 644 $BASE_IMG_PATH
if [ -n "$BASE_IMAGE_RESIZEROOT" ]
then
# resize image to minimal size + provided size
minimize_ext $BASE_IMG_PATH $BASE_ROOT_PARTITION $BASE_IMAGE_RESIZEROOT
fi
popd
echo_green -e "\nBUILD SUCCEEDED @ $(date)!\n"