wok-current view syslinux/stuff/iso2exe/init @ rev 24139
Add redupe
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Nov 09 17:05:26 2021 +0000 (2021-11-09) |
parents | 3d19917d3a03 |
children | a8ab25106e45 |
line source
1 #!/bin/sh
3 getarg()
4 {
5 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
6 }
8 media=/media/cdrom
9 mnt=/mnt
10 getiso()
11 {
12 mkdir -p $media
13 for bdev in /sys/block/*; do
14 for dev in $(ls -d $bdev/$(basename $bdev)*); do
15 [ "$dev" ] || continue 2
16 mount /dev/$(basename $dev) $mnt
17 if [ -s $mnt/$ISO ] && [ $(getarg magic) = $(hexdump -v -s 18 -n 2 -e "\"\" 1/2 \" %u\n\"" $mnt/$ISO) ]; then
18 echo "Found $ISO on $(basename $dev)"
19 ISO=$mnt/$ISO
20 mount -o loop,ro $ISO $media
21 return
22 fi
23 umount $mnt
24 done
25 done
26 text
27 }
29 uncpio=uncpio64
30 uncpio64()
31 {
32 i=$1
33 grep ' lm ' /proc/cpuinfo && [ -s ${i}64 ] && i=${i}64
34 [ -s "$i" ] || return
35 echo -en "\n Extracting $(basename $i) ..."
36 case $(get 0 $i) in
37 *35615) ( zcat || gunzip );;
38 *14333) unxz;;
39 *\ 93) unlzma;;
40 *) cat;;
41 esac < $i | ( cd ${2:-/}; cpio -idmu > /dev/null 2>&1 )
42 }
44 tty0=tty0
45 bootlog()
46 {
47 dialog --clear --title " Linux boot messages " --textbox /tmp/dmesg 24 78
48 }
50 gotposixovl()
51 {
52 mount.posixovl 2>&1 | grep -qi usage &&
53 echo -en "\"$1\" \"$2\""
54 }
56 dosync()
57 {
58 sync
59 if [ -s /lib/modules/squashfs.ko* ]; then
60 rm /var /usr
61 umount -d /sqfs
62 rmdir /sqfs 2>/dev/null || rm -f /sqfs
63 rm -rf /etc
64 fi
65 umount -d $media
66 rm -f /dev/cdrom
67 umount $mnt
68 killall udevd 2>/dev/null
69 umount /sys/fs/fuse/connections 2>/dev/null
70 umount /sys
71 umount /proc
72 }
74 xhascustomconf=false
75 text()
76 {
77 [ -d /etc/skel ] || $uncpio $(ls -r $media/boot/rootfs?*.* | sed q)
78 init=
79 cmdline="$(cat /proc/cmdline)"
80 if $xhascustomconf 2> /dev/null; then
81 getcustomconf /tmp > /dev/null
82 [ -s /tmp/cmdline ] &&
83 cmdline="$cmdline $(cat /tmp/cmdline)" &&
84 init="$(sed '/rdinit=/!d;s/.*rdinit=\([^ ]*\).*/\1/' /tmp/cmdline)"
85 [ -s /tmp/initrd ] && $uncpio /tmp/initrd
86 fi
87 dosync
88 sed 's/ || exit//' -i /init
89 exec ${init:-/init} $cmdline
90 }
92 xdowait=echo
93 live()
94 {
95 n=0
96 $xdotwait "Extract filesystem..."
97 for i in $(ls -r $media/boot/rootfs?*.*); do
98 [ $((n++)) -eq 0 ] || $uncpio $i
99 done
100 rm -f /tmp/wait
101 text
102 }
104 restart()
105 {
106 dosync
107 reboot -f
108 }
110 stop()
111 {
112 dosync
113 poweroff -f
114 }
116 dokexec()
117 {
118 kexec -l $file || return
119 dosync
120 kexec -e
121 }
123 shell()
124 {
125 trap text 2
126 getty -n -l /bin/ash 38400 tty1 2>/dev/null || sh
127 }
129 BIN=bin/mount.posixovl
130 [ -x /usr/s$BIN ] || mv /$BIN.iso2exe /usr/s$BIN 2>/dev/null || mv /$BIN.iso2exe /$BIN 2>/dev/null
131 mount -t proc /proc /proc
132 mount -t sysfs /sys /sys
133 udevd --daemon 2>/dev/null && udevadm trigger && sleep 5
134 mdev -s 2> /dev/null ||
135 for i in /sys/block/*/dev /sys/block/*/*/dev; do
136 [ -s "$i" ] || continue
137 n=${i%/dev}
138 n=/dev/${n##*/}
139 [ -e $n ] && continue
140 mknod $n b $(sed 's/:/ /' < $i)
141 done 2>/dev/null
142 ISO="$(getarg iso | sed 's/.://;s|\\|/|g')"
143 getiso 2>/dev/null || text
144 if [ -s /lib/modules/squashfs.ko* ]; then
145 insmod /lib/modules/squashfs.ko* 2>/dev/null
146 if [ -d $media/fs ]; then
147 ln -s $media/fs /sqfs
148 else
149 mkdir /sqfs
150 losetup -o 124 /dev/loop6 $(ls -r $media/boot/rootfs?*.* | sed q)
151 mount -r /dev/loop6 /sqfs
152 fi
153 cp -a /sqfs/dev/fuse /sqfs/dev/tty[12] /dev
154 for i in /sqfs/dev/* ; do [ -b $i ] && cp -a $i /dev ; done
155 ln -s /sqfs/lib/* lib 2>/dev/null
156 ln -fs /sqfs/usr /sqfs/var /
157 mkdir /etc && cp /sqfs/etc/dialogrc /etc 2>/dev/null
158 fi
159 [ -s /usr/bin/taziso ] || live
160 . /usr/bin/taziso