-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
124 lines (118 loc) · 4.03 KB
/
build.sh
File metadata and controls
124 lines (118 loc) · 4.03 KB
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
#!/usr/bin/bash
ALL_BUILD_TARGETS=()
DO_CLEAN_FIRST=0
DO_RUN_AFTER=0
BUNDLE_PUBLIC=0
BUNDLE_INTERNAL=0
# Parse all arguments
while [[ $# -gt 0 ]]; do
case $1 in
--help|-h)
echo "Usage: $0 [--help|-h]"
echo "This script sets up the environment for building artifacts."
exit 0
;;
"--clean")
echo "Will clean the build directories first."
DO_CLEAN_FIRST=1
;;
"--run")
echo "Will run the build after setup."
DO_RUN_AFTER=1
;;
"--bundle-internal")
echo "Will bundle the container for testing - THE RESULTING IMAGE MUST NOT BE SHARED!"
BUNDLE_INTERNAL=1
;;
"--bundle-external")
echo "Will bundle the container for external use - the image can be made public"
BUNDLE_PUBLIC=1
;;
"native")
ALL_BUILD_TARGETS+=("native")
;;
"docker")
ALL_BUILD_TARGETS+=("docker")
;;
"systemd-container")
ALL_BUILD_TARGETS+=("systemd-container")
;;
"test")
ALL_BUILD_TARGETS+=("test")
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information."
exit 1
;;
esac
shift
done
for TARGET in "${ALL_BUILD_TARGETS[@]}"; do
# Here you can add specific setup commands for each target if needed
if [[ $TARGET == "native" ]]; then
echo "Setting up native build environment..."
# Add commands specific to native setup if needed
if [[ $DO_CLEAN_FIRST -eq 1 ]]; then
echo "Cleaning previous builds (native)..."
rm -rf builds/native
fi
mkdir -p builds/native
bash buildscripts/native.sh
elif [[ $TARGET == "docker" ]]; then
echo "Setting up Docker build environment..."
if [[ $DO_CLEAN_FIRST -eq 1 ]]; then
echo "Cleaning previous builds (docker)..."
rm -rf builds/docker
fi
mkdir -p builds/docker
# Add commands specific to Docker setup if needed
bash buildscripts/docker.sh
elif [[ $TARGET == "test" ]]; then
echo "Testing environment. WARNING: This will unpack and install the native build locally. You have 30 seconds to cancel if this is a mistake"
for i in {30..1}; do
echo -ne "\rTesting in $i seconds..."
sleep 1
done
if [[ $DO_CLEAN_FIRST -eq 1 ]]; then
echo "Cleaning previous builds (test)..."
rm -rf builds/test
fi
mkdir -p builds/test
bash buildscripts/test.sh
elif [[ $TARGET == "systemd-container" ]]; then
echo "Preparing systemd-container build environment..."
if [[ $DO_CLEAN_FIRST -eq 1 ]]; then
echo "Cleaning previous builds (systemd-container)..."
sudo rm -rf builds/systemd-container
fi
mkdir -p builds/systemd-container
bash buildscripts/systemd-container.sh
if [[ $BUNDLE_PUBLIC -eq 1 ]]; then
echo "Bundling systemd-container for external use..."
pushd builds
tar --exclude=systemd-container/cpu2017.iso -czf systemd-container-PUBLIC.tar.gz systemd-container
popd
fi
if [ -f cpu2017.iso ]; then
echo "Copying cpu2017.iso to builds/systemd-container"
cp cpu2017.iso builds/systemd-container/
else
echo "cpu2017.iso not found, skipping copy."
fi
if [[ $BUNDLE_INTERNAL -eq 1 ]]; then
echo "Bundling systemd-container for internal use..."
pushd builds
tar -czf systemd-container-internal.tar.gz systemd-container
popd
fi
if [[ $DO_RUN_AFTER -eq 1 ]]; then
echo "Running systemd-container build..."
pushd builds/systemd-container
bash run.sh
popd
fi
else
echo "Unknown build target: $TARGET"
fi
done