Skip to content

Commit 25851ad

Browse files
author
Aleksei Shpakovskii
committed
fu! wordy comment
1 parent 7c515c8 commit 25851ad

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

packaging/common/cfengine-hub/preinstall.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,33 @@ if is_upgrade && egrep '^3\.([6-9]|1[012])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/
2626
mkdir -p "$BACKUP_DIR"
2727
# Try to check if free space on $BACKUP_DIR drive is not less than $PREFIX/state/pg/data contains
2828
if command -v df >/dev/null && command -v du >/dev/null && command -v awk >/dev/null; then
29-
# we have enough commands to test it
29+
# We have enough commands to test it.
30+
# Explanation of arguments:
31+
# `df`
32+
# `-P` - use POSIX output format (free space in 4th column),
33+
# `-BM` - print output in Megabytes
34+
# `awk`
35+
# `FNR==2` - take record (line) number two (first line in `df` output is table header)
36+
# `gsub(...)` - remove non-numbers from 4th column
37+
# `print $4` - well, print 4th column
38+
# `du`
39+
# `-s` - print only summary - i.e. only one line with total size of all
40+
# files in direcrory passed as argument - unlike in normal case when it
41+
# prints disk usage by each nested directory, recursively
42+
# `-BM` - print output in Megabytes
43+
#
44+
# Example of `df -PBM .` output on my machine:
45+
# ```
46+
# Filesystem 1048576-blocks Used Available Capacity Mounted on
47+
# /dev/sda1 246599M 210974M 24564M 90% /
48+
# ```
49+
# and awk would extract "24564" number from it
50+
# Example of `du -sBM .` output on my machine:
51+
# ```
52+
# 172831M .
53+
# ```
54+
# and awk would extract "172831" number from it
55+
#
3056
megabytes_free="$(df -PBM $BACKUP_DIR | awk 'FNR==2{gsub(/[^0-9]/,"",$4);print $4}')"
3157
megabytes_need="$(du -sBM $PREFIX/state/pg/data | awk '{gsub(/[^0-9]/,"",$1);print $1}')"
3258
if [ "$megabytes_free" -le "$megabytes_need" ]; then
@@ -120,7 +146,7 @@ if is_upgrade && egrep '^3\.([6-9]|1[01])\.' "$PREFIX/UPGRADED_FROM.txt" >/dev/n
120146
else
121147
# Copy failed, so remove partially-copied data and abort
122148
rm -rf "$BACKUP_DIR/data"
123-
cf_console echo "Creating of backup failed"
149+
cf_console echo "Backup creation failed"
124150
cf_console echo "Please fix it before upgrading or disable upgrade by removing/renaming $PREFIX/state/pg/data prior to upgrade."
125151
exit 1
126152
fi

0 commit comments

Comments
 (0)