Skip to content

Commit

Permalink
Add server disk space check for mounted share when capturing an image…
Browse files Browse the repository at this point in the history
…, thanks to rluzuriaga

Resolves #60
  • Loading branch information
rluzuriaga authored Feb 23, 2023
1 parent 5fdea7d commit 8b29992
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
23 changes: 23 additions & 0 deletions Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.checkmountdrivesize
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
dots "Checking Server Disk Space"
getServerDiskSpaceUsage=$(df -h | grep "/images" | sed -n '/dev/{s/ */ /gp}')
echo "Done"

dots "Server Disk Size Total"
serverDiskSizeTotal=$(echo "$getServerDiskSpaceUsage" | cut -d ' ' -f2)
echo "$serverDiskSizeTotal"

dots "Server Disk Size Used"
serverDiskSizeUsed=$(echo "$getServerDiskSpaceUsage" | cut -d ' ' -f3)
echo "$serverDiskSizeUsed"

dots "Server Disk Size Used Percentage"
serverDiskSizeUsedPercent=$(echo "$getServerDiskSpaceUsage" | cut -d ' ' -f5)
echo "$serverDiskSizeUsedPercent"

dots "Server Disk Size Available"
serverDiskSizeAvailable=$(echo "$getServerDiskSpaceUsage" | cut -d ' ' -f4)
[[ $serverDiskSizeAvailable == "0" ]] && serverDiskSizeAvailable="0M"
echo "$serverDiskSizeAvailable"

debugPause
1 change: 1 addition & 0 deletions Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.upload
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
. /bin/fog.checkin
. /bin/fog.mount
. /bin/fog.checkmount
. /bin/fog.checkmountdrivesize
. /bin/fog.checkimgvar
imagePath="/images/$macWinSafe"
parts=""
Expand Down
16 changes: 13 additions & 3 deletions Buildroot/board/FOG/FOS/rootfs_overlay/usr/share/fog/lib/funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ getPartBlockSize() {
[[ -z $varVar ]] && handleError "No variable to set passed (${FUNCNAME[0]})\n Args Passed: $*"
printf -v "$varVar" $(blockdev --getpbsz $part)
}
# Retrieve available space from NFS share
# Should only be used when the share is mounted to `/images`
getServerDiskSpaceSvailable() {
local space=$(df -h | grep "/images" | sed -n '/dev/{s/ */ /gp}' | cut -d ' ' -f4)
[[ $space == "0" ]] && local space="0M"
echo $space
}
# Prepares location info for uploads
#
# $1 is the image path
Expand All @@ -437,7 +444,8 @@ prepareUploadLocation() {
*)
echo "Failed"
debugPause
handleError "Failed to create image capture path (${FUNCNAME[0]})\n Args Passed: $*"
local spaceAvailable=$(getServerDiskSpaceSvailable)
handleError "Failed to create image capture path (${FUNCNAME[0]})\nServer Disk Space Available: $spaceAvailable\n Args Passed: $*"
;;
esac
fi
Expand Down Expand Up @@ -2231,7 +2239,8 @@ savePartition() {
debugPause
;;
*)
handleError "Failed to complete capture (${FUNCNAME[0]})\n Args Passed: $*\n CMD: partclone.$fstype -n \"Storage Location $storage, Image name $img\" -s -O $fifoname -Nf 1\n Exit code: $exitcode\n Server Disk Space Available: $(df -h /images | awk '{print $4}')"
local spaceAvailable=$(getServerDiskSpaceSvailable)
handleError "Failed to complete capture (${FUNCNAME[0]})\n Args Passed: $*\n CMD: partclone.$fstype -n \"Storage Location $storage, Image name $img\" -s -O $fifoname -Nf 1\n Exit code: $exitcode\n Server Disk Space Available: $spaceAvailable"
;;
esac
;;
Expand All @@ -2257,7 +2266,8 @@ savePartition() {
debugPause
;;
*)
handleError "Failed to complete capture (${FUNCNAME[0]})\n Args Passed: $*\n CMD: partclone.$fstype -n \"Storage Location $storage, Image name $img\" -cs -O $fifoname -Nf 1 -a0\n Exit code: $exitcode\n Server Disk Space Available: $(df -h /images | awk '{print $4}')"
local spaceAvailable=$(getServerDiskSpaceSvailable)
handleError "Failed to complete capture (${FUNCNAME[0]})\n Args Passed: $*\n CMD: partclone.$fstype -n \"Storage Location $storage, Image name $img\" -cs -O $fifoname -Nf 1 -a0\n Exit code: $exitcode\n Server Disk Space Available: $spaceAvailable"
;;
esac
;;
Expand Down

0 comments on commit 8b29992

Please sign in to comment.