Skip to content

Commit

Permalink
live os partition names are not dev paths on disk
Browse files Browse the repository at this point in the history
  • Loading branch information
localstepdo authored and Algodev-github committed Apr 28, 2020
1 parent 73a0fb2 commit 2907f02
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions process_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ function print_dev_help
echo See the comments in $CONFPATH for details and more options.
}

function get_partition_info
{
PART_INFO=
if [[ -e $1 ]]; then
PART_INFO=$(df $1 | egrep $1)
else
# most likely linux live os
PART_INFO=$(df | egrep $1)
fi
echo $PART_INFO
}

function find_partition_for_dir
{
PART=$(df "$1" | tail -1 | awk '{print $1;}')
Expand All @@ -56,6 +68,8 @@ function find_dev_for_dir
exit
fi

REALPATH=$PART
if [[ -e $PART ]]; then
REALPATH=$(readlink -f $PART) # moves to /dev/dm-X in case of device mapper
if [[ "$REALPATH" == "" ]]; then
echo The directory where you want me store my test files,
Expand All @@ -67,6 +81,7 @@ function find_dev_for_dir
print_dev_help
exit
fi
fi

BASEPART=$(basename $PART)
REALPART=$(basename $REALPATH)
Expand Down Expand Up @@ -248,12 +263,12 @@ function get_max_affordable_file_size
PART=$(find_partition_for_dir $BASE_DIR)
fi

if [[ "$(df $PART | egrep $PART)" == "" ]]; then # it must be /dev/root
if [[ "$(get_partition_info $PART)" == "" ]]; then # it must be /dev/root
PART=/dev/root
fi

BASE_DIR_SIZE=$(du -s $BASE_DIR | awk '{print $1}')
FREESPACE=$(df $PART | egrep $PART | awk '{print $4}' | head -n 1)
FREESPACE=$(get_partition_info $PART | awk '{print $4}' | head -n 1)
MAXTOTSIZE=$((($FREESPACE + $BASE_DIR_SIZE) / 2))
MAXTOTSIZE_MiB=$(($MAXTOTSIZE / 1024))
MAXSIZE_MiB=$((MAXTOTSIZE_MiB / 15))
Expand Down Expand Up @@ -382,11 +397,11 @@ function prepare_basedir
PART=$(find_partition_for_dir $BASE_DIR)
fi

if [[ "$(df $PART | egrep $PART)" == "" ]]; then # it must be /dev/root
if [[ "$(get_partition_info $PART)" == "" ]]; then # it must be /dev/root
PART=/dev/root
fi

FREESPACE=$(df $PART | egrep $PART | awk '{print $4}' | head -n 1)
FREESPACE=$(get_partition_info $PART | awk '{print $4}' | head -n 1)

BASE_DIR_SIZE=$(du -s $BASE_DIR | awk '{print $1}')

Expand Down

0 comments on commit 2907f02

Please sign in to comment.