root/branches/livecd/LiveTools/rc.local.sh @ 599

Revision 599, 2.6 KB (checked in by balle, 4 years ago)

- add startup script for the live system

  • Property svn:executable set to *
Line 
1# workaround MATLAB problems
2#mkdir -p /mnt/rofs
3#ln -s /* /mnt/rofs/
4#mount --bind /mnt/rofs /rofs
5
6# Try to find a mindstorms.fat file in any local partition
7# If it exists, mount it to /home/mindstorms/work.
8# Also try to find mindstorms.swp files to use as swap space.
9
10mkdir -p /mnt/localfs /home/mindstorms/work
11chmod 700 /mnt
12
13shopt -s nullglob
14
15# Find boot-time plugged in USB drive to use
16for PART in /dev/disk/by-id/usb-*; do
17        [ "$( vol_id -t "$PART" )" = "vfat" ] || continue
18        mount -t vfat -o rw,uid=999,gid=999,fmask=0133,dmask=0022,iocharset=utf8 \
19                "$PART" /home/mindstorms/work && break
20done
21
22# Mount all partitions read-only
23for PART in /dev/disk/by-id/{ata,scsi}-*-part?; do
24        MOUNTPOINT="/mnt/localfs/${PART##*/}"
25        mkdir "$MOUNTPOINT" || continue
26        mount -o ro "$PART" "$MOUNTPOINT"
27done
28
29# If USB failed, try to find one mindstorms.dir directory
30if ! mountpoint -q /home/mindstorms/work; then
31        for DIR in /mnt/localfs/*/mindstorms.dir; do
32                MOUNTPOINT="${DIR%/*}"
33                if umount "$MOUNTPOINT"; then
34                        PART="/dev/disk/by-id/${MOUNTPOINT##*/}"
35                        if [ "$( vol_id -t "$PART" )" = "ntfs" ]; then
36                                mount -t ntfs-3g -o rw,no_def_opts,umask=077 "$PART" "$MOUNTPOINT" || continue
37                        else
38                                mount -o rw "$PART" "$MOUNTPOINT" || continue
39                        fi
40                fi
41                chown -R mindstorms.mindstorms "$DIR"
42                chmod -R u+rw "$DIR"
43                mount -o bind "$DIR" /home/mindstorms/work && break
44        done
45fi
46
47# If this also failed, try to find a mindstorms.fat file
48if ! mountpoint -q /home/mindstorms/work; then
49        for FAT in /mnt/localfs/*/mindstorms.fat; do
50                MOUNTPOINT="${FAT%/*}"
51                [ "$( vol_id -t "$FAT" )" = "vfat" ] || continue
52                if umount "$MOUNTPOINT"; then
53                        PART="/dev/disk/by-id/${MOUNTPOINT##*/}"
54                        if [ "$( vol_id -t "$PART" )" = "ntfs" ]; then
55                                mount -t ntfs-3g -o rw,no_def_opts,umask=077 "$PART" "$MOUNTPOINT" || continue
56                        else
57                                mount -o rw "$PART" "$MOUNTPOINT" || continue
58                        fi
59                fi
60                mount -t vfat -o loop,rw,uid=999,gid=999,fmask=0133,dmask=0022,iocharset=utf8 \
61                        "$FAT" /home/mindstorms/work && break
62        done
63fi
64
65# Try to find all mindstorms.swp files
66for SWP in /mnt/localfs/*/mindstorms.swp; do
67        MOUNTPOINT="${SWP%/*}"
68        PART="/dev/disk/by-id/${MOUNTPOINT##*/}"
69        if umount "$MOUNTPOINT"; then
70                if [ "$( vol_id -t "$PART" )" = "ntfs" ]; then
71                        mount -t ntfs-3g -o rw,no_def_opts,umask=077 "$PART" "$MOUNTPOINT" || continue
72                else
73                        mount -o rw "$PART" "$MOUNTPOINT" || continue
74                fi
75        fi
76        mkswap "$SWP" || continue
77        swapon "$SWP"
78done
79
80# Try to unmount all unused partitions
81for PART in /mnt/localfs/*; do
82        umount "$PART" 2>/dev/null
83done
84
85# Remove work directory if not mounted
86if ! mountpoint -q /home/mindstorms/work; then
87        rm -rf /home/mindstorms/work
88fi
Note: See TracBrowser for help on using the browser.