wok annotate syslinux/stuff/iso2exe/init @ rev 23962

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