-
Notifications
You must be signed in to change notification settings - Fork 3
/
round1.sh
executable file
·216 lines (172 loc) · 5.83 KB
/
round1.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
#!/bin/bash
# ROUND 1: Try making a snap out of a bare bones root
if [[ "$EUID" != "0" ]]; then
echo "I .. AM... not g.. ROOT"
exit 1
fi
. common.sh
ROOTDIR="$WORKDIR/BASE_ROOT"
# Bit of house keeping to ensure package managers don't jank up the rootfs
function init_root()
{
if [[ ! -d "$ROOTDIR" ]]; then
mkdir -p $ROOTDIR
fi
mkdir -p $ROOTDIR/run/lock
mkdir -p $ROOTDIR/var
ln -s ../run/lock $ROOTDIR/var/lock
ln -s ../run $ROOTDIR/var/run
}
# Make the rootfs happy enough for snapd
function snappify()
{
# Needed in general for everyone
mkdir -p $ROOTDIR/var/lib/snapd
mkdir -p $ROOTDIR/var/log
mkdir -p $ROOTDIR/var/snap
mkdir -p $ROOTDIR/lib/modules
mkdir -p $ROOTDIR/usr/src
mkdir -p $ROOTDIR/usr/lib/snapd
mkdir -p $ROOTDIR/media
mkdir -p $ROOTDIR/snap
# OK so in theory we could install snapd inside but meh.
install -m 00755 /usr/lib/udev/snappy-app-dev $ROOTDIR/lib/udev/.
# UGLY HACKS: Get this fixed in snapd confinement policy!
# We use lib64, snapd defines "lib" within the target
rm $ROOTDIR/lib
mv $ROOTDIR/lib64 $ROOTDIR/lib
ln -sv lib $ROOTDIR/lib64
# Repeat of the above
rm $ROOTDIR/usr/lib
mv $ROOTDIR/usr/lib64 $ROOTDIR/usr/lib
ln -sv lib $ROOTDIR/usr/lib64
}
# Desparately attempt to install a package
function install_package()
{
eopkg install -y -D "$ROOTDIR" --ignore-comar $*
}
# Similar to install_package, just uses -c notation.
function install_component()
{
install_package -c $*
}
# Ugly, add a repo to the directory
function add_repo()
{
eopkg add-repo -D "$ROOTDIR" "Solus" $1
}
# Placeholder until we can have custom packages for this runtime
# Basically the LDM detection will fail and the default mesa symlinks will
# be put in place.
function configure_pending()
{
# Now ask usysconf to finish up for us
mount --bind /proc "$ROOTDIR/proc"
# Force a machine for this new image
chroot "$ROOTDIR" /usr/bin/systemd-machine-id-setup
chroot "$ROOTDIR" /usr/sbin/usysconf run -f
umount "$ROOTDIR/proc"
# At this point lets seal it off and stick in our overriden files
cp -Rv "$BASEDIR/support_assets"/* "$ROOTDIR/."
}
function clean_root()
{
# Nuke system files that take up space we're not wanting to use..
rm -rf "$ROOTDIR/usr/share/doc"
rm -rf "$ROOTDIR/usr/share/man"
rm -rf "$ROOTDIR/usr/share/info"
# Clean out package manager noise
rm -rf "$ROOTDIR/var/lib/eopkg"
rm -rf "$ROOTDIR/var/cache/eopkg"
# Clean out dbs+cruft
rm -rf "$ROOTDIR/var/db"
rm -rf "$ROOTDIR/var/log"
# Clean up other unneeded dudes from qt bits
rm -rf "$ROOTDIR/usr/lib64/kconf_update_bin"
rm -rf "$ROOTDIR/usr/share/kconf_update"
# If we need these then we'll restore them..
rm -rf "$ROOTDIR/usr/share/locale"
# Nuke accidental .a fatties
rm -fv "$ROOTDIR/usr/lib64"/*.a
rm -fv "$ROOTDIR/usr/lib32"/*.a
rm -rf "$ROOTDIR/etc/NetworkManager"
rm -rf "$ROOTDIR/etc/systemd"
rm -rf "$ROOTDIR/etc/X11"
rm -rf "$ROOTDIR/lib/xtables"
rm -rf "$ROOTDIR/lib/security"
rm -rf "$ROOTDIR/usr/lib/ModemManager"
rm -rf "$ROOTDIR/usr/lib/network-manager"
rm -rf "$ROOTDIR/usr/lib/NetworkManager"
rm -rf "$ROOTDIR/usr/lib32/NetworkManager"
rm -rf "$ROOTDIR/usr/lib/cups"
rm -rf "$ROOTDIR/usr/lib/pulse-10.0"
rm -rf "$ROOTDIR/usr/lib/udev/rules.d"
rm -rf "$ROOTDIR/usr/lib/systemd"
rm -rf "$ROOTDIR/usr/lib/sysusers.d"
rm -rf "$ROOTDIR/usr/lib/tmpfiles.d"
rm -rf "$ROOTDIR/usr/share/base-layout"
rm -rf "$ROOTDIR/usr/share/bash-completion"
rm -rf "$ROOTDIR/usr/share/gettext"
rm -rf "$ROOTDIR/usr/share/gdb"
# Clean up some unnecessary setuid crap
rm -v "$ROOTDIR/bin/mount"
rm -v "$ROOTDIR/bin/umount"
rm -v "$ROOTDIR/sbin/unix_chkpwd"
rm -v "$ROOTDIR/usr/bin/ksu"
rm -v "$ROOTDIR/usr/bin/pkexec"
rm -v "$ROOTDIR/usr/bin/wall"
rm -v "$ROOTDIR/usr/lib/dbus-1.0/dbus-daemon-launch-helper"
rm -v "$ROOTDIR/usr/lib/polkit-1/polkit-agent-helper-1"
rm -rf "$ROOTDIR/var/spool/cups/tmp"
# systemd things, breaking dependencies
rm -vf "$ROOTDIR/usr/bin/"systemd*
rm -vf "$ROOTDIR/usr/bin/"*ctl
# Fix stuff not meant to be there like /dev/lp* nodes from tmpfiles snippets
rm -vf "$ROOTDIR/dev/"*
# Fix avx2 links
ln -sv avx2 "$ROOTDIR/usr/lib64/haswell"
ln -sv avx2 "$ROOTDIR/usr/lib32/haswell"
# Provide symlink to keep fonts happy inside the image
ln -sv "/usr/share/fonts" "$ROOTDIR/etc/fonts"
}
# Cheap and dirty, copy the named runtime meta into the root and tell it to
# bake a snap for us
function cook_snap()
{
cp -Rv $RUNTIME_DIR/$1/meta "$ROOTDIR/."
snap pack "$ROOTDIR"
}
set -e
set -x
# Bring up the root tree
init_root
# Let's get a repo going.
add_repo "https://packages.solus-project.com/unstable/eopkg-index.xml.xz"
# Must have our baselayout first.
install_package baselayout --ignore-safety
# Now lets fire in our core component, i.e. a working system.
# Totally ignore system.base safety to minimise the system
install_package --ignore-safety $(cat pkgs/base)
# Now install our graphical packages
install_package --ignore-safety $(cat pkgs/gui)
# Lastly, prep our runtime packages (+emul32 stuff)
install_package --ignore-safety $(cat pkgs/gaming)
# Cosmetics, install breeze theme for integration, WITHOUT qt dependency
install_package --ignore-safety --ignore-dependency breeze-gtk-theme
# Our override directories.
build_one glew16
# Override glibc with our custom glibc
build_one glibc
# Now install all of our packages to our app root
install_package $PACKAGE_OUT_DIR/*.eopkg --ignore-safety
rm -rf "$PACKAGE_OUT_DIR"
# Ensure everything is good to go
configure_pending
# TODO: Lock the root, configure it
# Now lets clean the rootfs out
clean_root
# Make snapd happy
snappify
# Now lets cook a snap
cook_snap gaming