tazusb rev 47
Now support Fat32 and ext2 for format command.
author | erjo@localhost |
---|---|
date | Thu Nov 19 13:25:40 2009 +0100 (2009-11-19) |
parents | 01dc7df923e6 |
children | 3e207f1401be |
files | tazusb |
line diff
1.1 --- a/tazusb Thu Apr 16 02:01:20 2009 +0200 1.2 +++ b/tazusb Thu Nov 19 13:25:40 2009 +0100 1.3 @@ -8,12 +8,13 @@ 1.4 # Authors : Christophe Lincoln (Pankso) <pankso@slitaz.org> 1.5 # Andrew Miller (Spode) <spode@spodesabode.com> 1.6 # 1.7 -VERSION=2.1 1.8 +VERSION=2.1.1 1.9 1.10 COMMAND=$1 1.11 TARGET_ROOT=/media/flash 1.12 DRIVE_NAME=`cat /proc/sys/dev/cdrom/info | grep "drive name" | cut -f 3` 1.13 CDROM=/dev/$DRIVE_NAME 1.14 +LOG=/tmp/$(basename $0).log 1.15 1.16 # 1.17 # Tazusb functions 1.18 @@ -28,8 +29,8 @@ 1.19 usage Print this short usage. 1.20 writefs Write the current filesystem to rootfs.gz. 1.21 tazSupported compression: lzma. gzip, none. 1.22 - format Format and label device with ext3 filesystem 1.23 - (for LiveUSB or /home). 1.24 + format Format and label device with ext3, ext2 or fat32 filesystem 1.25 + (for LiveUSB or /home). Default is ext3. 1.26 gen-liveusb Generate a bootable LiveUSB using files from the LiveCD. 1.27 gen-swap Create or recreate and activate additional swap memory. 1.28 gen-iso2usb Generate a bootable LiveUSB using files from ISO file. 1.29 @@ -120,16 +121,94 @@ 1.30 1.31 } 1.32 1.33 +#Get label for device 1.34 +# 1.35 +get_label() 1.36 +{ 1.37 + echo -n "Please specify a label for the partition (TazUSB): " 1.38 + read label 1.39 + 1.40 + if [ -z $label ]; then 1.41 + label=TazUSB 1.42 + fi 1.43 +} 1.44 + 1.45 +#Get fs type 1.46 +# supported fs are ext3, ext2, fat32 1.47 +get_fs_type() 1.48 +{ 1.49 + echo -n "Please specify a filesystem type ext2, ext3 or fat32 (ext3): " 1.50 + read fs_type 1.51 + 1.52 + if [ -z $fs_type ]; then 1.53 + fs_type=ext3 1.54 + fi 1.55 +} 1.56 + 1.57 +# We can chose the filesystem type. 1.58 +ask_for_fs_type() 1.59 +{ 1.60 + echo -n "\ 1.61 +Please specify the filesystem type to $COMMAND. 1.62 +Available format is ext3(default), ext2 or fat32. 1.63 +Press enter to keep the default value. 1.64 + 1.65 +File system type : "; read anser 1.66 + if [ "$anser" = "" ]; then 1.67 + FS_TYPE=ext3 1.68 + else 1.69 + FS_TYPE=$anser 1.70 + fi 1.71 +} 1.72 + 1.73 +# Format target device in ext3, ext2 or fat32. 1.74 +# 1.75 +make_fs() 1.76 +{ 1.77 + local answer 1.78 + 1.79 + FS=$(echo $fs_type | tr [A-Z] [a-z]) 1.80 + case "$FS" in 1.81 + ext3|ext2) 1.82 + echo -e "\nProcessiong..." 1.83 + echo "Label : $label" 1.84 + echo "Mkfs : mkfs.$FS -L \"$label\" $DEVICE" 1.85 + echo "" && sleep 2 1.86 + mkfs.$@ -L "$label" $DEVICE > $LOG 2>&1 1.87 + ;; 1.88 + [Ff]at32) 1.89 + if [ -x /sbin/mkdosfs ];then 1.90 + echo -e "\nProcessiong..." 1.91 + echo "Label : $label" 1.92 + echo "Mkfs : mkdosfs -F 32 -n \"$label\" $DEVICE" 1.93 + echo "" && sleep 2 1.94 + mkdosfs -F 32 -n "$label" $DEVICE 1.95 + else 1.96 + echo -ne "Can't find mkdosfs tool.\nWould you like to install dosfstools from repository [y/N] ? "; read answer 1.97 + case $answer in 1.98 + y|Y) 1.99 + yes | tazpkg get-install dosfstools && make_fs fat32;; 1.100 + *) 1.101 + exit 1 ;; 1.102 + esac 1.103 + fi 1.104 + ;; 1.105 + *) 1.106 + echo "Sorry. Filesystem $FS not supported." 1.107 + exit 1.108 + esac 1.109 +} 1.110 + 1.111 # Mount an existing USB device. 1.112 unmount_target_usb() 1.113 { 1.114 # If mount point is in use, unmount 1.115 - if mount | grep $TARGET_ROOT; then 1.116 + if mount | grep -q $TARGET_ROOT; then 1.117 umount $TARGET_ROOT 1.118 fi 1.119 1.120 # Device could be mounted elsewhere, so unmount 1.121 - if mount | grep $DEVICE; then 1.122 + if mount | grep -q $DEVICE; then 1.123 echo "Unmounting USB target device..." 1.124 umount $DEVICE 1.125 fi 1.126 @@ -455,13 +534,18 @@ 1.127 echo -e "\033[1mFormat a device\033[0m" 1.128 echo "===============================================================================" 1.129 DEVICE=$2 1.130 + label=$3 1.131 + fs_type=$4 1.132 if [ -z $DEVICE ]; then 1.133 ask_for_device 1.134 check_for_device 1.135 else 1.136 echo "Device : $DEVICE" 1.137 fi 1.138 - mkfs_ext3 1.139 + test -z $fs_type && get_fs_type 1.140 + unmount_target_usb 1.141 + make_fs "$fs_type" 1.142 + #mkfs_ext3 1.143 echo "===============================================================================" 1.144 echo "Device $label ($DEVICE) is ready to use as LiveUSB and/or /home partition." 1.145 echo "" 1.146 @@ -492,7 +576,7 @@ 1.147 check_root 1.148 gen_swap_file 1.149 ;; 1.150 - gen-iso2usb) 1.151 + gen-iso2usb|iso2usb) 1.152 check_root 1.153 1.154 # Check if file exists