-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit.sh
More file actions
88 lines (77 loc) · 1.85 KB
/
Copy pathinit.sh
File metadata and controls
88 lines (77 loc) · 1.85 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
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
#!/bin/busybox sh
rescue_shell() {
echo "Something went wrong. Dropping you to a shell."
exec sh
}
/bin/busybox --install -s
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
mkdir /mnt/ramdisk
mount -t tmpfs -o noatime,size=3g tmpfs /mnt/ramdisk || rescue_shell
mkdir /mnt/target
echo "Scanning disks ..."
target_dev=0
ntrials=0
while [[ "$target_dev" == "0" ]]
do
for dev in $(tail -n +2 /proc/partitions | awk '{print $4}')
do
if mount -o ro /dev/"$dev" /mnt/target 2>> /dev/null
then
if [ -e /mnt/target/.uuid ]
then
read -r candidate_id</mnt/target/.uuid
if [[ "$candidate_id" == "$uuid" ]]
then
if [ -e /mnt/target/live/filesystem.squashfs ]
then
mem=$(head -n 1 /proc/meminfo | awk '{print $2}')
if [ "$mem" -lt 3000000 ]
then
echo "You need more RAM to use Pirate Linux Live"
rescue_shell
fi
echo "Checking filesystem ..."
if sha512sum /mnt/target/live/filesystem.squashfs | grep "$filesystem_squashfs_shasum"
then
echo "Unsquashing filesystem"
if /bin/unsquashfs -f -d /mnt/ramdisk /mnt/target/live/filesystem.squashfs
then
target_dev=1 && break
else
rescue_shell
fi
fi
fi
fi
fi
umount /mnt/target || rescue_shell
fi
done
if [[ "$target_dev" == "1" ]]
then
break
fi
ntrials=$(echo "$ntrials 1 + p" | dc)
if [[ "$ntrials" == "1000" ]]
then
break
fi
sleep 1
done
if [[ "$target_dev" == "0" ]]
then
rescue_shell
fi
mkdir tmp
ncpus=$(grep -c ^processor /proc/cpuinfo)
nj=$(echo "$ncpus 1 + p" | dc)
echo "nj = $nj"
sed 's/^MAKEOPTS[=].*$/MAKEOPTS="-j'"$nj"'"/' </mnt/ramdisk/etc/portage/make.conf >tmp/make.conf
mv tmp/make.conf /mnt/ramdisk/etc/portage/
rmdir tmp
umount /proc
umount /sys
umount /dev
exec /bin/busybox switch_root /mnt/ramdisk /sbin/init