some modification on instpkg
[cmdllinux.git] / scripts / manage / createswap-byid
blobb1fbae28559b8719898bfb7b40e79f515c0ecc48
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 lsswappart()
10 for drv in $(find /dev -maxdepth 1 -name "[hs]d[a-z]" -o -name "ub[a-z]" | sort); do
11 LC_ALL=C sfdisk -d $drv 2> /dev/null | grep "^/dev/" | \
12 while read LINE; do
13 if echo "$LINE" | grep -q "type=82\|type=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F"; then
14 DEVICE=$(echo "$LINE" | cut -d : -f 1 | tr -d " ")
15 DEVNAME=$(basename $DEVICE)
16 shopt -s lastpipe
17 (cd /dev/disk/by-id; ls -l ata-* usb-* scsi-* 2> /dev/null | \
18 sed -n -e 's%.*[[:space:]]\+\(ata-.*\)%\1%p' -e 's%.*[[:space:]]\+\(usb-.*\)%\1%p' \
19 -e 's%.*[[:space:]]\+\(scsi-.*\)%\1%p' | grep "/$DEVNAME$") | read -r DEV_ID LNK_S LNK
20 shopt -u lastpipe
21 if [ -n "$DEV_ID" ]; then
22 echo -n "$DEV_ID "
23 eval $(echo "$LINE" | cut -d : -f 2 | cut -d , -f 2 | tr -d " ")
24 echo -n "$(expr $size \* 512 / 1048576)MB "
27 done
28 done
31 $DIALOG --backtitle "Create swap on device" \
32 --title "" --clear \
33 --menu "Select partition" 20 70 15 \
34 `lsswappart` 2> $tempfile
36 retval=$?
38 choice=`cat $tempfile`
39 case $retval in
41 if [ ! -z "$choice" ]; then
42 DEV=`realpath /dev/disk/by-id/$choice`
43 mkswap $DEV
47 #cancel pressed
49 255)
50 #ESC pressed
52 esac