From f020b9cf9d4d49fba4c1ed4a7cf94aa68c8b822f Mon Sep 17 00:00:00 2001 From: Steven Mondji-Lerider Date: Fri, 25 Jan 2013 16:39:39 +0000 Subject: [PATCH] Bugfixing ( for the 32134th time ) quotas getting and setting scripts: tested with local and nfs driven quotas. --- src/quota_edit | 24 +++++++++++++++++++++--- src/quota_get | 28 +++++++++++++--------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/quota_edit b/src/quota_edit index db40bc68..9d1ccd75 100755 --- a/src/quota_edit +++ b/src/quota_edit @@ -1,4 +1,5 @@ #!/bin/bash +set -x . /etc/alternc/local.sh # Set disk quota to an user # Won't work over NFS @@ -6,7 +7,10 @@ MID=$1 SIZE=$2 AWK=/usr/bin/awk +MOUNT=/bin/mount +SED=/bin/sed QUOTA=/usr/sbin/setquota +DF=/bin/df #checking if quotas are installed command -v $QUOTA >/dev/null && continue || { echo "Quotas uninstalled"; exit 1; } @@ -14,8 +18,22 @@ command -v $QUOTA >/dev/null && continue || { echo "Quotas uninstalled"; exit 1; if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; then echo "Usage: quota_edit " echo "Edit the quota of the AlternC account having uid the the available space to " - exit 1 + exit 1 fi -DATA_PART=`df "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1; }'` -`sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2` +DATA_PART=`$DF "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1 }'` + +# quota will give over NFS will print the partition using the full NFS name +# (e.g. 10.0.0.1:/var/alternc) so we need to lookup first with mount +# to convert DATA_PART if needed. + +QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${ALTERNC_LOC}/html type nfs.*,\1,p"` +echo $QUOTA_PART + +if [ -z "$QUOTA_PART" ]; then + `sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2` +else + `sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 "$ALTERNC_LOC/html" 2>/dev/null || echo "Group quota are not enabled on /var/alternc." >&2` +fi + + diff --git a/src/quota_get b/src/quota_get index e45901bf..856ac0c5 100755 --- a/src/quota_get +++ b/src/quota_get @@ -1,5 +1,5 @@ #!/bin/bash -. /etc/alternc/local.sh +set -x AWK=/usr/bin/awk DF=/bin/df SED=/bin/sed @@ -10,6 +10,7 @@ WC=/usr/bin/wc BLKID=/sbin/blkid MID=$1 + if [ "x$MID" == "x" ] ; then echo "Usage: quota_get " echo "Get the quota of the AlternC account having uid " @@ -39,25 +40,22 @@ if [ -z "$QUOTA_PART" ]; then UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/') fi -#We check that quotas are activated on the right partition -quot=$(sudo quota -A -wg "$MID" | awk 'NR==3 { print $1; }') -part=$( $BLKID | grep "$quot" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/') - -# If the quotas are activated on another part we return 0 meaning that the quotas are infinite -if [ "$UUID" != "$part" ]; then - echo -e "0\n0" - exit 0 -fi +quot=$(sudo quota -wvg "$MID" | grep "$QUOTA_PART" | $AWK 'NR==1 {print $1;}' ) # Now we get the quota -val=$(sudo quota -A -wg "$MID" | awk 'NR==3 { print $2 "\n" $3; }') - +#first by testing if the partition is referenced by UUID +val=$(sudo quota -vwg "$MID" |grep "$UUID" | awk 'END { print $2 "\n" $3; }') if [ -z "$val" ] ; then + val=$(sudo quota -A -wg "$MID" |grep "$QUOTA_PART" | awk '{ print $2 "\n" $3; }') + # If the quota aren't activated, I return something anyway - if [ "$UUID" != "$part" ]; then - echo -e "0\n0" + if [ -z "$val" ] ; then + echo -e "0\n0" + else + echo -e "0\n0" fi -else + +else echo -e "$val" fi