slitaz-tools diff lib/libmountbox @ 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
children db0e82bebc70
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/libmountbox	Sun May 11 00:25:10 2008 +0200
     1.3 @@ -0,0 +1,188 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Libmountbox provide devices list in suitable format for GTK tree
     1.7 +# and varius dialog boxes to mount, umount, etc.
     1.8 +#
     1.9 +# (C) 2008 - SliTaz GNU/Linux project.
    1.10 +#
    1.11 +
    1.12 +# Short usage.
    1.13 +usage()
    1.14 +{
    1.15 +	echo -e "\nUsage: $0 command\n
    1.16 +Outpout commads:
    1.17 +  list-mounted      List all mounted devices in suitable GTK tree format.
    1.18 +  list-umounted     List all umounted in suitable GTK tree format.
    1.19 +  
    1.20 +GTKdialog boxes
    1.21 +  mounted-fs-infos  Display a mounted devices infos with actions.
    1.22 +  umounted-fs-infos  Display a umounted devices infos with actions.\n"
    1.23 +}
    1.24 +
    1.25 +# Format df -h output fot GTK tree.
    1.26 +mounted_fs_data()
    1.27 +{
    1.28 +	SIZE=`echo $RES | cut -d " " -f 2`
    1.29 +	USED=`echo $RES | cut -d " " -f 3`
    1.30 +	AVAILABLE=`echo $RES | cut -d " " -f 4`
    1.31 +	PCT=`echo $RES | cut -d " " -f 5`
    1.32 +	MOUNTED_ON=`echo $RES | cut -d " " -f 6`
    1.33 +}
    1.34 +
    1.35 +case $1 in
    1.36 +	list-mounted)
    1.37 +		# List all fs found by: df -h
    1.38 +		#
    1.39 +		for dev in `df -h | grep ^/dev/[c-s]d | cut -d " " -f 1`
    1.40 +		do
    1.41 +			RES=`df -h $dev | grep ^$dev`
    1.42 +			mounted_fs_data
    1.43 +			echo "$dev | $SIZE | $USED | $AVAILABLE | $PCT | $MOUNTED_ON"
    1.44 +		done ;;
    1.45 +	list-umounted)
    1.46 +		# List all umounted fs found by: fdisk -l
    1.47 +		#
    1.48 +		for dev in `fdisk -l | grep ^/dev | cut -d " " -f 1`
    1.49 +		do
    1.50 +			RES=`fdisk -l | grep $dev | sed s/*//g`
    1.51 +			START=`echo $RES | cut -d " " -f 2`
    1.52 +			END=`echo $RES | cut -d " " -f 3`
    1.53 +			BLOCKS=`echo $RES | cut -d " " -f 4`
    1.54 +			ID=`echo $RES | cut -d " " -f 5`
    1.55 +			SYSTEM=`echo $RES | cut -d " " -f 6`
    1.56 +			# Bootable...
    1.57 +			if fdisk -l | grep $dev | grep -q "*"; then
    1.58 +				BOOT="*"
    1.59 +			else
    1.60 +				BOOT="-"
    1.61 +			fi
    1.62 +			# Skip swap, extended part and mounted.
    1.63 +			if echo $RES | grep -q "swap" || echo $RES | grep -q "Extended" ; then
    1.64 +				continue
    1.65 +			elif mount | grep -q "^$dev"; then
    1.66 +				continue
    1.67 +			else
    1.68 +				echo "$dev | $BOOT | $START | $END | $BLOCKS | $ID | $SYSTEM"
    1.69 +			fi
    1.70 +		done ;;
    1.71 +	mounted-fs-infos)
    1.72 +		# Mounted fs infos and actions, rootfs or other fs.
    1.73 +		#
    1.74 +		if [ "$MOUNTED" == "/dev/root" ]; then
    1.75 +			export MOUNTED_DEVICE="
    1.76 +<window title=\"Device: rootfs\" icon-name=\"media-flash\">
    1.77 +<vbox>
    1.78 +	<text use-markup=\"true\" width-chars=\"56\">
    1.79 +		<label>\"
    1.80 +<b>/dev/root</b>
    1.81 +\"
    1.82 +		</label>
    1.83 +	</text>
    1.84 +	<text use-markup=\"true\" width-chars=\"56\">
    1.85 +		<input>df -h / | grep ^rootfs</input>
    1.86 +	</text>
    1.87 +	<hbox>
    1.88 +		<button>
    1.89 +			<label>Browse</label>
    1.90 +			<input file icon=\"folder-open\"></input>
    1.91 +			<action>pcmanfm / &</action>
    1.92 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
    1.93 +		</button>
    1.94 +		<button>
    1.95 +			<input file icon=\"gtk-close\"></input>
    1.96 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
    1.97 +		</button>
    1.98 +	</hbox>
    1.99 +</vbox>
   1.100 +</window>"
   1.101 +		gtkdialog --center --program=MOUNTED_DEVICE
   1.102 +		else
   1.103 +			UUID=`blkid | grep ^$MOUNTED | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'`
   1.104 +			TYPE=`blkid | grep ^$MOUNTED | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'`
   1.105 +			RES=`df -h $MOUNTED | grep ^$MOUNTED`
   1.106 +			mounted_fs_data
   1.107 +			export MOUNTED_DEVICE="
   1.108 +<window title=\"Device: $MOUNTED\" icon-name=\"media-flash\">
   1.109 +<vbox>
   1.110 +	<text use-markup=\"true\" width-chars=\"56\">
   1.111 +		<label>\"
   1.112 +Device <b>$MOUNTED</b> is mounted on <b>$MOUNTED_ON</b>
   1.113 +
   1.114 +UUID: $UUID
   1.115 +Type: $TYPE
   1.116 +\"
   1.117 +		</label>
   1.118 +	</text>
   1.119 +	<hbox>
   1.120 +		<button>
   1.121 +			<label>Browse</label>
   1.122 +			<input file icon=\"folder-open\"></input>
   1.123 +			<action>pcmanfm $MOUNTED_ON &</action>
   1.124 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
   1.125 +		</button>
   1.126 +		<button>
   1.127 +			<label>Umount</label>
   1.128 +			<input file icon=\"undo\"></input>
   1.129 +			<action>umount $MOUNTED_ON</action>
   1.130 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
   1.131 +		</button>
   1.132 +		<button>
   1.133 +			<input file icon=\"gtk-close\"></input>
   1.134 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
   1.135 +		</button>
   1.136 +	</hbox>
   1.137 +</vbox>
   1.138 +</window>"
   1.139 +		gtkdialog --center --program=MOUNTED_DEVICE
   1.140 +		fi ;;
   1.141 +	umounted-fs-infos)
   1.142 +		# Mounted fs infos and actions, rootfs or other fs.
   1.143 +		#
   1.144 +		UUID=`blkid | grep ^$DEVICE | sed 's/.*UUID=\"\([^ ]*\)\".*/\1/'`
   1.145 +		TYPE=`blkid | grep ^$DEVICE | sed 's/.*TYPE=\"\([^ ]*\)\".*/\1/'`
   1.146 +		export UMOUNTED_DEVICE="
   1.147 +<window title=\"Device: $DEVICE\" icon-name=\"media-flash\">
   1.148 +<vbox>
   1.149 +	<text use-markup=\"true\" width-chars=\"56\">
   1.150 +		<label>\"
   1.151 +Mount <b>$DEVICE</b> on <b>$MOUNT_POINT</b>
   1.152 +
   1.153 +UUID: $UUID
   1.154 +Type: $TYPE
   1.155 +\"
   1.156 +		</label>
   1.157 +	</text>
   1.158 +	
   1.159 +	<hbox>
   1.160 +		<button>
   1.161 +			<label>Mount</label>
   1.162 +			<input file icon=\"edit-redo\"></input>
   1.163 +			<action>mkdir -p $MOUNT_POINT</action>
   1.164 +			<action>mount $DEVICE $MOUNT_POINT</action>
   1.165 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
   1.166 +		</button>
   1.167 +		
   1.168 +		<button>
   1.169 +			<label>e2fsck check</label>
   1.170 +			<input file icon=\"drive-harddisk\"></input>
   1.171 +			<action>xterm -T \"e2fsck -p $DEVICE\" \
   1.172 +				--geomery 80x12 \
   1.173 +				-e \"echo; e2fsck -p $DEVICE; \
   1.174 +				echo -e '----\nENTER to close Termianl'; \
   1.175 +				read i\" &</action>
   1.176 +			<action type=\"closewindow\">MOUNTED_DEVICE</action>
   1.177 +		</button>
   1.178 +		
   1.179 +		<button>
   1.180 +			<input file icon=\"gtk-close\"></input>
   1.181 +			<action type=\"closewindow\">UMOUNTED_DEVICE</action>
   1.182 +		</button>
   1.183 +	</hbox>
   1.184 +</vbox>
   1.185 +</window>"
   1.186 +		gtkdialog --center --program=UMOUNTED_DEVICE ;;
   1.187 +	*)
   1.188 +		usage ;;
   1.189 +esac
   1.190 +
   1.191 +exit 0