slitaz-tools annotate lib/libmountbox @ rev 543
applications.conf: to have autostart.sh executed we nee openbox-session to be started
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun Jan 23 12:44:58 2011 +0100 (2011-01-23) |
parents | a87a3cca2926 |
children | 29fe613b2eb6 |
rev | line source |
---|---|
pankso@183 | 1 #!/bin/sh |
pankso@183 | 2 # |
MikeDSmith25@252 | 3 # Libmountbox provides devices list in suitable format for GTK tree |
MikeDSmith25@252 | 4 # and various dialog boxes to mount, umount, etc. |
pankso@183 | 5 # |
pascal@369 | 6 # (C) 2009 - SliTaz GNU/Linux project. |
pankso@183 | 7 # |
pankso@183 | 8 |
pankso@183 | 9 # Short usage. |
pankso@183 | 10 usage() |
pankso@183 | 11 { |
pankso@183 | 12 echo -e "\nUsage: $0 command\n |
MikeDSmith25@252 | 13 Output commands: |
pankso@183 | 14 list-mounted List all mounted devices in suitable GTK tree format. |
pankso@183 | 15 list-umounted List all umounted in suitable GTK tree format. |
pascal@381 | 16 create-file Create an empty file with predefined size. |
pascal@381 | 17 add-old-crypto Create loop-eas device. |
pascal@381 | 18 remove-crypto Delete a crypto device. |
pankso@183 | 19 |
pankso@183 | 20 GTKdialog boxes |
pankso@183 | 21 mounted-fs-infos Display a mounted devices infos with actions. |
pascal@381 | 22 umounted-fs-infos Display a umounted devices infos with actions. |
pascal@381 | 23 remove-loop Confirmation box. |
pascal@381 | 24 new-file Parameter box for file creation. |
pascal@381 | 25 cryptomgr Manage crypto device with devmapper. |
pascal@381 | 26 add-crypto Pass phrase dialog.\n" |
pankso@183 | 27 } |
pankso@183 | 28 |
MikeDSmith25@252 | 29 # Format df -h output for GTK tree. |
pankso@183 | 30 mounted_fs_data() |
pankso@183 | 31 { |
pankso@183 | 32 SIZE=`echo $RES | cut -d " " -f 2` |
pankso@183 | 33 USED=`echo $RES | cut -d " " -f 3` |
pankso@183 | 34 AVAILABLE=`echo $RES | cut -d " " -f 4` |
pankso@183 | 35 PCT=`echo $RES | cut -d " " -f 5` |
pankso@183 | 36 MOUNTED_ON=`echo $RES | cut -d " " -f 6` |
pankso@183 | 37 } |
pankso@183 | 38 |
pascal@370 | 39 # Update BLOCKS SIZE UUID TYPE LABEL variables |
pascal@369 | 40 getdevinfo() |
pascal@368 | 41 { |
pascal@370 | 42 local dev |
pascal@370 | 43 dev=${1#/dev/} |
pascal@370 | 44 BLOCKS=0 |
pascal@370 | 45 if [ -f /sys/block/$dev/size ]; then |
pascal@370 | 46 BLOCKS=`cat /sys/block/$dev/size` |
pascal@370 | 47 elif [ -f /sys/block/*/$dev/size ]; then |
pascal@370 | 48 BLOCKS=`cat /sys/block/*/$dev/size` |
pascal@370 | 49 fi |
pascal@368 | 50 if [ $BLOCKS -gt 2097152 ]; then |
pascal@368 | 51 unit=G |
pascal@370 | 52 n=$(($BLOCKS * 10 / 2097152)) |
pascal@368 | 53 elif [ $BLOCKS -gt 2048 ]; then |
pascal@368 | 54 unit=M |
pascal@370 | 55 n=$(($BLOCKS * 10 / 2048)) |
pascal@368 | 56 else |
pascal@368 | 57 unit=K |
pascal@370 | 58 n=$(($BLOCKS * 5)) |
pascal@368 | 59 fi |
pascal@369 | 60 SIZE=$(($n/10)).$(($n%10))$unit |
pascal@370 | 61 UUID=`blkid | grep ^/dev/$dev: | grep UUID= | sed 's/.*UUID=\"\([^\"]*\)\".*/\1/'` |
pascal@370 | 62 TYPE=`blkid | grep ^/dev/$dev: | grep TYPE= | sed 's/.*TYPE=\"\([^\"]*\)\".*/\1/'` |
pascal@370 | 63 LABEL=`blkid | grep ^/dev/$dev: | grep LABEL= | sed 's/.*LABEL=\"\([^\"]*\)\".*/\1/'` |
pascal@368 | 64 } |
pascal@368 | 65 |
pascal@379 | 66 # Generate label for device manager |
pascal@379 | 67 dmlabel() |
pascal@379 | 68 { |
pascal@379 | 69 echo crypto-$(basename $1) |
pascal@379 | 70 } |
pascal@379 | 71 |
pascal@379 | 72 unwrap() |
pascal@379 | 73 { |
pascal@379 | 74 awk '{ |
pascal@379 | 75 if ($2 == "") last=$1; |
pascal@379 | 76 else { |
pascal@379 | 77 print last $0 |
pascal@379 | 78 last="" |
pascal@379 | 79 } |
pascal@379 | 80 }' |
pascal@379 | 81 } |
pascal@379 | 82 |
pankso@183 | 83 case $1 in |
pankso@183 | 84 list-mounted) |
pankso@183 | 85 # List all fs found by: df -h |
pankso@183 | 86 # |
pascal@368 | 87 for dev in `df -h | grep ^/dev/ | cut -d " " -f 1` |
pankso@183 | 88 do |
pascal@381 | 89 RO='read-only' |
pascal@381 | 90 mount | grep $dev | grep -q '(rw' && RO='' |
pascal@379 | 91 RES=`df -h $dev | unwrap | grep ^$dev` |
pankso@183 | 92 mounted_fs_data |
pascal@381 | 93 echo "$dev | $SIZE | $USED | $AVAILABLE | $PCT | $MOUNTED_ON | $RO" |
pankso@183 | 94 done ;; |
pankso@183 | 95 list-umounted) |
pankso@183 | 96 # List all umounted fs found by: fdisk -l |
pankso@183 | 97 # |
pankso@183 | 98 for dev in `fdisk -l | grep ^/dev | cut -d " " -f 1` |
pankso@183 | 99 do |
pankso@183 | 100 RES=`fdisk -l | grep $dev | sed s/*//g` |
pankso@183 | 101 START=`echo $RES | cut -d " " -f 2` |
pankso@183 | 102 END=`echo $RES | cut -d " " -f 3` |
pankso@183 | 103 BLOCKS=`echo $RES | cut -d " " -f 4` |
pankso@183 | 104 ID=`echo $RES | cut -d " " -f 5` |
pascal@262 | 105 SYSTEM=`echo $RES | cut -d " " -f 6-` |
pankso@183 | 106 # Bootable... |
pankso@183 | 107 if fdisk -l | grep $dev | grep -q "*"; then |
pascal@368 | 108 BOOT="yes" |
pankso@183 | 109 else |
pankso@183 | 110 BOOT="-" |
pankso@183 | 111 fi |
MikeDSmith25@252 | 112 # Skip swap, extended, and mounted partitions. |
pankso@183 | 113 if echo $RES | grep -q "swap" || echo $RES | grep -q "Extended" ; then |
pankso@183 | 114 continue |
pascal@262 | 115 elif mount | grep -q "^$dev "; then |
pankso@183 | 116 continue |
pankso@183 | 117 else |
pascal@370 | 118 getdevinfo $dev |
pascal@368 | 119 echo "$dev | $SIZE | $SYSTEM | $TYPE | $LABEL | $BOOT | $START | $END | $BLOCKS | $ID | $UUID" |
pankso@183 | 120 fi |
pascal@262 | 121 done |
pascal@368 | 122 for dev in /dev/mapper/* ; do |
pascal@368 | 123 [ -b $dev ] || continue |
pascal@368 | 124 mount | grep -q "^$dev " && continue |
pascal@368 | 125 mdev=dm-$(ls -l $dev | awk '{ print $6 }') |
pascal@368 | 126 mount | grep -q "^/dev/$mdev " && continue |
pascal@370 | 127 getdevinfo /dev/$mdev |
pascal@369 | 128 echo "$dev | $SIZE | - | $TYPE | $LABEL | - | - | - | $BLOCKS | - | $UUID" |
pascal@369 | 129 done |
pascal@369 | 130 for dev in $(losetup | cut -d: -f1); do |
pascal@369 | 131 [ -b $dev ] || continue |
pascal@369 | 132 mount | grep -q "^$dev " && continue |
pascal@370 | 133 getdevinfo $dev |
pascal@368 | 134 echo "$dev | $SIZE | - | $TYPE | $LABEL | - | - | - | $BLOCKS | - | $UUID" |
pascal@368 | 135 done |
pascal@368 | 136 [ -e /dev/cdrom ] && |
pascal@368 | 137 echo "/dev/cdrom | - | CD/DVD | iso9660 | - | - | - | - | - | - | -" |
pascal@262 | 138 for i in /sys/devices/platform/floppy.*/block:*; do |
pascal@263 | 139 [ -e $i ] && echo "/dev/${i#*block:} | - | - | - | floppy | - | - | - | - | -" |
pascal@262 | 140 done |
pascal@262 | 141 ;; |
pankso@183 | 142 mounted-fs-infos) |
MikeDSmith25@252 | 143 # Mounted fs info and actions, rootfs or other fs. |
pankso@183 | 144 # |
pankso@183 | 145 if [ "$MOUNTED" == "/dev/root" ]; then |
pankso@183 | 146 export MOUNTED_DEVICE=" |
pankso@183 | 147 <window title=\"Device: rootfs\" icon-name=\"media-flash\"> |
pankso@183 | 148 <vbox> |
pankso@183 | 149 <text use-markup=\"true\" width-chars=\"56\"> |
pankso@183 | 150 <label>\" |
pankso@183 | 151 <b>/dev/root</b> |
pankso@183 | 152 \" |
pankso@183 | 153 </label> |
pankso@183 | 154 </text> |
pankso@183 | 155 <text use-markup=\"true\" width-chars=\"56\"> |
pankso@183 | 156 <input>df -h / | grep ^rootfs</input> |
pankso@183 | 157 </text> |
pankso@183 | 158 <hbox> |
pankso@183 | 159 <button> |
pankso@183 | 160 <label>Browse</label> |
pankso@183 | 161 <input file icon=\"folder-open\"></input> |
pankso@183 | 162 <action>pcmanfm / &</action> |
pankso@183 | 163 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pankso@183 | 164 </button> |
pankso@183 | 165 <button> |
pankso@183 | 166 <input file icon=\"gtk-close\"></input> |
pankso@183 | 167 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pankso@183 | 168 </button> |
pankso@183 | 169 </hbox> |
pankso@183 | 170 </vbox> |
pankso@183 | 171 </window>" |
pankso@183 | 172 gtkdialog --center --program=MOUNTED_DEVICE |
pankso@183 | 173 else |
pascal@370 | 174 getdevinfo $MOUNTED |
pankso@183 | 175 RES=`df -h $MOUNTED | grep ^$MOUNTED` |
pankso@183 | 176 mounted_fs_data |
pankso@183 | 177 export MOUNTED_DEVICE=" |
pankso@183 | 178 <window title=\"Device: $MOUNTED\" icon-name=\"media-flash\"> |
pankso@183 | 179 <vbox> |
pankso@183 | 180 <text use-markup=\"true\" width-chars=\"56\"> |
pankso@183 | 181 <label>\" |
pankso@183 | 182 Device <b>$MOUNTED</b> is mounted on <b>$MOUNTED_ON</b> |
pankso@183 | 183 |
pascal@370 | 184 Size: $SIZE |
pankso@183 | 185 UUID: $UUID |
pankso@183 | 186 Type: $TYPE |
pascal@263 | 187 Label: $LABEL |
pankso@183 | 188 \" |
pankso@183 | 189 </label> |
pankso@183 | 190 </text> |
pankso@183 | 191 <hbox> |
pankso@183 | 192 <button> |
pankso@183 | 193 <label>Browse</label> |
pankso@183 | 194 <input file icon=\"folder-open\"></input> |
pankso@183 | 195 <action>pcmanfm $MOUNTED_ON &</action> |
pankso@183 | 196 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@381 | 197 </button>" |
pascal@381 | 198 if mount | grep $MOUNTED_ON | grep -q '(rw'; then |
pascal@381 | 199 MOUNTED_DEVICE="$MOUNTED_DEVICE |
pascal@381 | 200 <button> |
pascal@381 | 201 <label>Remount read-only</label> |
pascal@381 | 202 <input file icon=\"redo\"></input> |
pascal@381 | 203 <action>mount -o remount,ro $MOUNTED_ON</action> |
pascal@381 | 204 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@381 | 205 </button>" |
pascal@381 | 206 else |
pascal@381 | 207 MOUNTED_DEVICE="$MOUNTED_DEVICE |
pascal@381 | 208 <button> |
pascal@381 | 209 <label>Remount read-write</label> |
pascal@381 | 210 <input file icon=\"redo\"></input> |
pascal@381 | 211 <action>mount -o remount,rw $MOUNTED_ON</action> |
pascal@381 | 212 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@381 | 213 </button>" |
pascal@381 | 214 fi |
pascal@381 | 215 MOUNTED_DEVICE="$MOUNTED_DEVICE |
pankso@183 | 216 <button> |
pankso@183 | 217 <label>Umount</label> |
pankso@183 | 218 <input file icon=\"undo\"></input> |
pankso@183 | 219 <action>umount $MOUNTED_ON</action> |
pankso@183 | 220 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pankso@183 | 221 </button> |
pankso@183 | 222 <button> |
pankso@183 | 223 <input file icon=\"gtk-close\"></input> |
pankso@183 | 224 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pankso@183 | 225 </button> |
pankso@183 | 226 </hbox> |
pankso@183 | 227 </vbox> |
pankso@183 | 228 </window>" |
pankso@183 | 229 gtkdialog --center --program=MOUNTED_DEVICE |
pankso@183 | 230 fi ;; |
pankso@183 | 231 umounted-fs-infos) |
MikeDSmith25@252 | 232 # Mounted fs info and actions, rootfs or other fs. |
pankso@183 | 233 # |
pascal@368 | 234 case "$DEVICE" in |
pascal@368 | 235 /dev/mapper/*) mdev=/dev/dm-$(ls -l $DEVICE | awk '{ print $6 }');; |
pascal@368 | 236 *) mdev=$DEVICE;; |
pascal@368 | 237 esac |
pascal@370 | 238 getdevinfo $mdev |
pankso@183 | 239 export UMOUNTED_DEVICE=" |
pankso@183 | 240 <window title=\"Device: $DEVICE\" icon-name=\"media-flash\"> |
pankso@183 | 241 <vbox> |
pankso@183 | 242 <text use-markup=\"true\" width-chars=\"56\"> |
pankso@183 | 243 <label>\" |
pankso@183 | 244 Mount <b>$DEVICE</b> on <b>$MOUNT_POINT</b> |
pankso@183 | 245 |
pascal@370 | 246 Size: $SIZE |
pankso@183 | 247 UUID: $UUID |
pankso@183 | 248 Type: $TYPE |
pascal@263 | 249 Label: $LABEL |
pankso@183 | 250 \" |
pankso@183 | 251 </label> |
pankso@183 | 252 </text> |
pankso@183 | 253 |
pankso@183 | 254 <hbox> |
pankso@183 | 255 <button> |
pascal@381 | 256 <label>Mount read-only</label> |
pascal@381 | 257 <input file icon=\"edit-redo\"></input> |
pascal@381 | 258 <action>mkdir -p $MOUNT_POINT</action> |
pascal@381 | 259 <action>mount -r $DEVICE $MOUNT_POINT</action> |
pascal@381 | 260 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@381 | 261 </button> |
pascal@381 | 262 <button> |
pascal@381 | 263 <label>Mount read-write</label> |
pankso@183 | 264 <input file icon=\"edit-redo\"></input> |
pankso@183 | 265 <action>mkdir -p $MOUNT_POINT</action> |
pankso@183 | 266 <action>mount $DEVICE $MOUNT_POINT</action> |
pankso@183 | 267 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@368 | 268 </button>" |
pascal@368 | 269 while read type fsck args; do |
pascal@368 | 270 [ "$TYPE" == "$type" ] || continue |
pascal@368 | 271 which $fsck > /dev/null || continue |
pascal@368 | 272 UMOUNTED_DEVICE="$UMOUNTED_DEVICE |
pankso@183 | 273 <button> |
pascal@368 | 274 <label>$fsck check</label> |
pankso@183 | 275 <input file icon=\"drive-harddisk\"></input> |
pascal@368 | 276 <action>xterm -T \"$fsck $args $DEVICE\" \ |
pascal@369 | 277 -geometry 80x12 \ |
pascal@368 | 278 -e \"echo; $fsck $args $DEVICE; \ |
pascal@369 | 279 echo -e '----\\nENTER to close Terminal'; \ |
pankso@183 | 280 read i\" &</action> |
pankso@183 | 281 <action type=\"closewindow\">MOUNTED_DEVICE</action> |
pascal@368 | 282 </button>" |
pascal@368 | 283 done <<EOT |
pascal@368 | 284 ext3 e2fsck -p |
pascal@368 | 285 ext2 e2fsck -p |
pascal@368 | 286 vfat dosfsck -a |
pascal@368 | 287 msdos dosfsck -a |
pascal@368 | 288 xfs fsck.xfs -s |
pascal@368 | 289 reiserfs reiserfsck --fix-fixable |
pascal@368 | 290 jfs jfs_fsck -a |
pascal@368 | 291 EOT |
pascal@368 | 292 UMOUNTED_DEVICE="$UMOUNTED_DEVICE |
pankso@183 | 293 <button> |
pankso@183 | 294 <input file icon=\"gtk-close\"></input> |
pankso@183 | 295 <action type=\"closewindow\">UMOUNTED_DEVICE</action> |
pankso@183 | 296 </button> |
pankso@183 | 297 </hbox> |
pankso@183 | 298 </vbox> |
pankso@183 | 299 </window>" |
pankso@183 | 300 gtkdialog --center --program=UMOUNTED_DEVICE ;; |
pascal@370 | 301 loopmgr) |
pascal@370 | 302 export LOOP_MANAGER=" |
pascal@370 | 303 <window title=\"Loop manager\" icon-name=\"media-flash\"> |
pascal@370 | 304 <vbox> |
pascal@370 | 305 <tree> |
pascal@370 | 306 <width>420</width><height>120</height> |
pascal@370 | 307 <variable>LOOP_DEV</variable> |
pascal@370 | 308 <label>Device|File|Size|Type|Label|Mounted on|Offset|UUID</label>" |
pascal@370 | 309 while read dev offset file; do |
pascal@370 | 310 DEV=$(echo $dev | cut -d: -f1) |
pascal@379 | 311 [ -b "$DEV" ] || continue |
pascal@370 | 312 MOUNT=$(mount | grep ^$DEV | awk '{ print $3 }') |
pascal@370 | 313 getdevinfo $DEV |
pascal@370 | 314 LOOP_MANAGER="$LOOP_MANAGER |
pascal@370 | 315 <item>$DEV | $file | $SIZE | $TYPE | $LABEL | $MOUNT | $offset | $UUID</item> |
pascal@370 | 316 " |
pascal@370 | 317 done <<EOT |
pascal@370 | 318 $(losetup) |
pascal@370 | 319 EOT |
pascal@370 | 320 LOOP_MANAGER="$LOOP_MANAGER |
pascal@379 | 321 <action>/usr/lib/slitaz/libmountbox remove-loop</action> |
pascal@379 | 322 <action>/usr/lib/slitaz/libmountbox loopmgr &</action> |
pascal@379 | 323 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@370 | 324 </tree> |
pascal@370 | 325 <hbox> |
pascal@370 | 326 <text use-markup=\"true\"> |
pascal@370 | 327 <label>\"<b>File</b>\"</label> |
pascal@370 | 328 </text> |
pascal@370 | 329 <entry accept=\"filename\"> |
pascal@370 | 330 <variable>FILE</variable> |
pascal@370 | 331 </entry> |
pascal@370 | 332 <button> |
pascal@370 | 333 <input file icon=\"folder-open\"></input> |
pascal@370 | 334 <action type=\"fileselect\">FILE</action> |
pascal@370 | 335 </button> |
pascal@370 | 336 </hbox> |
pascal@370 | 337 <hbox> |
pascal@379 | 338 <text use-markup=\"true\"> |
pascal@370 | 339 <label>\"<b>Offset</b>\"</label> |
pascal@370 | 340 </text> |
pascal@370 | 341 <entry> |
pascal@370 | 342 <default>0</default> |
pascal@370 | 343 <variable>OFFSET</variable> |
pascal@370 | 344 </entry> |
pascal@370 | 345 <button> |
pascal@379 | 346 <label>Disable</label> |
pascal@379 | 347 <input file icon=\"remove\"></input> |
pascal@379 | 348 <action>/usr/lib/slitaz/libmountbox remove-loop</action> |
pascal@379 | 349 <action>/usr/lib/slitaz/libmountbox loopmgr &</action> |
pascal@379 | 350 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@379 | 351 </button> |
pascal@379 | 352 <button> |
pascal@379 | 353 <label>Enable</label> |
pascal@370 | 354 <input file icon=\"add\"></input> |
pascal@381 | 355 <action>losetup -o \$OFFSET \$(losetup -f) \$FILE</action> |
pascal@370 | 356 <action>/usr/lib/slitaz/libmountbox loopmgr &</action> |
pascal@370 | 357 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@370 | 358 </button> |
pascal@370 | 359 <button> |
pascal@379 | 360 <label>Create</label> |
pascal@379 | 361 <input file icon=\"filenew\"></input> |
pascal@379 | 362 <action>/usr/lib/slitaz/libmountbox new-file</action> |
pascal@379 | 363 <action>/usr/lib/slitaz/libmountbox loopmgr &</action> |
pascal@379 | 364 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@379 | 365 </button> |
pascal@379 | 366 <button> |
pascal@370 | 367 <input file icon=\"gtk-close\"></input> |
pascal@370 | 368 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@370 | 369 </button> |
pascal@370 | 370 </hbox> |
pascal@370 | 371 </vbox> |
pascal@370 | 372 </window>" |
pascal@370 | 373 gtkdialog --center --program=LOOP_MANAGER ;; |
pascal@370 | 374 remove-loop) |
pascal@370 | 375 getdevinfo $LOOP_DEV |
pascal@370 | 376 export REMOVE_DEVICE=" |
pascal@370 | 377 <window title=\"Device: $LOOP_DEV\" icon-name=\"media-flash\"> |
pascal@370 | 378 <vbox> |
pascal@370 | 379 <text use-markup=\"true\" width-chars=\"56\"> |
pascal@370 | 380 <label>\" |
pascal@370 | 381 Disable <b>$LOOP_DEV</b> ? |
pascal@370 | 382 |
pascal@370 | 383 Size: $SIZE |
pascal@370 | 384 UUID: $UUID |
pascal@370 | 385 Type: $TYPE |
pascal@370 | 386 Label: $LABEL |
pascal@370 | 387 \" |
pascal@370 | 388 </label> |
pascal@370 | 389 </text> |
pascal@370 | 390 <hbox> |
pascal@370 | 391 <button yes> |
pascal@370 | 392 <action>umount $LOOP_DEV</action> |
pascal@370 | 393 <action>losetup -d $LOOP_DEV</action> |
pascal@370 | 394 <action type=\"closewindow\">LOOP_MANAGER</action> |
pascal@370 | 395 <action>/usr/lib/slitaz/libmountbox loopmgr &</action> |
pascal@370 | 396 <action type=\"closewindow\">REMOVE_DEVICE</action> |
pascal@370 | 397 </button> |
pascal@370 | 398 <button no> |
pascal@370 | 399 <action type=\"closewindow\">REMOVE_DEVICE</action> |
pascal@370 | 400 </button> |
pascal@370 | 401 </hbox> |
pascal@370 | 402 </vbox> |
pascal@370 | 403 </window>" |
pascal@370 | 404 gtkdialog --center --program=REMOVE_DEVICE ;; |
pascal@379 | 405 create-file) |
pascal@379 | 406 file=$2 |
pascal@379 | 407 size=$3 |
pascal@379 | 408 [ -n "$file" -a -n "$size" ] || exit |
pascal@379 | 409 [ "$4" == "true" ] && bs="1K" |
pascal@379 | 410 [ "$5" == "true" ] && bs="1M" |
pascal@379 | 411 [ "$6" == "true" ] && bs="1024M" |
pascal@404 | 412 [ "$8" == "true" ] && dev="/dev/zero count=$size" |
pascal@404 | 413 [ "$9" == "true" ] && dev="/dev/urandom count=$size" |
pascal@404 | 414 [ "$10" == "true" ] && dev="/dev/zero seek=$size count=0" |
pascal@379 | 415 if [ "$7" != "true" -a -e "$file" ]; then |
pascal@379 | 416 export FILE_EXIST=" |
pascal@379 | 417 <window title=\"File exist\" icon-name=\"media-flash\"> |
pascal@379 | 418 <vbox> |
pascal@379 | 419 <hbox> |
pascal@379 | 420 <text use-markup=\"true\"> |
pascal@379 | 421 <label> \"The file <b>$file</b> already exists\" </label> |
pascal@379 | 422 </text> |
pascal@379 | 423 </hbox> |
pascal@379 | 424 <hbox> |
pascal@379 | 425 <button> |
pascal@379 | 426 <input file icon=\"gtk-close\"></input> |
pascal@379 | 427 <action type=\"closewindow\">FILE_EXIST</action> |
pascal@379 | 428 </button> |
pascal@379 | 429 </hbox> |
pascal@379 | 430 </vbox> |
pascal@379 | 431 </window>" |
pascal@379 | 432 gtkdialog --center --program=FILE_EXIST |
pascal@379 | 433 exit |
pascal@379 | 434 fi |
pascal@404 | 435 dd if=$dev of=$file bs=$bs |
pascal@379 | 436 ;; |
pascal@379 | 437 new-file) |
pascal@379 | 438 export CREATE_FILE=" |
pascal@379 | 439 <window title=\"Create file\" icon-name=\"media-flash\"> |
pascal@379 | 440 <vbox> |
pascal@379 | 441 <hbox> |
pascal@379 | 442 <text use-markup=\"true\"> |
pascal@379 | 443 <label>\"<b>File:</b>\"</label> |
pascal@379 | 444 </text> |
pascal@379 | 445 <entry> |
pascal@379 | 446 <variable>FILE</variable> |
pascal@379 | 447 $( [ -n "$FILE" ] && echo "<default>$FILE</default>" ) |
pascal@379 | 448 </entry> |
pascal@379 | 449 <button> |
pascal@379 | 450 <input file icon=\"folder-open\"></input> |
pascal@379 | 451 <action type=\"fileselect\">FILE</action> |
pascal@379 | 452 </button> |
pascal@379 | 453 </hbox> |
pascal@379 | 454 <hbox> |
pascal@379 | 455 <text use-markup=\"true\"> |
pascal@379 | 456 <label>\"<b>Size:</b>\"</label> |
pascal@379 | 457 </text> |
pascal@379 | 458 <entry> |
pascal@379 | 459 <variable>NEW_SIZE</variable> |
pascal@379 | 460 <default>0</default> |
pascal@379 | 461 </entry> |
pascal@379 | 462 <radiobutton> |
pascal@379 | 463 <label>Kb</label> |
pascal@379 | 464 <variable>KB</variable> |
pascal@379 | 465 </radiobutton> |
pascal@379 | 466 <radiobutton> |
pascal@379 | 467 <label>Mb</label> |
pascal@379 | 468 <variable>MB</variable> |
pascal@379 | 469 </radiobutton> |
pascal@379 | 470 <radiobutton> |
pascal@379 | 471 <label>Gb</label> |
pascal@379 | 472 <variable>GB</variable> |
pascal@379 | 473 </radiobutton> |
pascal@379 | 474 </hbox> |
pascal@379 | 475 <hbox> |
pascal@404 | 476 <text use-markup=\"true\"> |
pascal@404 | 477 <label>\"<b>Fill</b>\"</label> |
pascal@404 | 478 </text> |
pascal@404 | 479 <radiobutton> |
pascal@404 | 480 <label>random</label> |
pascal@404 | 481 <variable>RANDOM</variable> |
pascal@404 | 482 </radiobutton> |
pascal@404 | 483 <radiobutton> |
pascal@404 | 484 <label>zero</label> |
pascal@404 | 485 <variable>ZERO</variable> |
pascal@404 | 486 </radiobutton> |
pascal@404 | 487 <radiobutton> |
pascal@404 | 488 <label>sparse</label> |
pascal@404 | 489 <variable>SPARSE</variable> |
pascal@404 | 490 </radiobutton> |
pascal@379 | 491 <checkbox> |
pascal@379 | 492 <label>Override</label> |
pascal@379 | 493 <variable>OVERRIDE</variable> |
pascal@379 | 494 <default>false</default> |
pascal@379 | 495 </checkbox> |
pascal@379 | 496 <button> |
pascal@379 | 497 <label>Create</label> |
pascal@379 | 498 <input file icon=\"filenew\"></input> |
pascal@404 | 499 <action>/usr/lib/slitaz/libmountbox create-file \"\$FILE\" \"\$NEW_SIZE\" \$KB \$MB \$GB \$OVERRIDE \$ZERO \$RANDOM \$SPARSE</action> |
pascal@379 | 500 <action type=\"closewindow\">CREATE_FILE</action> |
pascal@379 | 501 </button> |
pascal@379 | 502 <button> |
pascal@379 | 503 <input file icon=\"gtk-close\"></input> |
pascal@379 | 504 <action type=\"closewindow\">CREATE_FILE</action> |
pascal@379 | 505 </button> |
pascal@379 | 506 </hbox> |
pascal@379 | 507 </vbox> |
pascal@379 | 508 </window>" |
pascal@379 | 509 gtkdialog --center --program=CREATE_FILE ;; |
pascal@379 | 510 cryptomgr) |
pascal@379 | 511 missing="" |
pascal@379 | 512 for i in libdevmapper dmsetup linux-md hashalot cryptsetup ; do |
pascal@379 | 513 [ -d /var/lib/tazpkg/installed/$i ] || missing="$missing $i" |
pascal@379 | 514 done |
pascal@379 | 515 if [ -n "$missing" ]; then |
pascal@379 | 516 export CRYPTO_MANAGER=" |
pascal@379 | 517 <window title=\"Crypto manager\" icon-name=\"media-flash\"> |
pascal@379 | 518 <vbox> |
pascal@379 | 519 <hbox> |
pascal@379 | 520 <text use-markup=\"true\"> |
pascal@379 | 521 <label>\" |
paul@399 | 522 <b>Packages needed :</b> |
pascal@379 | 523 |
pascal@379 | 524 $(for i in $missing ; do echo $i; done) |
pascal@379 | 525 \" </label> |
pascal@379 | 526 </text> |
pascal@379 | 527 </hbox> |
pascal@379 | 528 <hbox> |
pascal@379 | 529 <button> |
pascal@379 | 530 <label>Install</label> |
pascal@379 | 531 <input file icon=\"go-jump\"></input> |
pascal@379 | 532 <action>xterm -T \"Install packages\" \ |
pascal@379 | 533 -geometry 80x16+120+120 -e \"for i in $missing ; do \ |
pascal@379 | 534 yes y | tazpkg get-install \\\$i ; done; sleep 2\" \ |
pascal@379 | 535 </action> |
pascal@379 | 536 <action>/usr/lib/slitaz/libmountbox cryptomgr &</action> |
pascal@379 | 537 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 538 </button> |
pascal@379 | 539 <button> |
pascal@379 | 540 <input file icon=\"gtk-close\"></input> |
pascal@379 | 541 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 542 </button> |
pascal@379 | 543 </hbox> |
pascal@379 | 544 </vbox> |
pascal@379 | 545 </window>" |
pascal@379 | 546 gtkdialog --center --program=CRYPTO_MANAGER |
pascal@379 | 547 exit |
pascal@379 | 548 fi |
pascal@379 | 549 for i in dm-mod dm-crypt aes-i586 ; do |
pascal@379 | 550 lsmod | grep -q $i || modprobe $i |
pascal@379 | 551 done |
pascal@379 | 552 export CRYPTO_MANAGER=" |
pascal@379 | 553 <window title=\"Crypto manager\" icon-name=\"media-flash\"> |
pascal@379 | 554 <vbox> |
pascal@379 | 555 <tree> |
pascal@379 | 556 <width>420</width><height>120</height> |
pascal@379 | 557 <variable>CRYTO_DEV</variable> |
pascal@379 | 558 <label>Name|Device|Size|Type|Label|Mounted on|UUID</label>" |
pascal@379 | 559 while read name ; do |
pascal@379 | 560 [ -b /dev/mapper/$name ] || continue |
pascal@379 | 561 DEV=/dev/dm-$(ls -l /dev/mapper/$name | awk '{ print $6 }') |
pascal@379 | 562 MOUNT=$(mount | egrep "^$DEV|/dev/mapper/$name" | awk '{ print $3 }') |
pascal@379 | 563 getdevinfo $DEV |
pascal@381 | 564 case "$name" in |
pascal@381 | 565 *crypto*) item="item icon=\"passwd\"";; |
pascal@381 | 566 *) item="item icon=\"drive-harddisk\"";; |
pascal@381 | 567 esac |
pascal@379 | 568 CRYPTO_MANAGER="$CRYPTO_MANAGER |
pascal@381 | 569 <$item>$name|$DEV | $SIZE | $TYPE | $LABEL | $MOUNT | $UUID</item> |
pascal@379 | 570 " |
pascal@379 | 571 done <<EOT |
pascal@379 | 572 $(ls /dev/mapper 2> /dev/null) |
pascal@379 | 573 EOT |
pascal@379 | 574 CRYPTO_MANAGER="$CRYPTO_MANAGER |
pascal@379 | 575 </tree> |
pascal@379 | 576 <hbox> |
pascal@379 | 577 <text use-markup=\"true\"> |
pascal@379 | 578 <label>\"<b>Device :</b>\"</label> |
pascal@379 | 579 </text> |
pascal@379 | 580 <combobox> |
pascal@379 | 581 <label>Device</label> |
pascal@379 | 582 $( (losetup ; blkid | grep -v /dev/loop ) | cut -d: -f1 | awk '{ printf "<item>%s</item>\n",$1}') |
pascal@379 | 583 <variable>DEVICE</variable> |
pascal@379 | 584 </combobox> |
pascal@379 | 585 <text use-markup=\"true\"> |
pascal@379 | 586 <label>\"<b>Cipher :</b>\"</label> |
pascal@379 | 587 </text> |
pascal@379 | 588 <combobox> |
pascal@379 | 589 <variable>CRYPTO</variable> |
pascal@379 | 590 <item>aes-256</item> |
pascal@379 | 591 <item>aes-192</item> |
pascal@379 | 592 <item>aes-128</item> |
pascal@379 | 593 </combobox> |
pascal@379 | 594 </hbox> |
pascal@379 | 595 <hbox> |
pascal@379 | 596 <button> |
pascal@379 | 597 <label>Remove</label> |
pascal@379 | 598 <input file icon=\"remove\"></input> |
pascal@379 | 599 <action>/usr/lib/slitaz/libmountbox remove-crypto</action> |
pascal@379 | 600 <action>/usr/lib/slitaz/libmountbox cryptomgr &</action> |
pascal@379 | 601 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 602 </button> |
pascal@379 | 603 <button> |
pascal@379 | 604 <label>Create</label> |
pascal@379 | 605 <input file icon=\"add\"></input> |
pascal@379 | 606 <action>/usr/lib/slitaz/libmountbox add-crypto</action> |
pascal@379 | 607 <action>/usr/lib/slitaz/libmountbox cryptomgr &</action> |
pascal@379 | 608 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 609 </button> |
pascal@379 | 610 <button> |
pascal@379 | 611 <label>Format</label> |
pascal@379 | 612 <input file icon=\"gtk-clear\"></input> |
pascal@379 | 613 <action>/usr/lib/slitaz/libmountbox format-crypto</action> |
pascal@379 | 614 <action>xterm -T \"Format LUKS\" \ |
pascal@379 | 615 -geometry 80x16+120+120 -e \"\ |
pascal@379 | 616 cryptsetup luksFormat -c aes -h sha\${CRYPTO#aes-} \$DEVICE \" \ |
pascal@379 | 617 </action> |
pascal@379 | 618 <action>/usr/lib/slitaz/libmountbox cryptomgr &</action> |
pascal@379 | 619 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 620 </button> |
pascal@379 | 621 <button> |
pascal@379 | 622 <input file icon=\"gtk-close\"></input> |
pascal@379 | 623 <action type=\"closewindow\">CRYPTO_MANAGER</action> |
pascal@379 | 624 </button> |
pascal@379 | 625 </hbox> |
pascal@379 | 626 </vbox> |
pascal@379 | 627 </window>" |
pascal@379 | 628 gtkdialog --center --program=CRYPTO_MANAGER ;; |
pascal@379 | 629 add-old-crypto) |
pascal@379 | 630 # Not luks format |
pascal@379 | 631 # Try old loop-eas |
pascal@379 | 632 case "$CRYPTO" in |
pascal@379 | 633 *128) key="16 sha256";; |
pascal@379 | 634 *192) key="24 sha384";; |
pascal@379 | 635 *) key="32 sha512";; |
pascal@379 | 636 esac |
pascal@379 | 637 getdevinfo $DEVICE |
pascal@379 | 638 key=$(echo $PASS_PHRASE | hashalot -x -n $key) |
pascal@379 | 639 echo 0 $BLOCKS crypt aes-plain $key 0 $DEVICE 0 | \ |
pascal@379 | 640 dmsetup create $(dmlabel $DEVICE) |
pascal@379 | 641 ;; |
pascal@379 | 642 add-crypto) |
pascal@379 | 643 if cryptsetup isLuks $DEVICE 2> /dev/null; then |
pascal@379 | 644 xterm -T "Open LUKS" -e \ |
pascal@379 | 645 "cryptsetup luksOpen $DEVICE $(dmlabel $DEVICE)" |
pascal@379 | 646 else |
pascal@379 | 647 export GET_PASS_PHRASE=" |
pascal@379 | 648 <window title=\"Crypto manager\" icon-name=\"media-flash\"> |
pascal@379 | 649 <vbox> |
pascal@379 | 650 <hbox> |
pascal@379 | 651 <text use-markup=\"true\"> |
pascal@379 | 652 <label>\"<b>Pass phrase :</b>\"</label> |
pascal@379 | 653 </text> |
pascal@379 | 654 <entry> |
pascal@379 | 655 <variable>PASS_PHRASE</variable> |
pascal@379 | 656 </entry> |
pascal@379 | 657 <button ok> |
pascal@379 | 658 <action>/usr/lib/slitaz/libmountbox add-old-crypto</action> |
pascal@379 | 659 <action type=\"closewindow\">GET_PASS_PHRASE</action> |
pascal@379 | 660 </button> |
pascal@379 | 661 </hbox> |
pascal@379 | 662 </vbox> |
pascal@379 | 663 </window>" |
pascal@379 | 664 gtkdialog --center --program=GET_PASS_PHRASE |
pascal@379 | 665 fi |
pascal@379 | 666 ;; |
pascal@379 | 667 remove-crypto) |
pascal@379 | 668 cryptsetup luksClose $CRYTO_DEV |
pascal@379 | 669 [ -e /dev/mapper/$CRYTO_DEV ] && dmsetup remove $CRYTO_DEV |
pascal@379 | 670 ;; |
pankso@183 | 671 *) |
pankso@183 | 672 usage ;; |
pankso@183 | 673 esac |
pankso@183 | 674 |
pankso@183 | 675 exit 0 |