slitaz-tools view lib/libmountbox @ rev 276

Moved torrentbox to ctorrent-dnh
author Christophe Lincoln <pankso@slitaz.org>
date Tue Nov 25 15:51:10 2008 +0100 (2008-11-25)
parents 426e821a7516
children b872243c81ab
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 UUID=`blkid | grep ^$dev | grep UUID= | sed 's/.*UUID=\"\([^\"]*\)\".*/\1/'`
66 TYPE=`blkid | grep ^$dev | grep TYPE= | sed 's/.*TYPE=\"\([^\"]*\)\".*/\1/'`
67 LABEL=`blkid | grep ^$dev | grep LABEL= | sed 's/.*LABEL=\"\([^\"]*\)\".*/\1/'`
68 echo "$dev | $BOOT | $START | $END | $BLOCKS | $ID | $SYSTEM | $TYPE | $LABEL | $UUID"
69 fi
70 done
71 echo "/dev/cdrom | - | - | - | CD/DVD | - | iso9660 | - | - | -"
72 for i in /sys/devices/platform/floppy.*/block:*; do
73 [ -e $i ] && echo "/dev/${i#*block:} | - | - | - | floppy | - | - | - | - | -"
74 done
75 ;;
76 mounted-fs-infos)
77 # Mounted fs info and actions, rootfs or other fs.
78 #
79 if [ "$MOUNTED" == "/dev/root" ]; then
80 export MOUNTED_DEVICE="
81 <window title=\"Device: rootfs\" icon-name=\"media-flash\">
82 <vbox>
83 <text use-markup=\"true\" width-chars=\"56\">
84 <label>\"
85 <b>/dev/root</b>
86 \"
87 </label>
88 </text>
89 <text use-markup=\"true\" width-chars=\"56\">
90 <input>df -h / | grep ^rootfs</input>
91 </text>
92 <hbox>
93 <button>
94 <label>Browse</label>
95 <input file icon=\"folder-open\"></input>
96 <action>pcmanfm / &</action>
97 <action type=\"closewindow\">MOUNTED_DEVICE</action>
98 </button>
99 <button>
100 <input file icon=\"gtk-close\"></input>
101 <action type=\"closewindow\">MOUNTED_DEVICE</action>
102 </button>
103 </hbox>
104 </vbox>
105 </window>"
106 gtkdialog --center --program=MOUNTED_DEVICE
107 else
108 UUID=`blkid | grep ^$MOUNTED | grep UUID= | sed 's/.*UUID=\"\([^\"]*\)\".*/\1/'`
109 TYPE=`blkid | grep ^$MOUNTED | grep TYPE= | sed 's/.*TYPE=\"\([^\"]*\)\".*/\1/'`
110 LABEL=`blkid | grep ^$MOUNTED | grep LABEL= | sed 's/.*LABEL=\"\([^\"]*\)\".*/\1/'`
111 RES=`df -h $MOUNTED | grep ^$MOUNTED`
112 mounted_fs_data
113 export MOUNTED_DEVICE="
114 <window title=\"Device: $MOUNTED\" icon-name=\"media-flash\">
115 <vbox>
116 <text use-markup=\"true\" width-chars=\"56\">
117 <label>\"
118 Device <b>$MOUNTED</b> is mounted on <b>$MOUNTED_ON</b>
120 UUID: $UUID
121 Type: $TYPE
122 Label: $LABEL
123 \"
124 </label>
125 </text>
126 <hbox>
127 <button>
128 <label>Browse</label>
129 <input file icon=\"folder-open\"></input>
130 <action>pcmanfm $MOUNTED_ON &</action>
131 <action type=\"closewindow\">MOUNTED_DEVICE</action>
132 </button>
133 <button>
134 <label>Umount</label>
135 <input file icon=\"undo\"></input>
136 <action>umount $MOUNTED_ON</action>
137 <action type=\"closewindow\">MOUNTED_DEVICE</action>
138 </button>
139 <button>
140 <input file icon=\"gtk-close\"></input>
141 <action type=\"closewindow\">MOUNTED_DEVICE</action>
142 </button>
143 </hbox>
144 </vbox>
145 </window>"
146 gtkdialog --center --program=MOUNTED_DEVICE
147 fi ;;
148 umounted-fs-infos)
149 # Mounted fs info and actions, rootfs or other fs.
150 #
151 UUID=`blkid | grep ^$MOUNTED | grep UUID= | sed 's/.*UUID=\"\([^\"]*\)\".*/\1/'`
152 TYPE=`blkid | grep ^$MOUNTED | grep TYPE= | sed 's/.*TYPE=\"\([^\"]*\)\".*/\1/'`
153 LABEL=`blkid | grep ^$MOUNTED | grep LABEL= | sed 's/.*LABEL=\"\([^\"]*\)\".*/\1/'`
154 export UMOUNTED_DEVICE="
155 <window title=\"Device: $DEVICE\" icon-name=\"media-flash\">
156 <vbox>
157 <text use-markup=\"true\" width-chars=\"56\">
158 <label>\"
159 Mount <b>$DEVICE</b> on <b>$MOUNT_POINT</b>
161 UUID: $UUID
162 Type: $TYPE
163 Label: $LABEL
164 \"
165 </label>
166 </text>
168 <hbox>
169 <button>
170 <label>Mount</label>
171 <input file icon=\"edit-redo\"></input>
172 <action>mkdir -p $MOUNT_POINT</action>
173 <action>mount $DEVICE $MOUNT_POINT</action>
174 <action type=\"closewindow\">MOUNTED_DEVICE</action>
175 </button>
177 <button>
178 <label>e2fsck check</label>
179 <input file icon=\"drive-harddisk\"></input>
180 <action>xterm -T \"e2fsck -p $DEVICE\" \
181 --geomery 80x12 \
182 -e \"echo; e2fsck -p $DEVICE; \
183 echo -e '----\nENTER to close Termianl'; \
184 read i\" &</action>
185 <action type=\"closewindow\">MOUNTED_DEVICE</action>
186 </button>
188 <button>
189 <input file icon=\"gtk-close\"></input>
190 <action type=\"closewindow\">UMOUNTED_DEVICE</action>
191 </button>
192 </hbox>
193 </vbox>
194 </window>"
195 gtkdialog --center --program=UMOUNTED_DEVICE ;;
196 *)
197 usage ;;
198 esac
200 exit 0