From c2f6a126ee3bb984e1d453a629c34cd67d2484e6 Mon Sep 17 00:00:00 2001 From: nemetho Date: Sun, 31 Dec 2017 17:07:56 +0100 Subject: [PATCH] improve createfs createswap (by-id listing) --- scripts/manage/createfs-byid | 79 ++++++++++++++++++++++++++++++++++++++++++ scripts/manage/createswap-byid | 52 +++++++++++++++++++++++++++ scripts/manage/mkdisklabel | 4 +-- scripts/manage/partdrive | 4 +-- 4 files changed, 135 insertions(+), 4 deletions(-) create mode 100755 scripts/manage/createfs-byid create mode 100755 scripts/manage/createswap-byid diff --git a/scripts/manage/createfs-byid b/scripts/manage/createfs-byid new file mode 100755 index 0000000..3dbc68e --- /dev/null +++ b/scripts/manage/createfs-byid @@ -0,0 +1,79 @@ +#! /bin/sh + +: ${DIALOG=dialog} + +tempfile=`mktemp 2> /dev/null` || tempfile=/tmp/test$$ +trap "rm -f $tempfile" 0 1 2 5 15 + + +lslinpart() +{ +for drv in $(find /dev -maxdepth 1 -name "[hs]d[a-z]" -o -name "ub[a-z]" | sort); do + LC_ALL=C sfdisk -d $drv 2> /dev/null | grep "^/dev/" | \ + while read LINE; do + if echo "$LINE" | grep -q "type=83"; then + DEVICE=$(echo "$LINE" | cut -d : -f 1 | tr -d " ") + DEVNAME=$(basename $DEVICE) + shopt -s lastpipe + (cd /dev/disk/by-id; ls -l ata-* usb-* scsi-* 2> /dev/null | \ + sed -n -e 's%.*[[:space:]]\+\(ata-.*\)%\1%p' -e 's%.*[[:space:]]\+\(usb-.*\)%\1%p' \ + -e 's%.*[[:space:]]\+\(scsi-.*\)%\1%p' | grep "/$DEVNAME$") | read -r DEV_ID LNK_S LNK + shopt -u lastpipe + if [ -n "$DEV_ID" ]; then + echo -n "$DEV_ID " + eval $(echo "$LINE" | cut -d : -f 2 | cut -d , -f 2 | tr -d " ") + echo -n "$(expr $size \* 512 / 1048576)MB " + fi + fi + done +done +} + +$DIALOG --backtitle "Create filesystem on device" \ + --title "" --clear \ + --menu "Select partition" 20 70 15 \ + `lslinpart` 2> $tempfile + +retval=$? + +choice=`cat $tempfile` +case $retval in + 0) + if [ ! -z "$choice" ]; then + DEV=`realpath /dev/disk/by-id/$choice` + + $DIALOG --backtitle "Create filesystem on device" \ + --title "" --clear --default-item ext4 \ + --menu "Select filesystem to create ($DEV)" 20 61 15 \ + `find /sbin -name "mkfs.*" | cut -d "." -f 2 | grep -v "bfs\|cramfs\|ext4dev" | sort | sed 's/.*/& $tempfile + + retval=$? + + choice=`cat $tempfile` + case $retval in + 0) + if [ ! -z "$choice" ]; then + [ "$choice" = "xfs" ] && mkfsopt="-f" + [ "$choice" = "jfs" ] && mkfsopt="-q" + [ "$choice" = "reiserfs" ] && mkfsopt="-q" + [ "$choice" = "reiser4" ] && mkfsopt="-y" + mkfs.$choice $mkfsopt $DEV + fi + ;; + 1) + #cancel pressed + ;; + 255) + #ESC pressed + ;; + esac + + fi + ;; + 1) + #cancel pressed + ;; + 255) + #ESC pressed + ;; +esac diff --git a/scripts/manage/createswap-byid b/scripts/manage/createswap-byid new file mode 100755 index 0000000..4e89391 --- /dev/null +++ b/scripts/manage/createswap-byid @@ -0,0 +1,52 @@ +#! /bin/sh + +: ${DIALOG=dialog} + +tempfile=`mktemp 2> /dev/null` || tempfile=/tmp/test$$ +trap "rm -f $tempfile" 0 1 2 5 15 + +lsswappart() +{ +for drv in $(find /dev -maxdepth 1 -name "[hs]d[a-z]" -o -name "ub[a-z]" | sort); do + LC_ALL=C sfdisk -d $drv 2> /dev/null | grep "^/dev/" | \ + while read LINE; do + if echo "$LINE" | grep -q "type=82"; then + DEVICE=$(echo "$LINE" | cut -d : -f 1 | tr -d " ") + DEVNAME=$(basename $DEVICE) + shopt -s lastpipe + (cd /dev/disk/by-id; ls -l ata-* usb-* scsi-* 2> /dev/null | \ + sed -n -e 's%.*[[:space:]]\+\(ata-.*\)%\1%p' -e 's%.*[[:space:]]\+\(usb-.*\)%\1%p' \ + -e 's%.*[[:space:]]\+\(scsi-.*\)%\1%p' | grep "/$DEVNAME$") | read -r DEV_ID LNK_S LNK + shopt -u lastpipe + if [ -n "$DEV_ID" ]; then + echo -n "$DEV_ID " + eval $(echo "$LINE" | cut -d : -f 2 | cut -d , -f 2 | tr -d " ") + echo -n "$(expr $size \* 512 / 1048576)MB " + fi + fi + done +done +} + +$DIALOG --backtitle "Create swap on device" \ + --title "" --clear \ + --menu "Select partition" 20 70 15 \ + `lsswappart` 2> $tempfile + +retval=$? + +choice=`cat $tempfile` +case $retval in + 0) + if [ ! -z "$choice" ]; then + DEV=`realpath /dev/disk/by-id/$choice` + mkswap $DEV + fi + ;; + 1) + #cancel pressed + ;; + 255) + #ESC pressed + ;; +esac diff --git a/scripts/manage/mkdisklabel b/scripts/manage/mkdisklabel index 3e8e041..8490a39 100755 --- a/scripts/manage/mkdisklabel +++ b/scripts/manage/mkdisklabel @@ -8,8 +8,8 @@ trap "rm -f $tempfile" 0 1 2 5 15 lsdev() { test -L /sys/block/$(ls /sys/block | head -n 1) && \ - find /sys/devices -path "*/block/*" \( -name "sd[a-z]" -o -name "ub[a-z]" \) || \ - find /sys/block \( -name "sd[a-z]" -o -name "ub[a-z]" \) + find /sys/devices -path "*/block/*" \( -name "[hs]d[a-z]" -o -name "ub[a-z]" \) || \ + find /sys/block \( -name "[hs]d[a-z]" -o -name "ub[a-z]" \) } lsdrives() diff --git a/scripts/manage/partdrive b/scripts/manage/partdrive index 03983d8..6f4e02b 100755 --- a/scripts/manage/partdrive +++ b/scripts/manage/partdrive @@ -8,8 +8,8 @@ trap "rm -f $tempfile" 0 1 2 5 15 lsdev() { test -L /sys/block/$(ls /sys/block | head -n 1) && \ - find /sys/devices -path "*/block/*" \( -name "sd[a-z]" -o -name "ub[a-z]" \) || \ - find /sys/block \( -name "sd[a-z]" -o -name "ub[a-z]" \) + find /sys/devices -path "*/block/*" \( -name "[hs]d[a-z]" -o -name "ub[a-z]" \) || \ + find /sys/block \( -name "[hs]d[a-z]" -o -name "ub[a-z]" \) } lsdrives() -- 2.11.4.GIT