-
Notifications
You must be signed in to change notification settings - Fork 0
/
eweos_bootstrap.sh
161 lines (159 loc) · 8.13 KB
/
eweos_bootstrap.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
#!/usr/bin/env bash
#
##DO NOT RUN DIRECTLY
##Self: bash <(curl -qfsSL "https://raw.githubusercontent.com/pkgforge/flatimage-base/refs/heads/main/eweos_bootstrap.sh")
#
#-------------------------------------------------------#
set -x
#Sanity Checks
if [ -z "${FIM_SRCDIR}" ] || \
[ -z "${FIM_BINDIR}" ] || \
[ -z "${FIM_IMGDIR}" ]; then
#exit
echo -e "\n[+] Skipping Builds...\n"
exit 1
fi
if [ ! -d "${FIM_BINDIR}" ] || [ $(du -s "${FIM_BINDIR}" | cut -f1) -le 1000 ]; then
echo -e "\n[+] FIM_BINDIR is Empty or Broken\n"
exit 1
fi
if ! declare -F create_flatimage_base >/dev/null; then
echo -e "\n[+] create_flatimage_base Function is undefined\n"
exit 1
fi
set +x
#-------------------------------------------------------#
#-------------------------------------------------------#
##eweos
echo -e "\n[+] Creating eweos.FlatImage\n"
#Bootstrap
pushd "$(mktemp -d)" >/dev/null 2>&1
docker stop "eweos" 2>/dev/null ; docker rm "eweos" 2>/dev/null
docker run --name "eweos" --privileged "ghcr.io/eweos/docker:nightly" bash -l -c '
#Bootstrap
pacman -y --sync --refresh --refresh --sysupgrade --noconfirm --debug
packages="bash binutils curl fakechroot fakeroot git wget"
for pkg in $packages; do pacman -Sy "$pkg" --noconfirm ; done
for pkg in $packages; do pacman -Sy "$pkg" --needed --noconfirm ; done
#Fix & Patches
sed '\''/DownloadUser/d'\'' -i "/etc/pacman.conf"
#sed '\''s/^.*Architecture\s*=.*$/Architecture = auto/'\'' -i "/etc/pacman.conf"
sed '\''0,/^.*SigLevel\s*=.*/s//SigLevel = Never/'\'' -i "/etc/pacman.conf"
#sed '\''s/^.*SigLevel\s*=.*$/SigLevel = Never/'\'' -i "/etc/pacman.conf"
sed '\''/#\[multilib\]/,/#Include = .*/s/^#//'\'' -i "/etc/pacman.conf"
echo -e "nameserver 8.8.8.8\nnameserver 2620:0:ccc::2" | tee "/etc/resolv.conf"
echo -e "nameserver 1.1.1.1\nnameserver 2606:4700:4700::1111" | tee -a "/etc/resolv.conf"
unlink "/var/lib/dbus/machine-id" 2>/dev/null
unlink "/etc/machine-id" 2>/dev/null
rm -rvf "/etc/machine-id"
systemd-machine-id-setup --print 2>/dev/null | tee "/var/lib/dbus/machine-id"
cat "/var/lib/dbus/machine-id" | tee "/etc/machine-id"
pacman -Scc --noconfirm
echo "disable-scdaemon" | tee "/etc/pacman.d/gnupg/gpg-agent.conf"
curl -qfsSL "https://raw.githubusercontent.com/pkgforge/flatimage-base/refs/heads/main/archlinux_hooks.sh" -o "/arch_hooks.sh"
chmod +x "/arch_hooks.sh" ; "/arch_hooks.sh"
rm -rfv "/arch_hooks.sh"
echo "LANG=en_US.UTF-8" | tee "/etc/locale.conf"
echo "LANG=en_US.UTF-8" | tee -a "/etc/locale.conf"
echo "LANGUAGE=en_US:en" | tee -a "/etc/locale.conf"
echo "LC_ALL=en_US.UTF-8" | tee -a "/etc/locale.conf"
echo "en_US.UTF-8 UTF-8" | tee -a "/etc/locale.gen"
echo "LC_ALL=en_US.UTF-8" | tee -a "/etc/environment"
locale-gen ; locale-gen "en_US.UTF-8"
#Cleanup
pacman -y --sync --refresh --refresh --sysupgrade --noconfirm
pacman -Rsn base-devel --noconfirm
pacman -Rsn perl --noconfirm
pacman -Rsn python --noconfirm
pacman -Scc --noconfirm
#Fake-Sudo
pacman -Rsndd sudo 2>/dev/null
rm -rvf "/usr/bin/sudo" 2>/dev/null
curl -qfsSL "https://github.com/pkgforge/flatimage-base/releases/download/$(uname -m)/fake-sudo-pkexec.tar.zst" -o "./fake-sudo-pkexec.tar.zst" && chmod +x "./fake-sudo-pkexec.tar.zst"
pacman -Uddd "./fake-sudo-pkexec.tar.zst" --noconfirm
pacman -Syy fakeroot --needed --noconfirm
rm -rvf "./fake-sudo-pkexec.tar.zst"
##Yay
# curl -qfsSL "https://github.com/pkgforge/flatimage-base/releases/download/$(uname -m)/yay" -o "/usr/bin/yay" && chmod +x "/usr/bin/yay"
# yay --version ; which fakeroot yay sudo
#More cleanup
rm -rfv "/usr/share/gtk-doc/"* 2>/dev/null
rm -rfv "/usr/share/man/"* 2>/dev/null
rm -rfv "/usr/share/help/"* 2>/dev/null
rm -rfv "/usr/share/info/"* 2>/dev/null
rm -rfv "/usr/share/doc/"* 2>/dev/null
rm -rfv "/var/tmp/"* 2>/dev/null
rm -rfv "/var/lib/pacman/sync/"* 2>/dev/null
rm -rfv "/var/cache/pacman/pkg/"* 2>/dev/null
find "/boot" -mindepth 1 -delete 2>/dev/null
find "/dev" -mindepth 1 -delete 2>/dev/null
find "/proc" -mindepth 1 -delete 2>/dev/null
find "/run" -mindepth 1 -delete 2>/dev/null
find "/sys" -mindepth 1 -delete 2>/dev/null
find "/tmp" -mindepth 1 -delete 2>/dev/null
find "/usr/include" -mindepth 1 -delete 2>/dev/null
find "/usr/lib" -type f -name "*.a" -print -exec rm -rfv "{}" 2>/dev/null \; 2>/dev/null
find "/usr/lib32" -type f -name "*.a" -print -exec rm -rfv "{}" 2>/dev/null \; 2>/dev/null
find "/etc/pacman.d/gnupg" -type f -name "S.*" -print -exec rm -rfv "{}" 2>/dev/null \; 2>/dev/null
find "/usr/share/locale" -mindepth 1 -maxdepth 1 ! -regex ".*/\(locale.alias\|en\|en_US\)$" -exec rm -rfv "{}" + 2>/dev/null
find "/usr/share/doc" -mindepth 1 -delete 2>/dev/null
find "/usr/share/gtk-doc" -mindepth 1 -delete 2>/dev/null
find "/usr/share/help" -mindepth 1 -delete 2>/dev/null
find "/usr/share/info" -mindepth 1 -delete 2>/dev/null
find "/usr/share/man" -mindepth 1 -delete 2>/dev/null
find "." -type d -name "__pycache__" -exec rm -rfv "{}" \; 2>/dev/null
find "." -type f -name "*.pacnew" -exec rm -rfv "{}" \; 2>/dev/null
find "." -type f -name "*.pacsave" -exec rm -rfv "{}" \; 2>/dev/null
find "/var/log" -type f -name "*.log" -exec rm -rfv "{}" \; 2>/dev/null
rm -rfv "/"{tmp,proc,sys,dev,run} 2>/dev/null
mkdir -pv "/"{tmp,proc,sys,dev,run/media,mnt,media,home} 2>/dev/null
rm -fv ""/etc/{host.conf,hosts,nsswitch.conf} 2>/dev/null
touch ""/etc/{host.conf,hosts,nsswitch.conf} 2>/dev/null
hostname 2>/dev/null; cat "/etc/os-release" 2>/dev/null'
docker export "$(docker ps -aqf 'name=eweos')" --output "rootfs.tar"
if [[ -f "./rootfs.tar" ]] && [[ $(stat -c%s "./rootfs.tar") -gt 10000 ]]; then
mkdir -pv "./rootfs" && export ROOTFS_DIR="$(realpath "./rootfs")"
rsync -achLv --mkpath "./rootfs.tar" "/tmp/ROOTFS/eweos.rootfs.tar"
if [ -n "${ROOTFS_DIR+x}" ] && [[ "${ROOTFS_DIR}" == "/tmp"* ]]; then
bsdtar -x -f "./rootfs.tar" -C "${ROOTFS_DIR}" 2>/dev/null
du -sh "${ROOTFS_DIR}"
sudo "${FIM_BINDIR}/proot" --kill-on-exit -R "${ROOTFS_DIR}" "/bin/bash" -c 'pacman -y --sync --refresh --refresh --sysupgrade --noconfirm'
sudo rm -rfv "${ROOTFS_DIR}/"{tmp,proc,sys,dev,run}
sudo mkdir -pv "${ROOTFS_DIR}/"{tmp,proc,sys,dev,run/media,mnt,media,home}
sudo rm -fv "${ROOTFS_DIR}"/etc/{host.conf,hosts,nsswitch.conf}
sudo touch "${ROOTFS_DIR}"/etc/{host.conf,hosts,nsswitch.conf}
du -sh "${ROOTFS_DIR}"
fi
fi
#Setup FS
if [ -d "${ROOTFS_DIR}" ] && [ $(du -s "${ROOTFS_DIR}" | cut -f1) -gt 10000 ]; then
popd >/dev/null 2>&1 ; pushd "${FIM_SRCDIR}" >/dev/null 2>&1
rm -rfv "${FIM_TMPDIR}/eweos" 2>/dev/null
mkdir -pv "${FIM_TMPDIR}/eweos/fim/config"
mkdir -pv "${FIM_TMPDIR}/eweos/fim/static"
sudo rsync -achv --mkpath "${ROOTFS_DIR}/." "${FIM_TMPDIR}/eweos"
sudo chown -R "$(whoami):$(whoami)" "${FIM_TMPDIR}/eweos" && chmod -R 755 "${FIM_TMPDIR}/eweos"
#Copy Bins
rsync -achv --mkpath "${FIM_BINDIR}/." "${FIM_TMPDIR}/eweos/fim/static"
#Copy Desktop, Icon & AppStream
mkdir -pv "${FIM_TMPDIR}/eweos/fim/desktop"
cp -fv "${FIM_SRCDIR}/mime/icon.svg" "${FIM_TMPDIR}/eweos/fim/desktop/icon.svg"
cp -fv "${FIM_SRCDIR}/mime/flatimage.xml" "${FIM_TMPDIR}/eweos/fim/desktop/flatimage.xml"
#Create
create_flatimage_base eweos || true
#Info
"${FIM_TMPDIR}/eweos.flatimage" fim-env add 'FIM_DIST=eweos' 2>/dev/null
"${FIM_TMPDIR}/eweos.flatimage" fim-env list 2>/dev/null
"${FIM_TMPDIR}/eweos.flatimage" fim-perms add "audio,dbus_user,dbus_system,gpu,home,input,media,network,udev,usb,xorg,wayland"
"${FIM_TMPDIR}/eweos.flatimage" fim-perms list
"${FIM_TMPDIR}/eweos.flatimage" fim-commit
fi
unset ROOTFS_DIR
#Copy
if [[ -f "${FIM_TMPDIR}/eweos.flatimage" ]] && [[ $(stat -c%s "${FIM_TMPDIR}/eweos.flatimage") -gt 10000 ]]; then
rsync -achLv "${FIM_TMPDIR}/eweos.flatimage" "${FIM_IMGDIR}"
realpath "${FIM_IMGDIR}/eweos.flatimage" | xargs -I {} sh -c 'file {}; sha256sum {}; du -sh {}'
fi
docker rmi "ghcr.io/eweos/docker:nightly" --force
popd >/dev/null 2>&1
#-------------------------------------------------------#