Skip to content
Snippets Groups Projects
Commit 2c59e267 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci Committed by Josiney de Souza
Browse files

disk.tree: Major update


New features and improvements:

- Added many comments discribing the code;
- Updated df(1) check;
- Added USB identification for the new UCA Classmates*;
- Added USB identification for the ProInfo Projectors prototypes*;
- Considered one USB as a disk if the computer does not have any disks, but
only mounted USB's (mostly usefull for netbooks).

* For finding the USB used to mount the system.

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
Acked-by: default avatarRenan Franca de Miranda <rfm08@c3sl.ufpr.br>
Signed-off-by: default avatarJosiney de Souza <josineys@c3sl.ufpr.br>
parent 8c436ede
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA. # USA.
if ! test -x $(which df); then # Check if df(1) exists before verifying the disks
if ! which df &> /dev/null; then
exit 2 exit 2
fi fi
...@@ -28,47 +29,97 @@ number=0 ...@@ -28,47 +29,97 @@ number=0
disks="" disks=""
raid=false raid=false
distro=$(cut -sd ' ' -f3,4 /etc/issue) distro=$(cut -sd ' ' -f3,4 /etc/issue)
# If this is a Classmate notebook, find the USB used to mount the root and save
# it to storage variable
if test "${distro}" = "Metasys ClassmatePC"; then if test "${distro}" = "Metasys ClassmatePC"; then
label=$(grep "\/ " /etc/fstab | cut -d"=" -f2 | cut -d" " -f1) label=$(grep "\/ " /etc/fstab | cut -d"=" -f2 | cut -d" " -f1)
classmateStorage=$(ls -l --time-style="+%F %R" /dev/disk/by-label | storage=$(ls -l --time-style="+%F %R" /dev/disk/by-label |
grep "$label" | cut -d"/" -f3 | sed 's/[0-9]//g') grep "$label" | cut -d"/" -f3 | sed 's/[0-9]//g')
elif test -f "/etc/cmpc-release"; then
storage=$(ls -l --time-style="+%F %R" /dev/disk/by-label |
grep "Mdv_Root" | cut -d"/" -f3 | sed 's/[0-9]//g')
fi
# If this is a ProInfo Projector, find the USB used to mount the system and
# save it to storage variable
if test -f "/usr/sbin/projetor"; then
storage=$(ls -l --time-style="+%F %R" /dev/disk/by-label | grep "conf" |
cut -d"/" -f3 | sed 's/[0-9]//g')
fi fi
# If the directory "/dev/disk/by-id/" exists, obtain the disks information
if test -d "/dev/disk/by-id/"; then if test -d "/dev/disk/by-id/"; then
# Find every USB connected to the computer
for line in $(ls -l --time-style="+%F %R" /dev/disk/by-id/ | grep "usb" | for line in $(ls -l --time-style="+%F %R" /dev/disk/by-id/ | grep "usb" |
awk '{print $10}' | grep "[a-z]$"; ls -l --time-style="+%F %R"\ awk '{print $10}' | grep "[a-z]$"; ls -l --time-style="+%F %R"\
/dev/cdrom* 2> /dev/null | awk '{print $10}' | grep "[a-z]$"); do /dev/cdrom* 2> /dev/null | awk '{print $10}' | grep "[a-z]$"); do
if test "${distro}" != "Metasys ClassmatePC" -o \ # If it's not the USB used as root by Classmate notebook, nor the USB
"$(basename $line)" != "${classmateStorage}"; then # used by the Projector, then add it to the list to avoid counting it as
# a disk
if test "$(basename $line)" != "${storage}"; then
test -n "${massStorage}" && massStorage="${massStorage}|" test -n "${massStorage}" && massStorage="${massStorage}|"
massStorage="${massStorage}$(basename $line)" massStorage="${massStorage}$(basename $line)"
fi fi
done done
# If massStorage list isn't empty, add "-v" to grep parameters, to exclude
# every USB listed here from verification
test -n "${massStorage}" && ParamGrep="-v" test -n "${massStorage}" && ParamGrep="-v"
# If there is only USB and no hard disk, remove the first USB found from the
# exclusion list and consider it a valid disk (for computers which use USB
# as root disk)
if test -z "$(ls -l --time-style="+%F %R" /dev/disk/by-id/ |
egrep ${ParamGrep} "$massStorage" | cut -d"/" -f3 |
grep "[a-z]$" | sort -u)" -a -z "${storage}"; then
if test -n "$(echo ${massStorage} | grep '|')"; then
massStorage="$(echo ${massStorage} | cut -d'|' -f2-)"
else
massStorage=""
ParamGrep=""
fi
fi
# If "/proc/mdstat" exists, than check for RAID disks
test -f "/proc/mdstat" && raid=true test -f "/proc/mdstat" && raid=true
# Verify every disk in "/dev/disk/by-id/", excluding all USB's, unless it's
# the USB used as root by Classmate notebook
for line in $(ls -l --time-style="+%F %R" /dev/disk/by-id/ | for line in $(ls -l --time-style="+%F %R" /dev/disk/by-id/ |
egrep ${ParamGrep} "$massStorage" | cut -d"/" -f3 | egrep ${ParamGrep} "$massStorage" | cut -d"/" -f3 |
grep "[a-z]$" | sort -u); do grep "[a-z]$" | sort -u); do
# Enumerate the disks and save the model of each one
disks="${disks}<hdd${number}>" disks="${disks}<hdd${number}>"
disks="${disks}<model value=\"$(ls -l --time-style="+%F %R"\ disks="${disks}<model value=\"$(ls -l --time-style="+%F %R"\
/dev/disk/by-id/ | grep "$line$" | awk '{print $8}' | grep "ata" | /dev/disk/by-id/ | grep "$line$" | awk '{print $8}' | grep "ata" |
cut -d"-" -f2)\" type=\"string\"/>" cut -d"-" -f2)\" type=\"string\"/>"
# Multiply the number of blocks by their standard size
diskSize=$(($(cat /sys/block/$line/size)*512)) diskSize=$(($(cat /sys/block/$line/size)*512))
# Size of disk in giga bytes. # Size of disk in giga bytes
disks="${disks}<size value=\"$((${diskSize}/1073741824 disks="${disks}<size value=\"$((${diskSize}/1073741824
))\" type=\"int\"/>" ))\" type=\"int\"/>"
diskUsed=0 diskUsed=0
# Check to RAID. # RAID check
if ${raid} && test -n "$(grep "raid" /proc/mdstat)"; then if ${raid} && test -n "$(grep "raid" /proc/mdstat)"; then
# Check every disk in the RAID
for dev in $(grep "${line}" /proc/mdstat | cut -d" " -f1); do for dev in $(grep "${line}" /proc/mdstat | cut -d" " -f1); do
# Obtain the number of disks in the RAID array
numDisksArray=$(grep -T1 "${dev}" /proc/mdstat | grep "blocks" | numDisksArray=$(grep -T1 "${dev}" /proc/mdstat | grep "blocks" |
cut -d"[" -f2 | cut -d"/" -f1) cut -d"[" -f2 | cut -d"/" -f1)
# Obtain the RAID type
type=$(grep "${dev}" /proc/mdstat | cut -d" " -f4) type=$(grep "${dev}" /proc/mdstat | cut -d" " -f4)
# If the disk is being used, obtain the amount used according to
# the RAID type
used=$(df -kPx swap | grep "$dev" | awk '{print $3}') used=$(df -kPx swap | grep "$dev" | awk '{print $3}')
if test -n "${used}"; then if test -n "${used}"; then
case ${type} in case ${type} in
...@@ -87,12 +138,26 @@ if test -d "/dev/disk/by-id/"; then ...@@ -87,12 +138,26 @@ if test -d "/dev/disk/by-id/"; then
fi fi
done done
# There is no RAID
else else
# If it's a Metasys Classmate notebook, $label will have the USB
# used as the system root
if test "${distro}" = "Metasys ClassmatePC"; then if test "${distro}" = "Metasys ClassmatePC"; then
for used in $(df -kPx swap | grep "${label}" | for used in $(df -kPx swap | grep "${label}" |
awk '{print $3}'); do awk '{print $3}'); do
(( diskUsed=${diskUsed}+${used} )) (( diskUsed=${diskUsed}+${used} ))
done done
# If it's a Mandriva Classmate notebook, there is no label, so it
# makes a grep for the root mount point
elif test -f "/etc/cmpc-release"; then
for used in $(df -kPx swap | grep "/" | head -n 1 |
awk '{print $3}'); do
(( diskUsed=${diskUsed}+${used} ))
done
# Else, $line will have the disk name
else else
for used in $(df -kPx swap | grep "${line}" | for used in $(df -kPx swap | grep "${line}" |
awk '{print $3}'); do awk '{print $3}'); do
...@@ -106,7 +171,13 @@ if test -d "/dev/disk/by-id/"; then ...@@ -106,7 +171,13 @@ if test -d "/dev/disk/by-id/"; then
disks="${disks}</hdd${number}>" disks="${disks}</hdd${number}>"
(( number=${number}+1 )) (( number=${number}+1 ))
done done
# Print the disk quantity and the details of every disk found (except USB's,
# unless it's a Classmate notebook or there is no disk - i.e. the system is
# mounted upon an USB)
printf "<hdd quantity=\"$number\">${disks}</hdd>\n" printf "<hdd quantity=\"$number\">${disks}</hdd>\n"
# There is no disk in the local system
else else
printf "<hdd quantity=\"0\"/>\n" printf "<hdd quantity=\"0\"/>\n"
fi fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment