slitaz-tools view lib/libmountbox @ rev 262

mountbox: add floppies
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 23 21:22:49 2008 +0000 (2008-07-23)
parents db0e82bebc70
children 9fbb84b399ed
line source
1 #!/bin/sh
2 #
3 # Libmountbox provides devices list in suitable format for GTK tree
4 # and various dialog boxes to mount, umount, etc.
5 #
6 # (C) 2008 - SliTaz GNU/Linux project.
7 #
9 # Short usage.
10 usage()
11 {
12 echo -e "\nUsage: $0 command\n
13 Output commands:
14 list-mounted List all mounted devices in suitable GTK tree format.
15 list-umounted List all umounted in suitable GTK tree format.
17 GTKdialog boxes
18 mounted-fs-infos Display a mounted devices infos with actions.
19 umounted-fs-infos Display a umounted devices infos with actions.\n"
20 }
22 # Format df -h output for GTK tree.
23 mounted_fs_data()
24 {
25 SIZE=`echo $RES | cut -d " " -f 2`
26 USED=`echo $RES | cut -d " " -f 3`
27 AVAILABLE=`echo $RES | cut -d " " -f 4`
28 PCT=`echo $RES | cut -d " " -f 5`
29 MOUNTED_ON=`echo $RES | cut -d " " -f 6`
30 }
32 case $1 in
33 list-mounted)
34 # List all fs found by: df -h
35 #
36 for dev in `df -h | grep ^/dev/[c-s]d | cut -d " " -f 1`
37 do
38 RES=`df -h $dev | grep ^$dev`
39 mounted_fs_data
40 echo "$dev | $SIZE | $USED | $AVAILABLE | $PCT | $MOUNTED_ON"
41 done ;;
42 list-umounted)
43 # List all umounted fs found by: fdisk -l
44 #
45 for dev in `fdisk -l | grep ^/dev | cut -d " " -f 1`
46 do
47 RES=`fdisk -l | grep $dev | sed s/*//g`
48 START=`echo $RES | cut -d " " -f 2`
49 END=`echo $RES | cut -d " " -f 3`
50 BLOCKS=`echo $RES | cut -d " " -f 4`
51 ID=`echo $RES | cut -d " " -f 5`
52 SYSTEM=`echo $RES | cut -d " " -f 6-`
53 # Bootable...
54 if fdisk -l | grep $dev | grep -q "*"; then
55 BOOT="*"
56 else
57 BOOT="-"
58 fi
59 # Skip swap, extended, and mounted partitions.
60 if echo $RES | grep -q "swap" || echo $RES | grep -q "Extended" ; then
61 continue
62 elif mount | grep -q "^$dev "; then
63 continue
64 else
65 echo "$dev | $BOOT | $START | $END | $BLOCKS | $ID | $SYSTEM"
66 fi
67 done
68 echo "/dev/cdrom | - | - | - | CD/DVD | - | iso9660"
69 for i in /sys/devices/platform/floppy.*/block:*; do
70 [ -e $i ] && echo "/dev/${i#*block:} | - | - | - | floppy | - | linux"
71 done
72 ;;
73 mounted-fs-infos)
74 # Mounted fs info and actions, rootfs or other fs.
75 #
76 if [ "$MOUNTED" == "/dev/root" ]; then
77 export MOUNTED_DEVICE="
78 <window title=\"Device: rootfs\" icon-name=\"media-flash\">
79 <vbox>
80 <text use-markup=\"true\" width-chars=\"56\">
81 <label>\"
82 <b>/dev/root</b>
83 \"
84 </label>
85 </text>
86 <text use-markup=\"true\" width-chars=\"56\">
87 <input>df -h / | grep ^rootfs</input>
88 </text>
89 <hbox>
90 <button>
91 <label>Browse</label>
92 <input file icon=\"folder-open\"></input>
93 <action>pcmanfm / &</action>
94 <action type=\"closewindow\">MOUNTED_DEVICE</action>
95 </button>
96 <button>
97 <input file icon=\"gtk-close\"></input>
98 <action type=\"closewindow\">MOUNTED_DEVICE</action>
99 </button>
100 </hbox>
101 </vbox>
102 </window>"
103 gtkdialog --center --program=MOUNTED_DEVICE
104 else
105 UUID=`blkid | grep ^$MOUNTED | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'`
106 TYPE=`blkid | grep ^$MOUNTED | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'`
107 RES=`df -h $MOUNTED | grep ^$MOUNTED`
108 mounted_fs_data
109 export MOUNTED_DEVICE="
110 <window title=\"Device: $MOUNTED\" icon-name=\"media-flash\">
111 <vbox>
112 <text use-markup=\"true\" width-chars=\"56\">
113 <label>\"
114 Device <b>$MOUNTED</b> is mounted on <b>$MOUNTED_ON</b>
116 UUID: $UUID
117 Type: $TYPE
118 \"
119 </label>
120 </text>
121 <hbox>
122 <button>
123 <label>Browse</label>
124 <input file icon=\"folder-open\"></input>
125 <action>pcmanfm $MOUNTED_ON &</action>
126 <action type=\"closewindow\">MOUNTED_DEVICE</action>
127 </button>
128 <button>
129 <label>Umount</label>
130 <input file icon=\"undo\"></input>
131 <action>umount $MOUNTED_ON</action>
132 <action type=\"closewindow\">MOUNTED_DEVICE</action>
133 </button>
134 <button>
135 <input file icon=\"gtk-close\"></input>
136 <action type=\"closewindow\">MOUNTED_DEVICE</action>
137 </button>
138 </hbox>
139 </vbox>
140 </window>"
141 gtkdialog --center --program=MOUNTED_DEVICE
142 fi ;;
143 umounted-fs-infos)
144 # Mounted fs info and actions, rootfs or other fs.
145 #
146 UUID=`blkid | grep ^$DEVICE | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'`
147 TYPE=`blkid | grep ^$DEVICE | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'`
148 export UMOUNTED_DEVICE="
149 <window title=\"Device: $DEVICE\" icon-name=\"media-flash\">
150 <vbox>
151 <text use-markup=\"true\" width-chars=\"56\">
152 <label>\"
153 Mount <b>$DEVICE</b> on <b>$MOUNT_POINT</b>
155 UUID: $UUID
156 Type: $TYPE
157 \"
158 </label>
159 </text>
161 <hbox>
162 <button>
163 <label>Mount</label>
164 <input file icon=\"edit-redo\"></input>
165 <action>mkdir -p $MOUNT_POINT</action>
166 <action>mount $DEVICE $MOUNT_POINT</action>
167 <action type=\"closewindow\">MOUNTED_DEVICE</action>
168 </button>
170 <button>
171 <label>e2fsck check</label>
172 <input file icon=\"drive-harddisk\"></input>
173 <action>xterm -T \"e2fsck -p $DEVICE\" \
174 --geomery 80x12 \
175 -e \"echo; e2fsck -p $DEVICE; \
176 echo -e '----\nENTER to close Termianl'; \
177 read i\" &</action>
178 <action type=\"closewindow\">MOUNTED_DEVICE</action>
179 </button>
181 <button>
182 <input file icon=\"gtk-close\"></input>
183 <action type=\"closewindow\">UMOUNTED_DEVICE</action>
184 </button>
185 </hbox>
186 </vbox>
187 </window>"
188 gtkdialog --center --program=UMOUNTED_DEVICE ;;
189 *)
190 usage ;;
191 esac
193 exit 0