-
Notifications
You must be signed in to change notification settings - Fork 2
/
grab_disks
executable file
·96 lines (88 loc) · 2.63 KB
/
grab_disks
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
#
# Copyright (C) 2022 David Valin [email protected]
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
disks_passed=$1
disks=""
numb_disks=0
seper=""
build_disks_list()
{
disk_list=`echo $1 | sed 's/,/ /g'`
for i in $disk_list; do
let "numb_disks=$numb_disks + 1"
if [[ $i == "/dev/"* ]]; then
disks=${disks}${seper}${i}
else
disks=${disks}${seper}/dev/${i}
fi
seper=" "
done
}
grab_disks()
{
if test -f "hw_config.yml"; then
grep storage hw_config.yml | cut -d: -f 2 | sed "s/,/ /g" > disks
else
ALLSTG=$(mktemp /tmp/allstgdsk.XXXXX)
USEDDSK=$(mktemp /tmp/useddsk.XXXXX)
ALLDSK=$(mktemp /tmp/alldsk.XXXXX)
MNTDDSK=$(mktemp /tmp/mntddsk.XXXXX)
lsblk -l > ${ALLSTG}
rootdisk=$(grep -e "part /$" -e boot$ ${ALLSTG} | awk '{print $1}')
if [[ $rootdisk =~ nvme* ]]; then
grep part ${ALLSTG}| grep -e / -e swap | awk '{print $1}' | sed s/p[[:digit:]]*$// | sort | uniq > $USEDDSK
else
grep -e disk -e part ${ALLSTG}| grep -e / -e swap | awk '{print $1}' | sed s/[[:digit:]]*$// | sort | uniq > $USEDDSK
fi
#
# Now the mounted disks
#
for i in `df | grep /dev | cut -d' ' -f1 | grep /`
do
echo ${i##*/} >> $USEDDSK
done
grep disk ${ALLSTG} | awk '{print $1}' | sort | uniq > ${ALLDSK}
disks_temp=`echo $(grep -F -x -v -f ${USEDDSK} ${ALLDSK})`
echo "$disks_temp" | awk '{ for (i=NF; i > 1; i--) printf("%s ",$i); print $1; }' > disks
fi
build_disks_list "`cat disks`"
}
if [[ $disks_passed == *"none"* ]]; then
if [[ $sys_type == "local" ]]; then
echo Unable to continue. non cloud systems require a disk to be designated.
exit 1
fi
fi
if [[ $disks_passed == "grab_disks" ]]; then
grab_disks
else
#
# Use the list of disks passed in.
#
build_disks_list $disks_passed
fi
#
# If no disks have been passed in, bail. Note we do not check
# to make sure the disk exist.
#
if [ $numb_disks -eq 0 ]; then
echo "Need to have disks to perform the requested test. No disks have been provided/found."
exit 1
fi
echo $disks:$numb_disks
exit 0