-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstage3.sh
More file actions
executable file
·148 lines (148 loc) · 5.68 KB
/
stage3.sh
File metadata and controls
executable file
·148 lines (148 loc) · 5.68 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#
# shellcheck disable=SC2035,SC2046,SC2086
#
# Prepare the environment for building a desktop environment.
set -e
# Ensure we're running as root.
if [ $EUID -ne 0 ]; then
echo "Error: Must be run as root." >&2
exit 1
fi
# Setup the environment.
export MASSOS="$PWD"/massos-rootfs
# Ensure stage1 has been run first.
if [ ! -d "$MASSOS" ] || [ -e "$MASSOS"/root/mbs/sources ]; then
echo "Error: You must complete stage1.sh and stage2.sh first!" >&2
exit 1
fi
# Ensure the specified desktop environment is valid.
if [ -z "$1" ]; then
echo "Error: Specify the desktop environment ('stage3/README' for info)." >&2
exit 1
fi
if [ ! -d "stage3/$1" ]; then
echo "Error: '$1' is not a valid or supported desktop environment." >&2
echo "The desktop environment must have a directory in 'stage3/'." >&2
echo "Alternatively, pass 'nodesktop' if you want a core only build." >&2
echo "See 'stage3/README' for more information." >&2
exit 1
fi
if [ ! -e "stage3/$1/stage3-$1.sh" ]; then
echo "Stage 3 directory for '$1' was found, but there is no Stage 3" >&2
echo "build script inside it." >&2
exit 1
fi
if [ ! -e "stage3/$1/source-urls" ]; then
echo "Stage 3 directory and build script for '$1' was found, but there" >&2
echo "is no source-urls file." >&2
exit 1
fi
if [ "$1" != "nodesktop" ] && [ ! -e "stage3/$1/builtins" ]; then
echo "Stage 3 directory and build script for '$1' was found, but there" >&2
echo "is no builtins file." >&2
exit 1
fi
# Download source URls for Stage 3.
echo "Downloading sources for '$1' (Stage 3)..."
mkdir -p stage3/sources; pushd stage3/sources
set +e
wget -nc --continue --input-file=../"$1"/source-urls
STATUS=$?
# Ensure everything downloaded successfully.
if [ $STATUS -ne 0 ]; then
echo -e "\nOne or more Stage 3 source download(s) failed." >&2
echo "Consider checking the above output and try re-running '$0 $1'." >&2
exit $STATUS
fi
set -e
popd
sync
# Put Stage 3 files into the system.
echo "Starting Stage 3 build for '$1'..."
mkdir -p "$MASSOS"/root/mbs/work
## Build script, sources and patches.
mv stage3/sources "$MASSOS"/root/mbs
cp stage3/"$1"/stage3-"$1".sh "$MASSOS"/root/mbs/build-stage3.sh
if [ -d stage3/"$1"/patches ]; then
cp -r stage3/"$1"/patches "$MASSOS"/root/mbs
fi
## Builtins.
if [ -e stage3/"$1"/builtins ]; then
install -Dm644 stage3/"$1"/builtins "$MASSOS"/usr/share/massos/builtins.d/"$1"
fi
## /etc/skel, if present.
if [ -d stage3/"$1"/skel ]; then
cp -r stage3/"$1"/skel/. "$MASSOS"/etc/skel/.
cp -r stage3/"$1"/skel/. "$MASSOS"/root/.
chown -R root:root "$MASSOS"/etc/skel
chown -R root:root "$MASSOS"/root
fi
## systemd units.
if [ -d stage3/"$1"/systemd-units ]; then
cp -r stage3/"$1"/systemd-units/* "$MASSOS"/usr/lib/systemd/system
chown -R root:root "$MASSOS"/usr/lib/systemd/system
fi
## extra-package-licenses, if present.
if [ -d stage3/"$1"/extra-package-licenses ]; then
cp -r stage3/"$1"/extra-package-licenses "$MASSOS"/root/mbs/extras
fi
## build environment file.
cp build.env "${MASSOS}"/root/mbs
# Re-enter the chroot and continue the build.
utils/programs/mass-chroot "$MASSOS" /root/mbs/build-stage3.sh
# Put in finalize.sh and finish the build.
echo "Finalizing the build..."
cp finalize.sh "$MASSOS"/root/mbs
utils/programs/mass-chroot "$MASSOS" /root/mbs/finalize.sh
# Mark the stage 3 variant.
echo "$1" > "$MASSOS"/usr/share/massos/.variant
# Install preupgrade, postupgrade and upgrade-exclude.
cp utils/{{pre,post}upgrade{,_ng},etc-force-replace,upgrade-exclude} "$MASSOS"/tmp
# Install Live CD cleanup script for osinstallgui.
install -t "$MASSOS"/tmp -m755 utils/livecd-cleanup.sh
# Strip executables and libraries to free up space.
# Use --strip-unneeded on binaries and shared libraries.
# Use --strip-debug on object files and static libraries.
# Do NOT strip .efi executables as it will remove their secure boot signatures!
printf "Stripping binaries and libraries... "
find "$MASSOS"/usr/{bin,lib,libexec,sbin} -type f ! -name \*.a ! -name \*.o ! -name \*.mod ! -name \*.module ! -name \*.ko\* ! -name \*.efi\* -exec strip --strip-unneeded {} ';' &>/dev/null || true
find "$MASSOS"/usr/lib -type f \( -name \*.a -o -name \*.o -o -name \*.mod -o -name \*.module \) -exec strip --strip-debug {} ';' &>/dev/null || true
echo "Done!"
# Generate list of distribution-provided files, for 'upgrade-massos' utility.
find "$MASSOS"/{boot,etc,usr,var} -type d,f,l -printf "%y:%p\n" | sed "s|$MASSOS||" | sort > "$MASSOS"/usr/share/massos/.distfiles
# Finish the MassOS system.
sync
outfile="massos-$(cat "$MASSOS"/etc/massos-release)-rootfs-x86_64-$1.tar"
printf "Creating %s... " "$outfile"
cd "$MASSOS"
tar -cpf ../"$outfile" *
cd ..
echo "Done!"
sync
echo "Compressing $outfile with ZSTD (using $(nproc) threads)... "
zstd --ultra -22 -T$(nproc) --rm "$outfile"
echo "Successfully created $outfile.zst."
b2sum "$outfile.zst" > "$outfile.zst.b2"
echo "Wrote Blake-2 checksum to $outfile.zst.b2."
# Change ownership of rootfs to top-level directory owner if possible.
chown -v "$(stat -c "%U:%G" .)" "$outfile.zst" "$outfile.zst.b2" || true
# Clean up.
rm -rf "$MASSOS"
sync
# Finishing message.
echo
echo "We know it took time, but the build has finally finished successfully!"
echo "You can produce a detached GPG signature for your build by running:"
echo
echo " gpg --detach-sign --armor '$outfile.zst'"
echo
echo "The detached signature will be written to '$outfile.zst.asc'."
echo
echo "If you wish to create a Live CD ISO image for your build, run:"
echo
echo " ./create-livecd.sh '$outfile.zst'"
# Send a notification to the system if supported.
if notify-send --version &>/dev/null; then
notify-send -i "$PWD"/logo/massos-logo-circlecropped.png "MassOS Build System" "The Stage 3 build has finished successfully." &>/dev/null || true
fi