This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathinshim.sh
More file actions
52 lines (47 loc) · 1.46 KB
/
Copy pathinshim.sh
File metadata and controls
52 lines (47 loc) · 1.46 KB
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
#!/bin/bash
[ "$EUID" -ne 0 ] && fail "Not running as root, this shouldn't happen! Failing."
fail() {
printf "%b\n" "$*" >&2 || :
sleep 1d
}
get_largest_cros_blockdev() {
local largest size dev_name tmp_size remo
size=0
for blockdev in /sys/block/*; do
dev_name="${blockdev##*/}"
echo -e "$dev_name" | grep -q '^\(loop\|ram\)' && continue
tmp_size=$(cat "$blockdev"/size)
remo=$(cat "$blockdev"/removable)
if [ "$tmp_size" -gt "$size" ] && [ "${remo:-0}" -eq 0 ]; then
case "$(sfdisk -d "/dev/$dev_name" 2>/dev/null)" in
*'name="STATE"'*'name="KERN-A"'*'name="ROOT-A"'*)
largest="/dev/$dev_name"
size="$tmp_size"
;;
esac
fi
done
echo -e "$largest"
}
format_part_number() {
echo -n "$1"
echo "$1" | grep -q '[0-9]$' && echo -n p
echo "$2"
}
mount /dev/disk/by-label/STATE /mnt/stateful_partition/
cros_dev="$(get_largest_cros_blockdev)"
if [ -z "$cros_dev" ]; then
echo "No CrOS SSD found on device. Failing."
sleep 1d
fi
stateful=$(format_part_number "$cros_dev" 1)
mkfs.ext4 -F "$stateful" || fail "Failed to wipe stateful." # This only wipes the stateful partition
mount "$stateful" /tmp || fail "Failed to mount stateful."
mkdir -p /tmp/unencrypted
cp /mnt/stateful_partition/usr/share/packeddata/. /tmp/unencrypted/ -rvf
chown 1000 /tmp/unencrypted/PKIMetadata -R
rm /tmp/.developer_mode
umount /tmp
crossystem disable_dev_request=1 || fail "Failed to set disable_dev_request."
read -p "Finished! Press enter to reboot."
reboot