-
Notifications
You must be signed in to change notification settings - Fork 21
/
05-setup-user.sh
executable file
·79 lines (64 loc) · 1.84 KB
/
05-setup-user.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
#!/bin/bash
set -e
source .env
HOSTARCH=$(uname -m)
echo "================"
echo "05-setup-user.sh"
echo "================"
# Functions
infecho () {
echo "[Info] $1"
}
# Notify User
infecho "The env vars that will be used in this script..."
infecho "PP_PARTB = $PP_PARTB"
echo
# Automatic Preflight Checks
if [[ $EUID -ne 0 ]]; then
errecho "This script must be run as root!"
exit 1
fi
# Warning
echo "=== WARNING WARNING WARNING ==="
infecho "I didn't test this so it might also cause WWIII or something."
infecho "I'm not responsible for anything that happens, you should read the script first."
echo "=== WARNING WARNING WARNING ==="
echo
if [ ! -z "$PS1" ]; then
read -p "Continue? [y/N] " -n 1 -r
else
REPLY=y
fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
infecho "Mounting rootfs..."
mkdir -p rootfs
mount $PP_PARTB rootfs
infecho "Mounting bootfs..."
mkdir -p rootfs/boot
mount $PP_PARTA rootfs/boot
if [[ $HOSTARCH != "aarch64" ]]; then
infecho "Installing qemu in rootfs..."
cp /usr/bin/qemu-aarch64-static rootfs/usr/bin
fi
cp phone-scripts/* rootfs/root
infecho "Copy resolv.conf /etc/tmp-resolv.conf"
cp /etc/resolv.conf rootfs/etc/tmp-resolv.conf
if [[ $HOSTARCH != "aarch64" ]]; then
infecho "Chrooting with qemu into rootfs..."
systemd-nspawn -D rootfs qemu-aarch64-static /bin/bash /root/all.sh
infecho "KILLING ALL QEMU PROCESSES, MAKE SURE YOU HAVE NO MORE RUNNING!"
killall -9 /usr/bin/qemu-aarch64-static || true
infecho "Removing qemu binary, so it doesn't stay in image"
rm -f rootfs/usr/bin/qemu-aarch64-static
else
infecho "Chrooting into rootfs..."
chroot rootfs /bin/bash /root/all.sh
fi
infecho "Unmounting rootfs..."
sleep 3
umount $PP_PARTA
umount $PP_PARTB
rmdir rootfs
fi