update repository
[cmdllinux.git] / scripts / manage / createfs.sgdisk
blob1a53b7ceda56ed7884d6cab96dcec3d8abde669f
1 #! /bin/bash
3 : ${DIALOG=dialog}
5 tempfile=`mktemp 2> /dev/null` || tempfile=/tmp/test$$
6 trap "rm -f $tempfile" 0 1 2 5 15
8 gptlspart()
10 ###sgdisk - test if sgdisk prints the name of partition type or not
12 lsnum=0
13 for drv in $(find /dev -maxdepth 1 -name "[hs]d[a-z]" -o -name "ub[a-z]" | sort); do
14 LC_ALL=C sgdisk -p $drv | grep "Linux filesystem$" | \
15 while read num start end size amo rest; do
16 echo "$drv$num $size$amo"
17 lsnum=`expr $lsnum + 1`
18 done
19 done
21 if [ $lsnum = 0 ]; then
23 for drv in $(find /dev -maxdepth 1 -name "[hs]d[a-z]" -o -name "ub[a-z]" | sort); do
24 LC_ALL=C sgdisk -p $drv | grep "8300 $" | \
25 while read num start end size amo rest; do
26 echo "$drv$num $size$amo"
27 done
28 done
32 #LC_ALL=C fdisk -l | grep "^/dev/.*Linux$" | cut -d " " -f 1 | sed 's/.*/& </'
34 $DIALOG --backtitle "Create filesystem on device" \
35 --title "" --clear \
36 --menu "Select partition" 20 61 15 \
37 `gptlspart` 2> $tempfile
39 retval=$?
41 choice=`cat $tempfile`
42 case $retval in
44 if [ ! -z "$choice" ]; then
45 DEV=$choice
47 $DIALOG --backtitle "Create filesystem on device" \
48 --title "" --clear --default-item ext4 \
49 --menu "Select filesystem to create ($DEV)" 20 61 15 \
50 `find /sbin -name "mkfs.*" | cut -d "." -f 2 | grep -v "bfs\|cramfs\|ext4dev" | sort | sed 's/.*/& </'` 2> $tempfile
52 retval=$?
54 choice=`cat $tempfile`
55 case $retval in
57 if [ ! -z "$choice" ]; then
58 [ "$choice" = "xfs" ] && mkfsopt="-f"
59 [ "$choice" = "jfs" ] && mkfsopt="-q"
60 [ "$choice" = "reiserfs" ] && mkfsopt="-q"
61 [ "$choice" = "reiser4" ] && mkfsopt="-y"
62 mkfs.$choice $mkfsopt $DEV
66 #cancel pressed
68 255)
69 #ESC pressed
71 esac
76 #cancel pressed
78 255)
79 #ESC pressed
81 esac