parent
d8848f1108
commit
4a818bb2d5
@ -1,3 +1,28 @@
|
|||||||
# disks
|
# disks
|
||||||
|
|
||||||
Scripts for disks
|
Scripts for disks
|
||||||
|
|
||||||
|
**PLEASE NOTE:** These scripts should be considered experimental.
|
||||||
|
Test on non-production or backed-up data first.
|
||||||
|
|
||||||
|
- ckalign
|
||||||
|
> Check if a given sector number is aligned on a 4k boundary
|
||||||
|
- ctoa
|
||||||
|
> CrypTab Open All: Opens all devices listed in /etc/cryptab
|
||||||
|
- drvspeed
|
||||||
|
> Reports speeds of all devices using hdparm
|
||||||
|
- ddi
|
||||||
|
> Dump Disk Info: Dumps UUID and Label to .uuid and .label files in root of device
|
||||||
|
- filldev
|
||||||
|
> Fills a hard drive with 0's or with random data
|
||||||
|
- lctopen
|
||||||
|
> LUKS CrypTab Open: Opens a device in /etc/cryptab given a unique identifier)
|
||||||
|
- makeraid
|
||||||
|
> Make a RAID device
|
||||||
|
- mkcrypt
|
||||||
|
> Make a crypt device
|
||||||
|
- nhdtest
|
||||||
|
> Tests new hard drives
|
||||||
|
- partcopy
|
||||||
|
> Copies the contents of one partition to another (takes care of mounting and unmounting)
|
||||||
|
- partvis
|
||||||
|
> Displays device partitions on the command line
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ ${1} == "-e" -o ${1} == "--end" ]; then
|
||||||
|
BOUNDADJ=1
|
||||||
|
elif [ ${1} == "-s" -o ${1} == "--start" ]; then
|
||||||
|
BOUNDADJ=0
|
||||||
|
else
|
||||||
|
echo "Neither '--start' nor '--end' were specified."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
BOUNDARY=$(( ${2} + BOUNDADJ ))
|
||||||
|
|
||||||
|
ALIGN_4K=$(( BOUNDARY / 8 ))
|
||||||
|
SECTS_4K=$(( ALIGN_4K * 8 ))
|
||||||
|
((SECTS_4K-=${BOUNDADJ}))
|
||||||
|
|
||||||
|
ALIGN_1M=$(( BOUNDARY / 2048 ))
|
||||||
|
SECTS_1M=$(( ALIGN_1M * 2048 ))
|
||||||
|
((SECTS_1M-=${BOUNDADJ}))
|
||||||
|
|
||||||
|
if [ ${2} -eq ${SECTS_4K} ]; then
|
||||||
|
echo "Boundary is 4K aligned."
|
||||||
|
else
|
||||||
|
echo "Boundary is not 4K aligned. Proper alignment would be ${SECTS_4K} or $(( SECTS_4K + 8 ))."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${2} -eq ${SECTS_1M} ]; then
|
||||||
|
echo "Boundary ${2} is 1M aligned."
|
||||||
|
else
|
||||||
|
echo "Boundary is not 1M aligned. Proper alignment would be ${SECTS_1M} or $(( SECTS_1M + 2048 ))."
|
||||||
|
fi
|
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# CryptTab Open
|
||||||
|
|
||||||
|
while read -r NAME DEV KEY OPTS; do
|
||||||
|
if [ -f "${KEY}" ]; then
|
||||||
|
cryptsetup open "${DEV}" "${NAME}" --key-file "${KEY}"
|
||||||
|
else
|
||||||
|
cryptsetup open "${DEV}" "${NAME}"
|
||||||
|
fi
|
||||||
|
done <<< $(grep -v '^#' /etc/crypttab | sed '/^[[:space:]]*$/d' | sed 's/[[:space:]]\{1,\}/\t/g' | sed 's|UUID=|/dev/disk/by-uuid/|g')
|
@ -0,0 +1,10 @@
|
|||||||
|
# DDI - Dump Disk Information
|
||||||
|
#
|
||||||
|
# Dumps the UUID and label of a filesystem to its / (root) directory.
|
||||||
|
# Parses df output to find current mounts and then uses lsblk to get info.
|
||||||
|
|
||||||
|
for dev in `df -h | grep ^/dev | cut -d\ -f1 | cut -d/ -f3`; do
|
||||||
|
loc=`cat /proc/mounts | grep $dev | cut -d\ -f2`
|
||||||
|
lsblk -fn -o UUID /dev/$dev > $loc/.uuid
|
||||||
|
lsblk -fn -o LABEL /dev/$dev > $loc/.label
|
||||||
|
done
|
@ -0,0 +1,45 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
DEVICES="$(lsblk -l -x NAME -o NAME | tail -n +2 | cut -d\ -f1 | grep -v '[0-9]' | tr '\n' ' ') $(find /dev -maxdepth 1 -type b -name 'md*'|sort -V|rev|cut -d/ -f1|rev) $(find /dev -maxdepth 1 -type b -name 'dm-*'|sort -V|rev|cut -d/ -f1|rev)"
|
||||||
|
|
||||||
|
case ${1} in
|
||||||
|
t)
|
||||||
|
|
||||||
|
sudo echo -n '╔══════╤'
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
printf "%6s╤" "══════"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -ne '\b╗\n║DEVICE│'
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
printf "%6s│" "${DEVICE}"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -ne '\b║\n╟──────┼'
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
printf "%6s┼" "──────"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -ne '\b╢\n║MB/sec│'
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
printf "%6s│" "$(sudo hdparm -t --direct /dev/${DEVICE} 2> /dev/null | grep 'MB/sec' | cut -d= -f2 | sed 's/\s\s*//g;s/MB\/sec//g')"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -ne '\b║\n╚══════╧'
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
printf "%6s╧" "══════"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -ne '\b╝\n'
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
|
||||||
|
sudo echo -n "DISK SPEED (MB/s): "
|
||||||
|
for DEVICE in $DEVICES; do
|
||||||
|
echo -n "${DEVICE}="
|
||||||
|
echo -n "$(sudo hdparm -t --direct /dev/${DEVICE} 2> /dev/null | grep 'MB/sec' | cut -d= -f2 | sed 's/\s\s*//g;s/MB\/sec//g'),"
|
||||||
|
done
|
||||||
|
echo -e '\b \b'
|
||||||
|
|
||||||
|
;;
|
||||||
|
esac
|
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo echo "garbage" > /dev/null
|
||||||
|
while [ $? -ne 0 ]; do !!; done
|
||||||
|
|
||||||
|
SEC=falase
|
||||||
|
|
||||||
|
for ARG in "$@"; do
|
||||||
|
case "${ARG}" in
|
||||||
|
"--secure") SEC=true ;;
|
||||||
|
*) [[ -b "${ARG}" ]] && DVC+=("${ARG}") || ( echo "${ARG} is not a block device"; exit 1 ) ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
echo -n "Filling ${DVC[@]} with "
|
||||||
|
${SEC} && echo "random data" || echo "zeros"
|
||||||
|
|
||||||
|
for DEV in "${DVC[@]}"; do
|
||||||
|
echo "${DEV}:"
|
||||||
|
${SEC} && openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | sudo dd of=${DEV} bs=4M status=progress
|
||||||
|
${SEC} || sudo dd if=/dev/zero of=${DEV} bs=4M status=progress
|
||||||
|
done
|
@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
blargityblargblarg &> /dev/null
|
||||||
|
while [ ${?} != 0 ]; do
|
||||||
|
sudo echo 'test' > /dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
COUNT=$(sudo grep -c "${1}" /etc/crypttab)
|
||||||
|
|
||||||
|
[[ ${COUNT} -eq 0 ]] && echo "Identifier '${1}' not found." && exit 1
|
||||||
|
[[ ${COUNT} -gt 1 ]] && echo "Identifier '${1}' is not unique." && exit 1
|
||||||
|
|
||||||
|
CTLINE=$(sudo grep "${1}" /etc/crypttab)
|
||||||
|
|
||||||
|
echo "Identifier '${1}' found in the following line:"
|
||||||
|
echo "${CTLINE}"
|
||||||
|
|
||||||
|
MPNAME=$(sudo grep "${1}" /etc/crypttab | sed 's/#//g;s/ */ /g;s/ /\t/g' | awk '{ print $1 }')
|
||||||
|
DEVICE=$(sudo grep "${1}" /etc/crypttab | sed 's/#//g;s/ */ /g;s/ /\t/g;s/UUID=/\/dev\/disk\/by-uuid\//g' | awk '{ print $2 }')
|
||||||
|
KEYFIL=$(sudo grep "${1}" /etc/crypttab | sed 's/#//g;s/ */ /g;s/ /\t/g' | awk '{ print $3 }')
|
||||||
|
|
||||||
|
set -x
|
||||||
|
sudo cryptsetup open "${DEVICE}" "${MPNAME}" --key-file "${KEYFIL}"
|
@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
help() {
|
||||||
|
echo "USAGE: makeraid [level] [device] [device] ... [ [--spares] [device] ... ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
[[ :0:1:4:5:6:10: == *:${1}:* ]] && RL=${1} || { help; exit 1; }
|
||||||
|
shift
|
||||||
|
|
||||||
|
until [ "${1}" = "--spares" ]; do
|
||||||
|
[ -b "${1}" ] && RD+=("${1}") || { help; exit 2; }
|
||||||
|
shift
|
||||||
|
[ ${#} = 0 ] && break
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${1}" == "--spares" ]; then
|
||||||
|
shift
|
||||||
|
for DV in ${@}; do
|
||||||
|
SD+=("${DV}")
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ "${#SD[@]}" -gt "0" ] && SO=( "-x" "${#SD[@]}" )
|
||||||
|
|
||||||
|
for MD in {0..127}; do
|
||||||
|
[ ! -b "/dev/md${MD}" ] && ND=${MD} && break
|
||||||
|
done
|
||||||
|
|
||||||
|
mdadm -Cve 1.2 /dev/md${ND} -l "${RL}" -c 32 -n ${#RD[@]} ${RD[@]} ${SO[@]} ${SD[@]}
|
@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
CIPHER="aes-xts-plain64"
|
||||||
|
KEYSIZ='512'
|
||||||
|
HSHTYP='sha512'
|
||||||
|
ITTIME='5000'
|
||||||
|
USERAN='random'
|
||||||
|
DEVICE="${1}"
|
||||||
|
|
||||||
|
# WE NEED ROOT PRIVILEGES
|
||||||
|
|
||||||
|
if [ $EUID -ne 0 ]; then
|
||||||
|
echo "This script must be run as root."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# CONFIRM THE DEVICE
|
||||||
|
|
||||||
|
echo "You are about to format the following device with LUKS:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
\lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT,LABEL,UUID "${DEVICE}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -n "Are you sure [y/N]? "
|
||||||
|
read CONFRM
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "${CONFRM,,}" = "y" ]; then
|
||||||
|
|
||||||
|
echo -n "Fill ${DEVICE} with random data [Y/n]? "
|
||||||
|
read DEVFIL
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "${DEVFIL,,}" = "n" ]; then
|
||||||
|
echo "Not filling ${DEVICE} with random data."
|
||||||
|
else
|
||||||
|
echo "Filling ${DEVICE} with random data..."
|
||||||
|
echo ""
|
||||||
|
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt </dev/zero | sudo dd of=${DEVICE} bs=4M status=progress
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "Setting up encryption with password..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
cryptsetup --verbose --cipher "${CIPHER}" --key-size "${KEYSIZ}" --hash "${HSHTYP}" --iter-time "${ITTIME}" --use-${USERAN} --verify-passphrase luksFormat "${DEVICE}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo -n "Do you wish to also use a key file [y/N]? "
|
||||||
|
read CONFRM
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
if [ "${CONFRM,,}" = "y" ]; then
|
||||||
|
echo -n "Path to key file: "
|
||||||
|
read EKFILE
|
||||||
|
echo ""
|
||||||
|
cryptsetup --verbose luksAddKey "${DEVICE}" "${EKFILE}"
|
||||||
|
echo ""
|
||||||
|
fi
|
||||||
|
|
||||||
|
DVUUID="$(\lsblk -nlo UUID "${DEVICE}")"
|
||||||
|
DVNAME="$(\lsblk -nlo MODEL,SERIAL "${DEVICE}" | sed 's/ */ /g' | tr ' ' '_')"
|
||||||
|
|
||||||
|
echo "Added the following line to /etc/crypttab:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "${DVNAME}"$'\t'"UUID=${DVUUID}"$'\t'"${EKFILE}"$'\t'"cipher=aes-xts-plain64:sha512:size=512" | tee -a /etc/crypttab
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo "Aborting."
|
||||||
|
|
||||||
|
fi
|
@ -0,0 +1,49 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
SECTORS=$(parted ${1} unit s print | grep '^Disk /dev' | cut -d: -f2 | sed 's/ //g;s/s//g')
|
||||||
|
HDDSIZE=$((${SECTORS} * 512))
|
||||||
|
BLKSIZE=$((4 * 1024))
|
||||||
|
TBLOCKS=$((${HDDSIZE} / ${BLKSIZE}))
|
||||||
|
|
||||||
|
DESTROY=true
|
||||||
|
EXHAUST=12
|
||||||
|
echo Device ${1} is $(printf "%'d" ${HDDSIZE}) bytes
|
||||||
|
echo Testing $(printf "%'d" ${TBLOCKS}) blocks of $(printf "%'d\n" ${BLKSIZE}) bytes using 1/${EXHAUST} exhaustion.
|
||||||
|
POINTER=$((${RANDOM} % ${EXHAUST}))
|
||||||
|
|
||||||
|
BEGIN=$(date +%s)
|
||||||
|
|
||||||
|
until [ ${POINTER} = ${TBLOCKS} ]; do
|
||||||
|
# RUNTIME=$(($(date +%s) - ${BEGIN}))
|
||||||
|
# RTD=$((${RUNTIME} / 86400))
|
||||||
|
# RTH=$((${RUNTIME} % 86400 / 3600))
|
||||||
|
# RTM=$((${RUNTIME} % 3600 / 60))
|
||||||
|
# RTS=$((${RUNTIME} % 60))
|
||||||
|
|
||||||
|
# ETATIME=$(echo "scale=6;${RUNTIME}/(${POINTER}+1)*${TBLOCKS}+0.5" | bc | cut -d. -f1)
|
||||||
|
# [[ -z ${ETATIME} ]] && ETATIME=0
|
||||||
|
# ETD=$((${ETATIME} / 86400))
|
||||||
|
# ETH=$((${ETATIME} % 86400 / 3600))
|
||||||
|
# ETM=$((${ETATIME} % 3600 / 60))
|
||||||
|
# ETS=$((${ETATIME} % 60))
|
||||||
|
|
||||||
|
# ETRTIME=$((${ETATIME} - ${RUNTIME}))
|
||||||
|
# ERD=$((${ETRTIME} / 86400))
|
||||||
|
# ERH=$((${ETRTIME} % 86400 / 3600))
|
||||||
|
# ERM=$((${ETRTIME} % 3600 / 60))
|
||||||
|
# ERS=$((${ETRTIME} % 60))
|
||||||
|
|
||||||
|
# echo -n RUN $(printf "%02d:%02d:%02d:%02d\n" ${RTD} ${RTH} ${RTM} ${RTS})' '
|
||||||
|
# echo -n ETA $(printf "%02d:%02d:%02d:%02d\n" ${ETD} ${ETH} ${ETM} ${ETS})' '
|
||||||
|
# echo -n ETR $(printf "%02d:%02d:%02d:%02d\n" ${ERD} ${ERH} ${ERM} ${ERS})' '
|
||||||
|
|
||||||
|
echo -n BLK $(printf "%012d" ${POINTER} | sed 's/\(...\)\(...\)\(...\)\(...\)/\1,\2,\3,\4/g')...
|
||||||
|
|
||||||
|
RNDDATA="$(dd if=/dev/urandom bs=${BLKSIZE} count=1 status=none | base64)"; echo -n G
|
||||||
|
${DESTROY} || ( ORGDATA="$(dd if=${1} bs=${BLKSIZE} count=1 skip=${POINTER} status=none | base64)"; echo -n B )
|
||||||
|
echo "${RNDDATA}" | base64 --decode | dd of=${1} bs=${BLKSIZE} seek=${POINTER} status=none; sync; echo -n W
|
||||||
|
CHKDATA=$(dd if=${1} bs=${BLKSIZE} count=1 skip=${POINTER} status=none| base64); echo -n V
|
||||||
|
${DESTROY} || ( echo "${ORGDATA}" | base64 --decode | dd of=${1} bs=${BLKSIZE} seek=${POINTER} status=none; sync; echo -n R )
|
||||||
|
[[ "${CHKDATA}" == "${RNDDATA}" ]] && echo -ne "\r" || echo "...FAILED"
|
||||||
|
((POINTER+=${EXHAUST}))
|
||||||
|
done
|
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
OLDFST="$(lsblk -no FSTYPE /dev/$1)"
|
||||||
|
OLDLBL="$(lsblk -no LABEL /dev/$1)"
|
||||||
|
OLDUID="$(lsblk -no UUID /dev/$1)"
|
||||||
|
NEWFST="$(lsblk -no FSTYPE /dev/$2)"
|
||||||
|
NEWLBL="$(lsblk -no LABEL /dev/$2)"
|
||||||
|
NEWUID="$(lsblk -no UUID /dev/$2)"
|
||||||
|
|
||||||
|
[ ! -e /dev/$1 ] && echo "Device /dev/$1 does not exist." && exit 1
|
||||||
|
[ ! -e /dev/$2 ] && echo "Device /dev/$2 does not exist." && exit 1
|
||||||
|
|
||||||
|
clear
|
||||||
|
|
||||||
|
echo -e " --DEVICE-- -FS- -----LABEL------ ----------------UUID----------------\nOLD:\nNEW:"
|
||||||
|
|
||||||
|
tput cup 1 5; echo -e /dev/$1
|
||||||
|
tput cup 1 16; echo -e $OLDFST
|
||||||
|
tput cup 1 21; echo -e $OLDLBL
|
||||||
|
tput cup 1 38; echo -e $OLDUID
|
||||||
|
|
||||||
|
tput cup 2 5; echo -e /dev/$2
|
||||||
|
tput cup 2 16; echo -e $NEWFST
|
||||||
|
tput cup 2 21; echo -e $NEWLBL
|
||||||
|
tput cup 2 38; echo -e $NEWUID
|
||||||
|
|
||||||
|
echo ''
|
||||||
|
read -n 1 -p 'CANCEL WITH CTRL+C OR PRESS ANY KEY TO CONTNUE...'
|
||||||
|
|
||||||
|
[[ $3 != nozero ]] && dcfldd if=/dev/zero of=/dev/$2 bs=4M
|
||||||
|
mkfs -t $OLDFST -L "$OLDLBL" -U $OLDUID /dev/$2
|
||||||
|
mkdir -p /mnt/partcopy-{old,new}
|
||||||
|
mount /dev/$1 /mnt/partcopy-old
|
||||||
|
mount /dev/$2 /mnt/partcopy-new
|
||||||
|
rsync -avPH --numeric-ids /mnt/partcopy-old/ /mnt/partcopy-new
|
||||||
|
umount /dev/$2
|
||||||
|
umount /dev/$1
|
||||||
|
rmdir /mnt/partcopy-{old,new}
|
@ -0,0 +1,144 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
sectors_to_size() {
|
||||||
|
|
||||||
|
SIZE=$(( ${1} * 512 ))
|
||||||
|
MAG=0
|
||||||
|
until [ $(awk "BEGIN { print ${SIZE} < 1000 }") -eq 1 ]; do
|
||||||
|
SIZE=$(awk "BEGIN { print ${SIZE} / 1024 }" )
|
||||||
|
((MAG++))
|
||||||
|
done
|
||||||
|
case ${MAG} in
|
||||||
|
0) TAG="" ;;
|
||||||
|
1) TAG="Ki" ;;
|
||||||
|
2) TAG="Mi" ;;
|
||||||
|
3) TAG="Gi" ;;
|
||||||
|
4) TAG="Ti" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf "%.4g%s\n" "${SIZE}" "${TAG}B"
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $EUID -gt 0 ] && "Must run as superuser." && exit 1
|
||||||
|
#[ ! -b "${1}" ] && "${1} is not a block device." && exit 2
|
||||||
|
|
||||||
|
#for DEVICE in $(fdisk -l | grep '^Disk /' | cut -d\ -f2 | cut -d: -f1); do
|
||||||
|
for DEVICE in $(fdisk -l | grep '^Disk /' | grep -v '/dev/ram' | cut -d\ -f2 | cut -d: -f1); do
|
||||||
|
|
||||||
|
FDISKDATA="$(fdisk -l "${DEVICE}")"
|
||||||
|
COLS="$(tput cols)"
|
||||||
|
SECTORS="$(echo "${FDISKDATA}" | grep sectors | grep -v 'sectors of' | rev | cut -d\ -f2 | rev)"
|
||||||
|
#PARTLIST="$(echo "${FDISKDATA}" | grep '^/' | sed 's/ */ /g' | cut -d\ -f1-3)"
|
||||||
|
PARTLIST="$(echo "${FDISKDATA}" | grep '^/' | grep -v 'Extended$' | sed -e 's/*/ /' -e 's/ \+/ /g' | cut -d\ -f1-3)"
|
||||||
|
|
||||||
|
PARTITIONS=()
|
||||||
|
SIZE_LOG=0
|
||||||
|
PARTSECTS=()
|
||||||
|
PARTSIZES=()
|
||||||
|
SIZETOTAL=0
|
||||||
|
PRINTCOLS=0
|
||||||
|
PCOLS=()
|
||||||
|
|
||||||
|
if [ -z "${PARTLIST}" ]; then
|
||||||
|
PARTITIONS=${DEVICE}
|
||||||
|
SIZE_LOG=1
|
||||||
|
PARTSECTS=${SECTORS}
|
||||||
|
PARTSIZES=1
|
||||||
|
SIZETOTAL=1
|
||||||
|
else
|
||||||
|
LASTEND=0
|
||||||
|
while read -r PARTITION PARTSTART PARTEND; do
|
||||||
|
if [ ${PARTSTART} -gt $(( ${LASTEND} + 2049 )) ]; then
|
||||||
|
PARTITIONS+=( "Gap" )
|
||||||
|
SIZE_LOG=( $(awk "BEGIN { print log( ${PARTSTART} - ${LASTEND} ) / log( ${SECTORS} ) }") )
|
||||||
|
PARTSECTS+=( $(awk "BEGIN { print ${PARTSTART} - ${LASTEND} }") )
|
||||||
|
PARTSIZES+=( ${SIZE_LOG} )
|
||||||
|
SIZETOTAL=$(awk "BEGIN { print ${SIZETOTAL} + ${SIZE_LOG} }")
|
||||||
|
fi
|
||||||
|
PARTITIONS+=( ${PARTITION} )
|
||||||
|
SIZE_LOG=( $(awk "BEGIN { print log( ${PARTEND} - ${PARTSTART} + 1 ) / log( ${SECTORS} ) }") )
|
||||||
|
PARTSECTS+=( $(awk "BEGIN { print ${PARTEND} - ${PARTSTART} + 1 }") )
|
||||||
|
PARTSIZES+=( ${SIZE_LOG} )
|
||||||
|
SIZETOTAL=$(awk "BEGIN { print ${SIZETOTAL} + ${SIZE_LOG} }")
|
||||||
|
LASTEND=${PARTEND}
|
||||||
|
done <<< "${PARTLIST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
FACTOR=$(awk "BEGIN { print ( ${COLS} - ${#PARTITIONS[@]} - 1 ) / ${SIZETOTAL} }")
|
||||||
|
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
PRINTCOLS=$(( ${PRINTCOLS} + $(awk "BEGIN { print int ( ${PARTSIZES[${LCV}]} * ${FACTOR} + 0.5 ) }") ))
|
||||||
|
PCOLS+=( $(awk "BEGIN { print int ( ${PARTSIZES[${LCV}]} * ${FACTOR} + 0.5 ) }") )
|
||||||
|
done
|
||||||
|
|
||||||
|
OVERFLOW=$(( ${PRINTCOLS} + ${LCV} + 1 - ${COLS} ))
|
||||||
|
|
||||||
|
printf "%s" "┌"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
[ ${LCV} = $(( ${#PARTITIONS[@]} - 1 )) ] && (( PCOLS[${LCV}]-=${OVERFLOW} ))
|
||||||
|
printf '─%.0s' $(seq 1 ${PCOLS[${LCV}]})
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "┬"
|
||||||
|
done
|
||||||
|
printf "%s\n" "┐"
|
||||||
|
|
||||||
|
printf "%s" "│"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
OUTPUT=${PARTITIONS[${LCV}]##*/}
|
||||||
|
PADL=( $(( ( ${PCOLS[${LCV}]} - ${#OUTPUT} ) / 2 )) )
|
||||||
|
PADR=( $(( ${PCOLS[${LCV}]} - ${#OUTPUT} - ${PADL} )) )
|
||||||
|
printf '%*s%s%*s' ${PADL} "" ${OUTPUT} ${PADR} ""
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "│"
|
||||||
|
done
|
||||||
|
printf "%s\n" "│"
|
||||||
|
|
||||||
|
#echo -n "│"
|
||||||
|
#for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
# OUTPUT=${PARTSECTS[${LCV}]}s
|
||||||
|
# WIDTH=$(awk "BEGIN { print int ( ${PARTSIZES[${LCV}]} * ${FACTOR} + 0.5 ) }")
|
||||||
|
# PADL=$(( ( ${WIDTH} - ${#OUTPUT} ) / 2 ))
|
||||||
|
# PADR=$(( ${WIDTH} - ${#OUTPUT} - ${PADL} ))
|
||||||
|
# echo -n "$(printf '%*s%s%*s' ${PADL} "" ${OUTPUT} ${PADR} "")"
|
||||||
|
# [ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "│"
|
||||||
|
#done
|
||||||
|
#echo "│"
|
||||||
|
|
||||||
|
printf "%s" "│"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
OUTPUT=$(sectors_to_size "${PARTSECTS[${LCV}]}")
|
||||||
|
PADL=( $(( ( ${PCOLS[${LCV}]} - ${#OUTPUT} ) / 2 )) )
|
||||||
|
PADR=( $(( ${PCOLS[${LCV}]} - ${#OUTPUT} - ${PADL} )) )
|
||||||
|
printf '%*s%s%*s' ${PADL} "" ${OUTPUT} ${PADR} ""
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "│"
|
||||||
|
done
|
||||||
|
printf "%s\n" "│"
|
||||||
|
|
||||||
|
printf "%s" "│"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
#OUTPUT=$(blkid -o export "${PARTITIONS[${LCV}]}" | grep '^LABEL=' | cut -d= -f2)
|
||||||
|
OUTPUT=$(blkid -o export "${PARTITIONS[${LCV}]}" | grep '^\(TYPE=\)' | cut -d= -f2 | sed 's:linux_raid_member:raid:g')
|
||||||
|
PADL=$(( ( ${PCOLS[${LCV}]} - ${#OUTPUT} ) / 2 ))
|
||||||
|
PADR=$(( ${PCOLS[${LCV}]} - ${#OUTPUT} - ${PADL} ))
|
||||||
|
printf '%*s%s%*s' ${PADL} "" "${OUTPUT}" ${PADR} ""
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "│"
|
||||||
|
done
|
||||||
|
printf "%s\n" "│"
|
||||||
|
|
||||||
|
printf "%s" "│"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
#OUTPUT=$(blkid -o export "${PARTITIONS[${LCV}]}" | grep '^LABEL=' | cut -d= -f2)
|
||||||
|
OUTPUT=$(blkid -o export "${PARTITIONS[${LCV}]}" | grep '^\(LABEL=\)' | cut -d= -f2)
|
||||||
|
PADL=$(( ( ${PCOLS[${LCV}]} - ${#OUTPUT} ) / 2 ))
|
||||||
|
PADR=$(( ${PCOLS[${LCV}]} - ${#OUTPUT} - ${PADL} ))
|
||||||
|
printf '%*s%s%*s' ${PADL} "" "${OUTPUT}" ${PADR} ""
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "│"
|
||||||
|
done
|
||||||
|
printf "%s\n" "│"
|
||||||
|
|
||||||
|
echo -n "└"
|
||||||
|
for (( LCV = 0; LCV < ${#PARTITIONS[@]}; LCV++ )); do
|
||||||
|
printf '─%.0s' $(seq 1 ${PCOLS[${LCV}]})
|
||||||
|
[ ${LCV} -lt $(( ${#PARTITIONS[@]} - 1 )) ] && echo -n "┴"
|
||||||
|
done
|
||||||
|
echo "┘"
|
||||||
|
|
||||||
|
done
|
Loading…
Reference in new issue