Repository navigation
Expand file tree
/
Copy pathcommon.sh
More file actions
73 lines (60 loc) · 1.79 KB
/
Copy pathcommon.sh
File metadata and controls
73 lines (60 loc) · 1.79 KB
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
start_port=255
bs=16k
parallel_max=12
function get_min_fs_size_in_kb()
{
local dumpfs=$(dumpe2fs -h $1 2>/dev/null | \
awk -F: '{\
if ($1 == "Block size") bs=$NF; \
if ($1 == "Block count") count=$NF; \
if ($1 == "Free blocks") free=$NF; \
} END {printf "%.f %.f", bs+0, count-free}')
local fs_bs_k=$(echo $dumpfs | awk '{print $1/1024}')
local fs_used=$(echo $dumpfs | awk '{print $2}')
echo $(( fs_used * fs_bs_k ))
}
function get_max_fs_size_in_kb()
{
local bytes=$(fdisk -l $1 2>/dev/null | \
grep '^Disk '$1 | \
awk '{print $(NF-1)}')
echo $(( bytes / 1024 ))
}
function get_fs_size_in_kb()
{
local dumpfs=$(dumpe2fs -h $1 2>/dev/null | \
awk -F: '{\
if ($1 == "Block size") bs=$NF; \
if ($1 == "Block count") count=$NF; \
} END {printf "%.f %.f", bs, count}')
local fs_bs_k=$(echo $dumpfs | awk '{print $1/1024}')
local fs_count=$(echo $dumpfs | awk '{print $2}')
echo $(( fs_count * fs_bs_k ))
}
# $1 - index
function get_uuid()
{
local type=$1
local i=$2
# TODO: or accept mount points instead of block devices
fstab_line=$(grep $type /etc/fstab | \
grep -v ^# | \
egrep -v "[ ]($(df | tail -n+2 | awk '{printf "%s|", $NF}' | sed 's/|$//'))[ ]" | \
tail -n+$i | \
head -n1)
echo "$fstab_line" | awk -F'[= \t]' '{print $2}'
}
# TODO: resolve UUID's
function mounted()
{
grep -q "^$1 " /proc/mounts
}
# mounted read-only/ro
function read_only()
{
egrep -q "^$1 .*[, ]ro[, ]" /proc/mounts
}
function get_fstype()
{
blkid $@ | cut -d'"' -f4
}