slitaz-tools rev 183
Rewrited 'mountbox', better inerface, gen list automaicaly, add e2fsck and more...
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun May 11 00:25:10 2008 +0200 (2008-05-11) |
parents | 793899873acd |
children | 8fc4218a0995 |
files | lib/README lib/libmountbox tinyutils/mountbox |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/lib/README Sun May 11 00:25:10 2008 +0200 1.3 @@ -0,0 +1,8 @@ 1.4 + 1.5 + 1.6 +SliTaz tools, tinyutils and GTKboxes libraries and functions. On the 1.7 +system, all libs goes in: /usr/lib/slitaz. Some libs have a usage and 1.8 +can be called diretly from the command line, example: 1.9 + 1.10 + # /usr/lib/slitaz/libmountbox usage 1.11 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/lib/libmountbox Sun May 11 00:25:10 2008 +0200 2.3 @@ -0,0 +1,188 @@ 2.4 +#!/bin/sh 2.5 +# 2.6 +# Libmountbox provide devices list in suitable format for GTK tree 2.7 +# and varius dialog boxes to mount, umount, etc. 2.8 +# 2.9 +# (C) 2008 - SliTaz GNU/Linux project. 2.10 +# 2.11 + 2.12 +# Short usage. 2.13 +usage() 2.14 +{ 2.15 + echo -e "\nUsage: $0 command\n 2.16 +Outpout commads: 2.17 + list-mounted List all mounted devices in suitable GTK tree format. 2.18 + list-umounted List all umounted in suitable GTK tree format. 2.19 + 2.20 +GTKdialog boxes 2.21 + mounted-fs-infos Display a mounted devices infos with actions. 2.22 + umounted-fs-infos Display a umounted devices infos with actions.\n" 2.23 +} 2.24 + 2.25 +# Format df -h output fot GTK tree. 2.26 +mounted_fs_data() 2.27 +{ 2.28 + SIZE=`echo $RES | cut -d " " -f 2` 2.29 + USED=`echo $RES | cut -d " " -f 3` 2.30 + AVAILABLE=`echo $RES | cut -d " " -f 4` 2.31 + PCT=`echo $RES | cut -d " " -f 5` 2.32 + MOUNTED_ON=`echo $RES | cut -d " " -f 6` 2.33 +} 2.34 + 2.35 +case $1 in 2.36 + list-mounted) 2.37 + # List all fs found by: df -h 2.38 + # 2.39 + for dev in `df -h | grep ^/dev/[c-s]d | cut -d " " -f 1` 2.40 + do 2.41 + RES=`df -h $dev | grep ^$dev` 2.42 + mounted_fs_data 2.43 + echo "$dev | $SIZE | $USED | $AVAILABLE | $PCT | $MOUNTED_ON" 2.44 + done ;; 2.45 + list-umounted) 2.46 + # List all umounted fs found by: fdisk -l 2.47 + # 2.48 + for dev in `fdisk -l | grep ^/dev | cut -d " " -f 1` 2.49 + do 2.50 + RES=`fdisk -l | grep $dev | sed s/*//g` 2.51 + START=`echo $RES | cut -d " " -f 2` 2.52 + END=`echo $RES | cut -d " " -f 3` 2.53 + BLOCKS=`echo $RES | cut -d " " -f 4` 2.54 + ID=`echo $RES | cut -d " " -f 5` 2.55 + SYSTEM=`echo $RES | cut -d " " -f 6` 2.56 + # Bootable... 2.57 + if fdisk -l | grep $dev | grep -q "*"; then 2.58 + BOOT="*" 2.59 + else 2.60 + BOOT="-" 2.61 + fi 2.62 + # Skip swap, extended part and mounted. 2.63 + if echo $RES | grep -q "swap" || echo $RES | grep -q "Extended" ; then 2.64 + continue 2.65 + elif mount | grep -q "^$dev"; then 2.66 + continue 2.67 + else 2.68 + echo "$dev | $BOOT | $START | $END | $BLOCKS | $ID | $SYSTEM" 2.69 + fi 2.70 + done ;; 2.71 + mounted-fs-infos) 2.72 + # Mounted fs infos and actions, rootfs or other fs. 2.73 + # 2.74 + if [ "$MOUNTED" == "/dev/root" ]; then 2.75 + export MOUNTED_DEVICE=" 2.76 +<window title=\"Device: rootfs\" icon-name=\"media-flash\"> 2.77 +<vbox> 2.78 + <text use-markup=\"true\" width-chars=\"56\"> 2.79 + <label>\" 2.80 +<b>/dev/root</b> 2.81 +\" 2.82 + </label> 2.83 + </text> 2.84 + <text use-markup=\"true\" width-chars=\"56\"> 2.85 + <input>df -h / | grep ^rootfs</input> 2.86 + </text> 2.87 + <hbox> 2.88 + <button> 2.89 + <label>Browse</label> 2.90 + <input file icon=\"folder-open\"></input> 2.91 + <action>pcmanfm / &</action> 2.92 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.93 + </button> 2.94 + <button> 2.95 + <input file icon=\"gtk-close\"></input> 2.96 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.97 + </button> 2.98 + </hbox> 2.99 +</vbox> 2.100 +</window>" 2.101 + gtkdialog --center --program=MOUNTED_DEVICE 2.102 + else 2.103 + UUID=`blkid | grep ^$MOUNTED | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'` 2.104 + TYPE=`blkid | grep ^$MOUNTED | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'` 2.105 + RES=`df -h $MOUNTED | grep ^$MOUNTED` 2.106 + mounted_fs_data 2.107 + export MOUNTED_DEVICE=" 2.108 +<window title=\"Device: $MOUNTED\" icon-name=\"media-flash\"> 2.109 +<vbox> 2.110 + <text use-markup=\"true\" width-chars=\"56\"> 2.111 + <label>\" 2.112 +Device <b>$MOUNTED</b> is mounted on <b>$MOUNTED_ON</b> 2.113 + 2.114 +UUID: $UUID 2.115 +Type: $TYPE 2.116 +\" 2.117 + </label> 2.118 + </text> 2.119 + <hbox> 2.120 + <button> 2.121 + <label>Browse</label> 2.122 + <input file icon=\"folder-open\"></input> 2.123 + <action>pcmanfm $MOUNTED_ON &</action> 2.124 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.125 + </button> 2.126 + <button> 2.127 + <label>Umount</label> 2.128 + <input file icon=\"undo\"></input> 2.129 + <action>umount $MOUNTED_ON</action> 2.130 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.131 + </button> 2.132 + <button> 2.133 + <input file icon=\"gtk-close\"></input> 2.134 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.135 + </button> 2.136 + </hbox> 2.137 +</vbox> 2.138 +</window>" 2.139 + gtkdialog --center --program=MOUNTED_DEVICE 2.140 + fi ;; 2.141 + umounted-fs-infos) 2.142 + # Mounted fs infos and actions, rootfs or other fs. 2.143 + # 2.144 + UUID=`blkid | grep ^$DEVICE | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'` 2.145 + TYPE=`blkid | grep ^$DEVICE | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'` 2.146 + export UMOUNTED_DEVICE=" 2.147 +<window title=\"Device: $DEVICE\" icon-name=\"media-flash\"> 2.148 +<vbox> 2.149 + <text use-markup=\"true\" width-chars=\"56\"> 2.150 + <label>\" 2.151 +Mount <b>$DEVICE</b> on <b>$MOUNT_POINT</b> 2.152 + 2.153 +UUID: $UUID 2.154 +Type: $TYPE 2.155 +\" 2.156 + </label> 2.157 + </text> 2.158 + 2.159 + <hbox> 2.160 + <button> 2.161 + <label>Mount</label> 2.162 + <input file icon=\"edit-redo\"></input> 2.163 + <action>mkdir -p $MOUNT_POINT</action> 2.164 + <action>mount $DEVICE $MOUNT_POINT</action> 2.165 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.166 + </button> 2.167 + 2.168 + <button> 2.169 + <label>e2fsck check</label> 2.170 + <input file icon=\"drive-harddisk\"></input> 2.171 + <action>xterm -T \"e2fsck -p $DEVICE\" \ 2.172 + --geomery 80x12 \ 2.173 + -e \"echo; e2fsck -p $DEVICE; \ 2.174 + echo -e '----\nENTER to close Termianl'; \ 2.175 + read i\" &</action> 2.176 + <action type=\"closewindow\">MOUNTED_DEVICE</action> 2.177 + </button> 2.178 + 2.179 + <button> 2.180 + <input file icon=\"gtk-close\"></input> 2.181 + <action type=\"closewindow\">UMOUNTED_DEVICE</action> 2.182 + </button> 2.183 + </hbox> 2.184 +</vbox> 2.185 +</window>" 2.186 + gtkdialog --center --program=UMOUNTED_DEVICE ;; 2.187 + *) 2.188 + usage ;; 2.189 +esac 2.190 + 2.191 +exit 0
3.1 --- a/tinyutils/mountbox Fri May 09 20:36:03 2008 +0000 3.2 +++ b/tinyutils/mountbox Sun May 11 00:25:10 2008 +0200 3.3 @@ -1,163 +1,167 @@ 3.4 -#! /bin/sh 3.5 +#!/bin/sh 3.6 # 3.7 -# Gtkdialog box for the mount command. Part of SliTaz tools. 3.8 +# Gtkdialog box for the mount/umount commands. Part of SliTaz tools. 3.9 +# libmountbox: /usr/lib/slitaz/libmountbox 3.10 # 3.11 -VERSION=20080113 3.12 +# (C) 2008 - SliTaz GNU/Linux project. 3.13 +# 3.14 +VERSION=20080510 3.15 3.16 -# Check if user is root. 3.17 -check_root() 3.18 -{ 3.19 - if test $(id -u) != 0 ; then 3.20 - echo -e " 3.21 -You must be root to run `basename $0`. Please type 'su' and 3.22 -root password to become super-user.\n" 3.23 - exit 0 3.24 - fi 3.25 -} 3.26 +# Mountbox is only for root. 3.27 +if test $(id -u) != 0 ; then 3.28 + exec subox mountbox 3.29 + exit 0 3.30 +fi 3.31 3.32 -export FDISK_LIST=' 3.33 -<window title="Fdisk -l" icon-name="media-flash"> 3.34 - <vbox> 3.35 - <text use-markup="true"> 3.36 - <label>" 3.37 -<b>Harddisk devices list</b>" 3.38 - </label> 3.39 - </text> 3.40 - <frame Partitions table> 3.41 - <text wrap="false" width-chars="58"> 3.42 - <input>fdisk -l | grep ^/dev</input> 3.43 - </text> 3.44 - </frame> 3.45 - <hbox> 3.46 - <button> 3.47 - <input file icon="exit"></input> 3.48 - <action type="closewindow">FDISK_LIST</action> 3.49 - </button> 3.50 - </hbox> 3.51 - </vbox> 3.52 -</window> 3.53 -' 3.54 +# Commom mount point in /mnt 3.55 +mkdir -p /mnt/harddisk 3.56 3.57 -export MOUNTED=' 3.58 -<window title="Mounted devices" icon-name="media-flash"> 3.59 - <vbox> 3.60 - <text use-markup="true"> 3.61 - <label>" 3.62 -<b>Mounted devices list</b>" 3.63 - </label> 3.64 - </text> 3.65 - <frame Devices and mount points> 3.66 - <text wrap="false" width-chars="58"> 3.67 - <input>mount | grep ^/dev/[c-s]d</input> 3.68 - </text> 3.69 - </frame> 3.70 - <hbox> 3.71 - <button> 3.72 - <input file icon="exit"></input> 3.73 - <action type="closewindow">MOUNTED</action> 3.74 - </button> 3.75 - </hbox> 3.76 - </vbox> 3.77 -</window> 3.78 -' 3.79 +# Just basic help. 3.80 +export HELP=' 3.81 +<window title="Mountbox - Help" icon-name="help"> 3.82 +<vbox> 3.83 + <text use-markup="true" width-chars="56"> 3.84 + <label>" 3.85 +<b>SliTaz Mountbox - Help</b>" 3.86 + </label> 3.87 + </text> 3.88 + 3.89 + <frame English> 3.90 + <text wrap="true" use-markup="true"> 3.91 + <label> 3.92 +"Mountbox let you mount devices on mount points. Device 3.93 +can be cdrom, flash key, USB disk or local HD partitions. 3.94 +Mount points are generated from /media and /mnt. 3.95 +" 3.96 + </label> 3.97 + </text> 3.98 + </frame> 3.99 + <frame Français> 3.100 + <text wrap="true" use-markup="true"> 3.101 + <label> 3.102 +"Mountbox permet de monter des périphériques (devices) 3.103 +sur des points de montage. Un device peut être un cdrom, 3.104 +une clé USB ou un disque dur local. La liste des points 3.105 +de montage est généré depuis /media te /mnt. 3.106 +" 3.107 + </label> 3.108 + </text> 3.109 + </frame> 3.110 + 3.111 + <hbox> 3.112 + <button ok> 3.113 + <action type="closewindow">HELP</action> 3.114 + </button> 3.115 + </hbox> 3.116 +</vbox> 3.117 +</window>' 3.118 3.119 # Mount and umount buttons with fiel for devive and mount point. 3.120 -# 3.121 -export MOUNT_DIALOG=' 3.122 +MAIN_DIALOG=' 3.123 <window title="Mountbox" icon-name="media-flash"> 3.124 - <vbox> 3.125 - 3.126 - <text use-markup="true"> 3.127 - <label> 3.128 -" 3.129 -<b>SliTaz - Mountbox</b>" 3.130 - </label> 3.131 - </text> 3.132 - <text wrap="true" width-chars="44" use-markup="true"> 3.133 - <label> 3.134 -" 3.135 -Mount device on a mount point. Device can be cdrom, 3.136 -flash key, USB disk or local HD partitions. 3.137 -" 3.138 - </label> 3.139 - </text> 3.140 - 3.141 - <frame Configuration> 3.142 - <hbox> 3.143 - <text use-markup="true"> 3.144 - <label>"<b>Device : </b>"</label> 3.145 - </text> 3.146 - <combobox> 3.147 - <variable>DEVICE</variable> 3.148 - <item>/dev/cdrom</item>' 3.149 -for i in $(awk '{ if ($4 != "name" && $4 != "") print $4 }' < /proc/partitions); 3.150 +<vbox> 3.151 + 3.152 + <tree> 3.153 + <width>520</width><height>120</height> 3.154 + <variable>MOUNTED</variable> 3.155 + <label>Mounted fs|Size|Used|Available|Use%|Mounted on</label>' 3.156 + 3.157 +# /dev/root 3.158 +RES=`df -h / | grep rootfs` 3.159 +dev="/dev/root" 3.160 +SIZE=`echo $RES | cut -d " " -f 2` 3.161 +USED=`echo $RES | cut -d " " -f 3` 3.162 +AVAILABLE=`echo $RES | cut -d " " -f 4` 3.163 +PCT=`echo $RES | cut -d " " -f 5` 3.164 +MOUNTED_ON=`echo $RES | cut -d " " -f 6` 3.165 +ROOT_ITEM=" 3.166 + <item icon=\"drive-harddisk\">$dev | $SIZE | $USED | $AVAILABLE | $PCT | $MOUNTED_ON</item>" 3.167 +MAIN_DIALOG=${MAIN_DIALOG}${ROOT_ITEM} 3.168 + 3.169 +# Now we have rootfs and icons, list all mounted fs. 3.170 +DEVICE='<input>/usr/lib/slitaz/libmountbox list-mounted</input> 3.171 + <action>/usr/lib/slitaz/libmountbox mounted-fs-infos</action> 3.172 + <action>refresh:MOUNTED</action> 3.173 + <action>refresh:DEVICE</action> 3.174 + </tree> 3.175 + 3.176 + <tree> 3.177 + <width>500</width><height>120</height> 3.178 + <variable>DEVICE</variable> 3.179 + <label>Umounted dev|Boot|Start|End|Blocks|Id|System</label> 3.180 + <item icon="drive-harddisk">/dev/cdrom | - | - | - | CD/DVD | - | iso9660</item> 3.181 + <input>/usr/lib/slitaz/libmountbox list-umounted</input> 3.182 + <action>/usr/lib/slitaz/libmountbox umounted-fs-infos</action> 3.183 + <action>refresh:MOUNTED</action> 3.184 + <action>refresh:DEVICE</action> 3.185 + </tree> 3.186 + <text use-markup="true"> 3.187 + <label>"<b>Mount selected device on:</b>"</label> 3.188 + </text> 3.189 + <hbox> 3.190 + <combobox> 3.191 + <variable>MOUNT_POINT</variable>' 3.192 + 3.193 +# Get the mount points list. 3.194 +MAIN_DIALOG=${MAIN_DIALOG}${DEVICE} 3.195 +for dir in $(ls -d /media/* /mnt/*) 3.196 do 3.197 - MOUNT_DIALOG="$MOUNT_DIALOG<item>/dev/$i</item>" 3.198 + MOUNT_POINTS_ITEMS="<item>$dir</item>" 3.199 + MAIN_DIALOG=${MAIN_DIALOG}${MOUNT_POINTS_ITEMS} 3.200 done 3.201 -tmp='</combobox> 3.202 - <button> 3.203 - <label>List</label> 3.204 - <input file icon="drive-harddisk"></input> 3.205 - <action type="launch">FDISK_LIST</action> 3.206 - </button> 3.207 - </hbox> 3.208 - 3.209 - <hbox> 3.210 - <text use-markup="true"> 3.211 - <label>"<b>Mount point : </b>"</label> 3.212 - </text> 3.213 - <combobox> 3.214 - <variable>MOUNT_POINT</variable>' 3.215 -MOUNT_DIALOG="$MOUNT_DIALOG$tmp" 3.216 -for i in $(ls -d /media/* /mnt/*); do 3.217 - MOUNT_DIALOG="$MOUNT_DIALOG<item>$i</item>" 3.218 -done 3.219 -tmp='</combobox> 3.220 - <button> 3.221 - <label>List</label> 3.222 - <input file icon="drive-harddisk"></input> 3.223 - <action type="launch">MOUNTED</action> 3.224 - </button> 3.225 - </hbox> 3.226 - </frame> 3.227 - 3.228 - <hbox> 3.229 - <button> 3.230 - <label>Mount</label> 3.231 - <input file icon="forward"></input> 3.232 - <action>echo "Mounting $DEVICE..."</action> 3.233 - <action>mkdir -p $MOUNT_POINT; mount $DEVICE $MOUNT_POINT; sleep 1</action> 3.234 - <action>mount | grep $DEVICE; echo "Done."</action> 3.235 - </button> 3.236 - <button> 3.237 - <label>Umount</label> 3.238 - <input file icon="undo"></input> 3.239 - <action>echo "Unmounting $MOUNT_POINT..."</action> 3.240 - <action>umount $MOUNT_POINT; sleep 1</action> 3.241 - <action>mount | grep $DEVICE; echo "Done."</action> 3.242 - </button> 3.243 - <button> 3.244 - <label>Browse</label> 3.245 - <input file icon="folder"></input> 3.246 - <action>pcmanfm $MOUNT_POINT</action> 3.247 - </button> 3.248 - <button> 3.249 - <label>Eject</label> 3.250 - <input file icon="media-cdrom"></input> 3.251 - <action>eject</action> 3.252 - </button> 3.253 - <button> 3.254 - <input file icon="exit"></input> 3.255 - <action type="exit">Exit</action> 3.256 - </button> 3.257 - </hbox> 3.258 - </vbox> 3.259 -</window> 3.260 -' 3.261 -MOUNT_DIALOG="$MOUNT_DIALOG$tmp" 3.262 3.263 -# Only root can mount. 3.264 -check_root 3.265 -gtkdialog --center --program=MOUNT_DIALOG 3.266 +# Actions buttons (moun, umount, eject, etc). 3.267 +ACTIONS=' 3.268 + </combobox> 3.269 + <button> 3.270 + <label>Browse</label> 3.271 + <input file icon="folder-open"></input> 3.272 + <action>pcmanfm $MOUNT_POINT &</action> 3.273 + </button> 3.274 + </hbox> 3.275 + 3.276 + <hbox> 3.277 + <button> 3.278 + <label>Mount</label> 3.279 + <input file icon="edit-redo"></input> 3.280 + <action>mkdir -p $MOUNT_POINT</action> 3.281 + <action>mount $DEVICE $MOUNT_POINT</action> 3.282 + <action>refresh:MOUNTED</action> 3.283 + <action>refresh:DEVICE</action> 3.284 + </button> 3.285 + <button> 3.286 + <label>Umount</label> 3.287 + <input file icon="undo"></input> 3.288 + <action>umount $MOUNT_POINT; sleep 1</action> 3.289 + <action>refresh:MOUNTED</action> 3.290 + <action>refresh:DEVICE</action> 3.291 + </button> 3.292 + <button> 3.293 + <label>Device list</label> 3.294 + <input file icon="reload"></input> 3.295 + <action>refresh:DEVICE</action> 3.296 + </button> 3.297 + <button> 3.298 + <label>Eject</label> 3.299 + <input file icon="media-cdrom"></input> 3.300 + <action>eject</action> 3.301 + </button> 3.302 + <button help> 3.303 + <input file icon="help"></input> 3.304 + <action type="launch">HELP</action> 3.305 + </button> 3.306 + <button> 3.307 + <label>Quit</label> 3.308 + <input file icon="exit"></input> 3.309 + <action type="exit">Exit</action> 3.310 + </button> 3.311 + 3.312 + </hbox> 3.313 + 3.314 +</vbox> 3.315 +</window>' 3.316 + 3.317 +export MAIN_DIALOG=${MAIN_DIALOG}${ACTIONS} 3.318 +gtkdialog --center --program=MAIN_DIALOG >/dev/null 3.319 3.320 exit 0