wok-current view syslinux/stuff/iso2exe/init @ rev 23831

syslinux/iso2exe: fix loram case
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun May 31 14:59:28 2020 +0000 (2020-05-31)
parents 7744355508b9
children 1f97fc4c73f1
line source
1 #!/bin/sh
3 getarg()
4 {
5 sed "/$1=/!d;s/.*$1=\\([^ ]*\\).*/\\1/" /proc/cmdline
6 }
8 myget()
9 {
10 hexdump -v -s $1 -n ${4:-${3:-2}} -e "\"\" 1/${3:-2} \" %u\n\"" $2
11 }
13 mount_proc()
14 {
15 mount -t proc /proc /proc
16 mount -t sysfs /sys /sys
17 udevd --daemon 2>/dev/null && udevadm trigger && sleep 5
18 }
20 umount_proc()
21 {
22 killall udevd 2>/dev/null
23 umount /sys/fs/fuse/connections 2>/dev/null
24 umount /sys
25 umount /proc
26 }
28 checkmagic()
29 {
30 [ -s $1 ] && [ $(getarg magic) = $(myget 18 $1 2) ]
31 }
33 media=/media/cdrom
34 mnt=/mnt
35 getiso()
36 {
37 mkdir -p $media
38 for dev in /sys/block/?d?/?d??*; do
39 mount /dev/$(basename $dev) $mnt
40 if checkmagic $mnt/$ISO; then
41 mount -o loop,ro $mnt/$ISO $media
42 echo "Found $ISO on $(basename $dev)"
43 ISO=$mnt/$ISO
44 return 0
45 fi
46 umount $mnt
47 done 2>/dev/null
48 return 1
49 }
51 uncpio=uncpio64
52 uncpio64()
53 {
54 i=$1
55 sed 's|$| |' /proc/cpuinfo | grep ' lm ' && [ -s ${i}64 ] && i=${i}64
56 [ -s "$i" ] || return
57 echo -en "\n Extracting $(basename $i) ..."
58 case $(get 0 $i) in
59 *35615) ( zcat || gunzip );;
60 *14333) unxz;;
61 *\ 93) unlzma;;
62 *) cat;;
63 esac < $i | ( cd ${2:-/}; cpio -idmu > /dev/null 2>&1 )
64 }
66 tty0=tty0
68 bootlog()
69 {
70 dialog --clear --title " Linux boot messages " \
71 --textbox /tmp/dmesg 24 78
72 }
74 gotposixovl()
75 {
76 mount.posixovl 2>&1 | grep -qi usage &&
77 echo -en "\"$1\" \"$2\""
78 }
80 myis_loram()
81 {
82 [ -s /lib/modules/squashfs.ko* ]
83 }
85 mount_loram()
86 {
87 myis_loram || return
88 insmod /lib/modules/squashfs.ko* 2>/dev/null
89 if [ -d $media/fs ]; then
90 ln -s $media/fs /sqfs
91 else
92 mkdir /sqfs
93 losetup -o 124 /dev/loop6 $(ls -r $media/boot/rootfs?*.* | sed q)
94 mount -r /dev/loop6 /sqfs
95 fi
96 cp -a /sqfs/dev/fuse /sqfs/dev/tty[12] /sqfs/dev/[hs]d* /dev
97 ln -s /sqfs/lib/* lib 2>/dev/null
98 ln -fs /sqfs/usr /sqfs/var /
99 mkdir /etc && cp /sqfs/etc/dialogrc /etc 2>/dev/null
100 }
102 umount_loram()
103 {
104 myis_loram || return
105 rm /var /usr
106 umount -d /sqfs
107 rmdir /sqfs 2>/dev/null || rm -f /sqfs
108 rm -rf /etc
109 }
111 dosync()
112 {
113 sync
114 umount_loram
115 umount -d $media
116 rm -f /dev/cdrom
117 umount $mnt
118 umount_proc
119 }
121 xhascustomconf=false
122 text()
123 {
124 $uncpio $(ls -r $media/boot/rootfs?*.* | sed q)
125 init=
126 cmdline="$(cat /proc/cmdline)"
127 if $xhascustomconf 2> /dev/null; then
128 getcustomconf /tmp > /dev/null
129 [ -s /tmp/cmdline ] &&
130 cmdline="$cmdline $(cat /tmp/cmdline)" &&
131 init="$(sed '/rdinit=/!d;s/.*rdinit=\([^ ]*\).*/\1/' < /tmp/cmdline)"
132 [ -s /tmp/initrd ] && $uncpio /tmp/initrd
133 fi
134 dosync
135 sed -i 's/ || exit//' /init
136 exec ${init:-/init} $cmdline
137 }
139 xdowait=echo
140 live()
141 {
142 n=0
143 $xdotwait "Extract filesystem..."
144 for i in $(ls -r $media/boot/rootfs*); do
145 [ $((n++)) -eq 0 ] || $uncpio $i
146 done
147 rm -f /tmp/wait
148 text
149 }
151 restart()
152 {
153 dosync
154 reboot -f
155 }
157 stop()
158 {
159 dosync
160 poweroff -f
161 }
163 dokexec()
164 {
165 kexec -l $file || return
166 dosync
167 kexec -e
168 }
170 runmemtest()
171 {
172 gotcdfile "memtest*" && dokexec
173 }
175 runpxe()
176 {
177 gotcdfile "?pxe*" && dokexec
178 }
180 shell()
181 {
182 trap text 2
183 getty -n -l /bin/ash 38400 tty1 2>/dev/null || sh
184 }
186 BIN=bin/mount.posixovl
187 [ -x /usr/s$BIN ] || mv /bin/mount.posixovl.iso2exe \
188 /usr/s$BIN 2>/dev/null || mv /bin/mount.posixovl.iso2exe /$BIN 2>/dev/null
189 mount_proc
190 for i in /sys/block/*/dev /sys/block/*/*/dev; do
191 [ -s "$i" ] || continue
192 n=${i%/dev}
193 n=/dev/${n##*/}
194 [ -e $n ] && continue
195 mknod $n b $(sed 's/:/ /' < $i)
196 done 2>/dev/null
197 ISO="$(getarg bootfrom | sed 's/.://;s|\\|/|g')"
198 getiso 2>/dev/null || text
199 mount_loram
200 [ -s /usr/bin/taziso ] || live
202 . /usr/bin/taziso