* updated libkcddb (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / target / share / livecd / init
blob5ba81391a9ae72e589f2878bb5f46ad58e7e162f
1 #!/bin/sh
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 #
5 # T2 SDE: target/share/livecd/init
6 # Copyright (C) 2020 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
17 live="live=live.squash `cat /proc/cmdline`" ; live=${live##*live=} ; live=${live%% *}
18 echo "Searching for media with $live image ..."
19 mkdir -p /{media,mnt}/live
20 i=0
21 while [ $i -le 14 ]; do
22 for x in /sys/block/*/device; do
23 x=${x%/device}; x=${x#/sys/block/}
24 [ "$x" = "*" ] && continue
25 # TODO: make option to skip fixed devices
26 #case "`ls -l /sys/block/$x/device`" in
27 # */usb*|*/ieee1394) : ;;
28 # *) [ "`cat /sys/block/$x/removable`" = 1 ] || continue ;;
29 #esac
30 x=/dev/$x
31 for x in ${x}* ; do
32 [ -e $x ] || continue
33 fs=`disktype $x 2>/dev/null |
34 sed -e '/file system/!d' -e 's/file system.*//' -e 's/ //g' \
35 -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \
36 -e 's/fat.*/vfat/' | sed -n '$p'`
37 [ $i -gt 2 ] && echo "Testing device $x, type $fs ..."
38 if mount -t $fs -o ro $x /media/live 2>/dev/null; then
39 [ $i -gt 0 ] && echo "Successfully mounted $x ..."
40 if [ -f /media/live/$live ]; then
41 echo "Found the $live image on $x."
43 if losetup /dev/loop0 /media/live/$live &&
44 mount -t squashfs -o ro /dev/loop0 /mnt/live
45 then
46 kill %1
48 # setup final directory structure
49 mkdir -p /tmp/bin
50 mv /lib /tmp/
51 mv /bin/* /sbin/* /tmp/bin/
52 for x in /mnt/live/* ; do
53 x=${x#/mnt/live/}
54 case $x in
55 dev|proc|sys|media|mnt|tmp) continue ;;
56 esac
57 if [ -e /$x ]; then
58 # echo "Removing /$x ..."
59 /tmp/bin/rm -rf /$x
61 # echo "Sym-linking /mnt/live/$x /$x"
62 /tmp/bin/ln -s /mnt/live/$x /$x
63 done
65 # /tmp/bin/ls -l / /tmp
66 # /tmp/bin/rm -rf /tmp/bin
68 exec /init2 $*
69 else
70 echo "Failed to loop-mount $live."
71 losetup -d /dev/loop0
73 else
74 echo "No $live image found."
76 umount /media/live
78 done
79 done
80 : $(( i++ ))
81 sleep 1
82 done
84 echo "No live media found, giving up. Debug shell:"
85 exec /bin/sh