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