-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsetup.sh
executable file
·107 lines (93 loc) · 3.39 KB
/
setup.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
# Droidian rootfs installer script
# https://droidian.org
OUTFD=/proc/self/fd/$1;
VENDOR_DEVICE_PROP=`grep ro.product.vendor.device /vendor/build.prop | cut -d "=" -f 2 | awk '{print tolower($0)}'`;
# ui_print <text>
ui_print() { echo -e "ui_print $1\nui_print" > $OUTFD; }
## rootfs install
mv /data/droidian/data/* /data/;
mkdir /r;
# mount droidian rootfs
mount /data/rootfs.img /r;
# function to get the partitions where to flash imgs to.
get_partitions() {
current_slot=$(grep -o 'androidboot\.slot_suffix=_[a-b]' /proc/cmdline)
case "${current_slot}" in
"androidboot.slot_suffix=_a")
target_boot_partition="boot_a"
target_dtbo_partition="dtbo_a"
target_vbmeta_partition="vbmeta_a"
;;
"androidboot.slot_suffix=_b")
target_boot_partition="boot_b"
target_dtbo_partition="dtbo_b"
target_vbmeta_partition="vbmeta_b"
;;
"")
# No A/B
target_boot_partition="boot"
target_dtbo_partition="dtbo"
target_vbmeta_partition="vbmeta"
;;
*)
error "Unknown error while searching for a partition, exiting"
;;
esac
}
# If we should flash the kernel, do it
if [ -e "$(ls /r/boot/boot.img*)" ]; then
ui_print "Kernel found, flashing"
get_partitions
partition=$(find /dev/block/by-name -name "$target_boot_partition" | head -n 1)
if [ -n "${partition}" ]; then
ui_print "Found boot partition for current slot ${partition}"
dd if="$(find /r/boot -name 'boot.img*')" of="${partition}" || error "Unable to flash kernel"
ui_print "Kernel flashed"
fi
fi
# If we should flash the dtbo, do it
if [ -e "$(ls /r/boot/dtbo.img*)" ]; then
ui_print "DTBO found, flashing"
get_partitions
partition=$(find /dev/block/by-name -name "$target_dtbo_partition" | head -n 1)
if [ -n "${partition}" ]; then
ui_print "Found DTBO partition for current slot ${partition}"
dd if="$(find /r/boot -name 'dtbo.img*')" of="${partition}" || error "Unable to flash DTBO"
ui_print "DTBO flashed"
fi
fi
# If we should flash the vbmeta, do it
if [ -e "$(ls /r/boot/vbmeta.img*)" ]; then
ui_print "VBMETA found, flashing"
partition=$(find /dev/block/by-name -name "$target_vbmeta_partition" | head -n 1)
if [ -n "${partition}" ]; then
ui_print "Found VBMETA partition ${partition}"
dd if="$(find /r/boot -name 'vbmeta.img*')" of="${partition}" || error "Unable to flash VBMETA"
ui_print "VBMETA flashed"
fi
fi
if [ -f /r/.full_resize ]; then
umount /r;
# resize rootfs
# first get the remaining space on the partition
AVAILABLE_SPACE=$(df /data | awk '/dev\/block\/.+/ {print $4}')
PRETTY_SIZE=$(df -h /data | awk '/dev\/block\/.+/ {print $4}')
# then remove 100MB (102400KB) from the size
# later on in case of kernel updates this storage might come in handy.
# about the same amount is preserved for LVM images in the droidian--persistent and droidian--reserved partitions.
IMG_SIZE=$((AVAILABLE_SPACE - 102400))
ui_print "Resizing rootfs to $PRETTY_SIZE";
e2fsck -fy /data/rootfs.img
resize2fs /data/rootfs.img "$IMG_SIZE"K
else
umount /r;
ui_print "Resizing rootfs to 8GB";
e2fsck -fy /data/rootfs.img
resize2fs -f /data/rootfs.img 8G
fi
# halium initramfs workaround,
# create symlink to android-rootfs inside /data
if [ ! -e /data/android-rootfs.img ]; then
ln -s /halium-system/var/lib/lxc/android/android-rootfs.img /data/android-rootfs.img || true
fi
## end install