summarylogtreecommitdiffstats
path: root/pendrive-detect
diff options
context:
space:
mode:
authorsimona2018-11-25 17:05:22 +0100
committersimona2018-11-25 17:05:22 +0100
commitb583ae52f4aa6be344ff073d0e19675b24be69d5 (patch)
treeb69eff7dd5c88da9d703f836eba7e91201efc14c /pendrive-detect
parent45a87ebf459dc1839988e49b60a46f91a5919fd5 (diff)
downloadaur-b583ae52f4aa6be344ff073d0e19675b24be69d5.tar.gz
same scripts but different packaging
Diffstat (limited to 'pendrive-detect')
-rwxr-xr-xpendrive-detect47
1 files changed, 47 insertions, 0 deletions
diff --git a/pendrive-detect b/pendrive-detect
new file mode 100755
index 000000000000..c5b0c132b328
--- /dev/null
+++ b/pendrive-detect
@@ -0,0 +1,47 @@
+#!/bin/bash
+# Simona Pisano - 2018-11-18
+# simona-scripts
+# Libertamente utilizzabile sotto GPL v3
+
+ #sget-pendrive() {
+ n_found=0
+ #TO-DO
+ #for short_dev in `lsblk -ndlo NAME` ; do
+ # drive="/dev/$short_dev"
+ # #if [[ -b $drive ]] ; then
+ # #short_dev="${drive##*/}" # estract substring: take only final part after last '/' char
+ for drive in /dev/sd?* /dev/nvme* ; do
+ if [[ -b $drive ]] ; then
+
+ letter=${drive:7:1}
+ short_dev="${drive##*/}" # estract substring: take only final part after last '/' char
+
+ #base search
+ udev=`udevadm info -q path -n $drive`
+ udev=`udevadm info -a -p $udev `
+
+ search=`echo KERNEL==\"$short_dev\"`
+ udev_info=`echo "$udev" | grep $search | tr -d ' ' `
+ [[ $udev_info != "KERNEL==\"$short_dev\"" ]] && continue #not correct device
+
+ udev_info=`echo "$udev" | grep 'SUBSYSTEM=="block"' | tr -d ' ' `
+ [[ $udev_info != "SUBSYSTEM==\"block\"" ]] && continue #not correct device
+
+ udev_info=`echo "$udev" | grep 'ATTR{events}=="media_change"' | tr -d ' ' `
+ [[ $udev_info != "ATTR{events}==\"media_change\"" ]] && continue #not correct device
+
+ #check > 0 per evitare device pur presenti ma senza memoria inserita
+ udev_info=`echo "$udev" | grep -E 'ATTR{size}=="[0-9]{1,}"' | tr -d ' ' `
+ [[ $udev_info != *"ATTR{size}=="* ]] && continue #not correct device
+ value=` echo "$udev_info" | cut -d "\"" -f2 | cut -d "\"" -f1 `
+ [[ $value -lt 1 ]] && continue #not correct device
+
+ echo -e "Pendrive \e[1;39;41m$drive\e[0m (size $(($value *512/1000/1000/1000 ))GBi) detected."
+ #break #uncomment to stop search after the first
+
+ n_found=$(( $n_found + 1 ))
+ fi
+ done
+ [[ $n_found -lt 1 ]] && echo "No pendrive found" || echo "$n_found pendrives total found."
+ #}
+