some modification on instpkg
[cmdllinux.git] / scripts / manage / createswap.sgdisk
blob4db0d8226c64d7cf4fae7ad4d2ec14c35a8a8f38
1 #! /bin/sh
3 : ${DIALOG=dialog}
5 tempfile=`mktemp 2> /dev/null` || tempfile=/tmp/test$$
6 trap "rm -f $tempfile" 0 1 2 5 15
8 gptlsswap()
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 swap$" | \
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 "8200 $" | \
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/.*swap" | cut -d " " -f 1 | sed 's/.*/& </'
34 $DIALOG --backtitle "Create swap on device" \
35 --title "" --clear \
36 --menu "Select partition" 20 61 15 \
37 `gptlsswap` 2> $tempfile
39 retval=$?
41 choice=`cat $tempfile`
42 case $retval in
44 [ ! -z "$choice" ] && mkswap $choice
47 #cancel pressed
49 255)
50 #ESC pressed
52 esac