sync with linuxport @ 18013
[xbmc:xbmc-antiquated.git] / tools / XBMCLive / Creator / platforms / i386-intrepid-xbmc / initramfs / disk
1 #!/bin/bash
2 # Unified squash Hard Disk filesystem mounting            -*- shell-script -*-
3
4 #Function for parsing command line options with "=" in them
5 # get_opt("init=/sbin/init") will return "/sbin/init"
6 get_opt() {
7     echo "$@" | cut -d "=" -f 2
8 }
9
10 mountroot ()
11 {
12     CFG_FILE=/etc/moblin-initramfs.cfg
13     QUIET="$(grep "quiet" /proc/cmdline)"
14
15     if [ -f ${CFG_FILE} ]
16     then
17         . ${CFG_FILE}
18     else
19         if [ "$QUIET" == "" ]; then
20                 echo "Did not find config file: ${CFG_FILE}"
21         fi
22         sleep 5
23         halt
24     fi
25
26
27     CMDLINE=$(cat /proc/cmdline)
28
29     #Process command line options
30     XBMC_PARAMS=""
31     for i in ${CMDLINE}; do
32         case "${i}" in
33             xbmc\=*)
34                 XBMC_PARAMS=$(get_opt $i)
35                 ;;
36         esac
37     done
38
39     AUTOGPU="$( echo $XBMC_PARAMS | grep "autogpu" )"
40
41     if [ "$AUTOGPU" != "" ]; then
42         if [ "$QUIET" = "" ]; then
43              echo "found auto"
44         fi
45         XBMC_AMD="$(lspci -nn | grep 0300 | grep 1002)"
46         XBMC_NVIDIA="$(lspci -nn | grep 0300 | grep 10de)"
47     else
48         XBMC_NVIDIA="$( echo $XBMC_PARAMS | grep "nvidia" )"
49         XBMC_AMD="$( echo $XBMC_PARAMS | grep "amd" )"
50     fi
51
52     if [ "$XBMC_NVIDIA" != "" ]; then
53            if [ "$QUIET" = "" ]; then
54                echo "Mounting NVIDIA drivers..."
55            fi
56     else
57         if [ "$XBMC_AMD" != "" ]; then
58             if [ "$QUIET" = "" ]; then
59                 echo "Mounting AMD drivers..."
60             fi
61         else
62            # No Ops for Intel as of today
63             if [ "$QUIET" = "" ]; then
64                 echo "Defaulting to Xorg autodetect..."
65             fi
66         fi
67     fi
68
69
70         mkdir -p /mnt
71         mkdir -p /squashmnt1
72         mkdir -p /squashmnt2
73         mkdir -p /squashmnt3
74         mkdir -p /persistmnt
75
76     # Find the boot disk
77     while true; do
78       for device in 'hda' 'hdb' 'sda' 'sdb'; do
79         if [ "$QUIET" == "" ]; then
80                 echo "checking device /dev/${device}"
81         fi
82         if [ -e /sys/block/${device}/removable ]; then
83            if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then
84                 if [ "$QUIET" == "" ]; then
85                       echo "found harddisk at /dev/${device}"
86                 fi
87
88               found="yes"
89               break
90            fi
91          fi
92       done
93       if [ "$found" = "yes" ]; then
94         break;
95       fi
96       /bin/sleep 5
97     done
98
99     # try to resume first
100     if [ "$QUIET" == "" ]; then
101             echo "Attempting to resume from hibernation..."
102     fi
103
104     # /bin/resume /dev/${device}2
105
106     # if the resume succeeded then we won't get to here, so if we have got here
107     # then resume did NOT succeed, which is okay.
108     if [ "$QUIET" == "" ]; then
109             echo "Will mount root from /dev/${device}"
110     fi
111
112
113         # We are using squashfs
114         if [ "$QUIET" == "" ]; then
115                 echo "Setting up our squashfs and ext3fs unionfs system..."
116         fi
117
118         mount -o rw /dev/${device}1 /mnt
119         while [ ! -e "/mnt/rootfs.img" ]
120         do
121             if [ "$QUIET" == "" ]; then
122                    echo "Did not find /mnt/rootfs.img"
123                     echo "sleeping for 0.5 seconds..."
124             fi
125             /bin/sleep 0.5
126             if [ "$QUIET" == "" ]; then
127                 echo "Mount root from /dev/${device}1..."
128             fi
129             mount -o rw /dev/${device}1 /mnt
130         done
131
132         mount -o ro,loop -t squashfs /mnt/rootfs.img /squashmnt1
133
134         if [ "$XBMC_NVIDIA" != "" ]; then
135             if [ -f /mnt/restrictedDrivers.nvidia.img ]; then
136                if [ "$QUIET" = "" ]; then
137                    echo "Mounting NVIDIA drivers..."
138                fi
139                mount -o ro,loop,noatime,nodiratime /mnt/restrictedDrivers.nvidia.img /squashmnt2
140             fi
141         else
142             if [ "$XBMC_AMD" != "" ]; then
143                 if [ -f /mnt/restrictedDrivers.amd.img ]; then
144                     if [ "$QUIET" = "" ]; then
145                         echo "Mounting AMD drivers..."
146                     fi
147                     mount -o ro,loop,noatime,nodiratime /mnt/restrictedDrivers.amd.img /squashmnt2
148                 fi
149             else
150                 # No Ops for Intel as of today
151                 mount -t tmpfs -o noatime,nodiratime none /squashmnt2
152
153                 if [ "$QUIET" = "" ]; then
154                     echo "Defaulting to Xorg autodetect..."
155                 fi
156             fi
157         fi
158
159         if [ -f /mnt/ext3fs.img ]; then
160             mount -o rw,loop,noatime,nodiratime /mnt/ext3fs.img /persistmnt
161         else
162             mount -t tmpfs -o noatime,nodiratime none /persistmnt
163         fi
164         mount -t unionfs -o dirs=/persistmnt=rw:/squashmnt2=ro:/squashmnt1=ro none ${rootmnt}
165
166     if [ -f /mnt/config/fstab ]; then
167         mv /mnt/config/fstab ${rootmnt}/etc
168     fi
169
170     if [ -f /mnt/ext3fs.img ]; then
171         XBMC_TEMPFS="$( echo $XBMC_PARAMS | grep "tempfs" )"
172         if [ "$XBMC_TEMPFS" != "" ]; then
173             echo "tmpfs /var/log/apt   tmpfs defaults 0 0" >> ${rootmnt}/etc/fstab
174             echo "tmpfs /var/log       tmpfs defaults 0 0" >> ${rootmnt}/etc/fstab
175             echo "tmpfs /tmp           tmpfs defaults 0 0" >> ${rootmnt}/etc/fstab
176             echo "tmpfs /var/tmp       tmpfs defaults 0 0" >> ${rootmnt}/etc/fstab
177         fi
178     fi
179
180     if [ -f /mnt/config/shadow ]; then
181         mv /mnt/config/shadow ${rootmnt}/etc
182         chmod 640 ${rootmnt}/etc/shadow
183     fi
184
185     if [ -f /mnt/config/xorg.conf ]; then
186         mv /mnt/config/xorg.conf ${rootmnt}/etc/X11
187     fi
188
189     if [ -f /mnt/config/lircd.conf ]; then
190         mv/mnt/config/lircd.conf ${rootmnt}/etc/lirc
191     fi
192
193     if [ -f /mnt/config/hardware.conf ]; then
194         mv /mnt/config/hardware.conf ${rootmnt}/etc/lirc
195     fi
196
197     if [ -f /mnt/config/interfaces ]; then
198         mv /mnt/config/interfaces ${rootmnt}/etc/network
199     fi
200 }
201