forked from WhitewaterFoundry/fedora-remix-rootfs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-targz.sh
186 lines (149 loc) · 7.44 KB
/
create-targz.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
#!/bin/bash
echo "##[section] Set environment"
set -e
ORIGINDIR=$(pwd)
TMPDIR=${2:-$(mktemp -d -p "${HOME}")}
ARCH=""
ARCHDIR=""
mkdir -p "${TMPDIR}"
source linux_files/os-release-36
function build() {
echo "##[section] Install dependencies"
dnf -y update
dnf -y install mock qemu-user-static
if [ "$(uname -i)" != "$ARCH" ]; then
systemctl restart systemd-binfmt.service
fi
echo "##[section] Move to our temporary directory"
cd "${TMPDIR}"
mkdir "${TMPDIR}"/dist
echo "##[section] Make sure /dev is created before later mount"
mkdir -m 0755 "${TMPDIR}"/dist/dev
echo "##[section] Use mock to initialise chroot filesystem"
mock --root="fedora-${VERSION_ID}-${ARCH}" --init --dnf --forcearch="${ARCH}" --rootdir="${TMPDIR}"/dist
echo "##[section] Bind mount current /dev to new chroot/dev"
# (fixes '/dev/null: Permission denied' errors)
mount --bind /dev "${TMPDIR}"/dist/dev
echo "##[section] Install required packages, exclude unnecessary packages to reduce image size"
dnf --installroot="${TMPDIR}"/dist --forcearch="${ARCH}" --releasever="${VERSION_ID}" -y install @core libgcc glibc-langpack-en --exclude=grub\*,sssd-kcm,sssd-common,sssd-client,linux-firmware,dracut*,plymouth,parted,e2fsprogs,iprutils,iptables,ppc64-utils,selinux-policy*,policycoreutils,sendmail,kernel*,firewalld,fedora-release,fedora-logos,fedora-release-notes --allowerasing
echo "##[section] Unmount /dev"
umount "${TMPDIR}"/dist/dev
mkdir -p "${TMPDIR}"/dist/etc/fish/conf.d/
mkdir -p "${TMPDIR}"/dist/etc/fonts/
mkdir -p "${TMPDIR}"/dist/usr/local/bin/
echo "##[section] Fix dnf.conf"
# shellcheck disable=SC2155
local from_index=$(grep -n -m 1 '\[main\]' "${TMPDIR}"/dist/etc/dnf/dnf.conf | cut -d : -f 1)
# shellcheck disable=SC2155
local to_index=$(grep -n -m 1 '# repos' "${TMPDIR}"/dist/etc/dnf/dnf.conf | cut -d : -f 1)
sed -i "${from_index}"','"$((to_index - 2))"'d' "${TMPDIR}"/dist/etc/dnf/dnf.conf
cat "${ORIGINDIR}"/linux_files/dnf.conf "${TMPDIR}"/dist/etc/dnf/dnf.conf >"${TMPDIR}"/dist/etc/dnf/dnf.temp
mv "${TMPDIR}"/dist/etc/dnf/dnf.temp "${TMPDIR}"/dist/etc/dnf/dnf.conf
echo "##[section] Copy over some of our custom files"
cp "${ORIGINDIR}"/linux_files/wsl.conf "${TMPDIR}"/dist/etc/
cp "${ORIGINDIR}"/linux_files/local.conf "${TMPDIR}"/dist/etc/fonts/
cp "${ORIGINDIR}"/linux_files/00-remix.sh "${TMPDIR}"/dist/etc/profile.d/
cp "${ORIGINDIR}"/linux_files/00-remix.fish "${TMPDIR}"/dist/etc/fish/conf.d/
chmod -x,+r "${TMPDIR}"/dist/etc/profile.d/00-remix.sh
chmod -x,+r "${TMPDIR}"/dist/etc/fish/conf.d/00-remix.fish
cp "${ORIGINDIR}"/linux_files/upgrade.sh "${TMPDIR}"/dist/usr/local/bin/
chmod +x "${TMPDIR}"/dist/usr/local/bin/upgrade.sh
ln -s /usr/local/bin/upgrade.sh "${TMPDIR}"/dist/usr/local/bin/update.sh
cp "${ORIGINDIR}"/linux_files/start-systemd.sudoers "${TMPDIR}"/dist/etc/sudoers.d/start-systemd
cp "${ORIGINDIR}"/linux_files/start-systemd.sh "${TMPDIR}"/dist/usr/local/bin/start-systemd
chmod +x "${TMPDIR}"/dist/usr/local/bin/start-systemd
cp "${ORIGINDIR}"/linux_files/wsl2-xwayland.service "${TMPDIR}"/dist/etc/systemd/system/wsl2-xwayland.service
cp "${ORIGINDIR}"/linux_files/wsl2-xwayland.socket "${TMPDIR}"/dist/etc/systemd/system/wsl2-xwayland.socket
ln -sf ../wsl2-xwayland.socket "${TMPDIR}"/dist/etc/systemd/system/sockets.target.wants/
cp "${ORIGINDIR}"/linux_files/systemctl3.py "${TMPDIR}"/dist/usr/local/bin/wslsystemctl
chmod +x "${TMPDIR}"/dist/usr/local/bin/wslsystemctl
echo "##[section] Comply with Fedora Remix terms"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
dnf -y update
dnf -y install generic-release --allowerasing --releasever="${VERSION_ID}"
dnf -y reinstall fedora-repos-modular fedora-repos
EOF
echo "##[section] Overwrite os-release provided by generic-release"
cp "${ORIGINDIR}"/linux_files/os-release-"${VERSION_ID}" "${TMPDIR}"/dist/etc/os-release
echo "##[section] Install cracklibs-dicts"
systemd-nspawn --resolv-conf="replace-host" -q -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
dnf -y install --allowerasing --skip-broken cracklib-dicts
EOF
echo "##[section] Install bash-completion, vim, wget"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
dnf -y install bash-completion vim wget distribution-gpg-keys rsync
echo 'source /etc/vimrc' > /etc/skel/.vimrc
echo 'set background=dark' >> /etc/skel/.vimrc
echo 'set visualbell' >> /etc/skel/.vimrc
echo 'set noerrorbells' >> /etc/skel/.vimrc
echo '\$include /etc/inputrc' > /etc/skel/.inputrc
echo 'set bell-style none' >> /etc/skel/.inputrc
echo 'set show-all-if-ambiguous on' >> /etc/skel/.inputrc
echo 'set show-all-if-unmodified on' >> /etc/skel/.inputrc
EOF
echo "##[section] Fix ping"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
chmod u+s "$(command -v ping)"
EOF
echo "##[section] Reinstall crypto-policies and clean up"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
dnf -y reinstall crypto-policies --exclude=grub\*,dracut*,grubby,kpartx,kmod,os-prober,libkcapi*
dnf -y autoremove
dnf -y clean all
EOF
echo "##[section] 'Setup Whitewater Foundry repo"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
curl -s https://packagecloud.io/install/repositories/whitewaterfoundry/fedoraremix/script.rpm.sh | env os=fedora dist=35 bash
EOF
echo "##[section] 'Install fix for WSL1 and gpgcheck"
cp "${ORIGINDIR}"/linux_files/check-dnf.sh "${TMPDIR}"/dist/etc/profile.d
cp "${ORIGINDIR}"/linux_files/check-dnf.fish "${TMPDIR}"/dist/etc/fish/conf.d/
cp "${ORIGINDIR}"/linux_files/check-dnf "${TMPDIR}"/dist/usr/bin
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
echo '%wheel ALL=NOPASSWD: /usr/bin/check-dnf' | sudo EDITOR='tee -a' visudo --quiet --file=/etc/sudoers.d/check-dnf
chmod -w /usr/bin/check-dnf
chmod u+x /usr/bin/check-dnf
chmod -x,+r /etc/fish/conf.d/check-dnf.fish
chmod -x,+r /etc/profile.d/check-dnf.sh
EOF
echo "##[section] 'Install MESA"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
dnf -y install 'dnf-command(versionlock)'
dnf -y install mesa-dri-drivers-21.2.3-wsl.fc35 mesa-libGL-21.2.3-wsl.fc35 glx-utils
dnf versionlock add mesa-dri-drivers mesa-libGL mesa-filesystem mesa-libglapi
EOF
echo "##[section] 'Setup WSLU"
systemd-nspawn -q --resolv-conf="replace-host" -D "${TMPDIR}"/dist --pipe /bin/bash <<EOF
(
source /etc/os-release && dnf -y copr enable wslutilities/wslu "\${ID_LIKE}-${VERSION_ID}-${ARCH}"
)
dnf -y install wslu
EOF
echo "##[section] Copy dnf.conf"
cp "${ORIGINDIR}"/linux_files/dnf.conf "${TMPDIR}"/dist/etc/dnf/dnf.conf
echo "##[section] Create filesystem tar, excluding unnecessary files"
cd "${TMPDIR}"/dist
mkdir -p "${ORIGINDIR}"/"${ARCHDIR}"
tar --exclude='boot/*' --exclude=proc --exclude=dev --exclude=sys --exclude='var/cache/dnf/*' --numeric-owner -czf "${ORIGINDIR}"/"${ARCHDIR}"/install.tar.gz ./*
echo "##[section] Return to origin directory"
cd "${ORIGINDIR}"
echo "##[section] Cleanup"
rm -rf "${TMPDIR}"
}
function usage() {
echo "./create-targz.sh <BUILD_ARCHITECTURE>"
echo "Possible architectures: arm64, x86_64"
}
# Accept argument input for architecture type
ARCH="$1"
if [ "$ARCH" = "x86_64" ]; then
ARCH="x86_64"
ARCHDIR="x64"
build
elif [ "$ARCH" = "arm64" ]; then
ARCH="aarch64"
ARCHDIR="ARM64"
build
else
usage
fi