Bugfixing ( for the 32134th time ) quotas getting and setting scripts: tested with local and nfs driven quotas.
This commit is contained in:
parent
7ef8a958cc
commit
f020b9cf9d
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -x
|
||||||
. /etc/alternc/local.sh
|
. /etc/alternc/local.sh
|
||||||
# Set disk quota to an user
|
# Set disk quota to an user
|
||||||
# Won't work over NFS
|
# Won't work over NFS
|
||||||
|
@ -6,7 +7,10 @@
|
||||||
MID=$1
|
MID=$1
|
||||||
SIZE=$2
|
SIZE=$2
|
||||||
AWK=/usr/bin/awk
|
AWK=/usr/bin/awk
|
||||||
|
MOUNT=/bin/mount
|
||||||
|
SED=/bin/sed
|
||||||
QUOTA=/usr/sbin/setquota
|
QUOTA=/usr/sbin/setquota
|
||||||
|
DF=/bin/df
|
||||||
|
|
||||||
#checking if quotas are installed
|
#checking if quotas are installed
|
||||||
command -v $QUOTA >/dev/null && continue || { echo "Quotas uninstalled"; exit 1; }
|
command -v $QUOTA >/dev/null && continue || { echo "Quotas uninstalled"; exit 1; }
|
||||||
|
@ -17,5 +21,19 @@ if [ $# -ne 2 ] || [[ ! "$MID" =~ ^[0-9]+$ ]] || [[ ! "$SIZE" =~ ^[0-9]+$ ]]; th
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_PART=`df "${ALTERNC_LOC}/html" 2>/dev/null | $AWK 'NR==2 { print $1; }'`
|
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`
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
. /etc/alternc/local.sh
|
set -x
|
||||||
AWK=/usr/bin/awk
|
AWK=/usr/bin/awk
|
||||||
DF=/bin/df
|
DF=/bin/df
|
||||||
SED=/bin/sed
|
SED=/bin/sed
|
||||||
|
@ -10,6 +10,7 @@ WC=/usr/bin/wc
|
||||||
BLKID=/sbin/blkid
|
BLKID=/sbin/blkid
|
||||||
MID=$1
|
MID=$1
|
||||||
|
|
||||||
|
|
||||||
if [ "x$MID" == "x" ] ; then
|
if [ "x$MID" == "x" ] ; then
|
||||||
echo "Usage: quota_get <uid>"
|
echo "Usage: quota_get <uid>"
|
||||||
echo "Get the quota of the AlternC account having uid <uid>"
|
echo "Get the quota of the AlternC account having uid <uid>"
|
||||||
|
@ -39,24 +40,21 @@ if [ -z "$QUOTA_PART" ]; then
|
||||||
UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/')
|
UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\(UUID="\)\(.*\)\(\"$\)/\2/')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#We check that quotas are activated on the right partition
|
quot=$(sudo quota -wvg "$MID" | grep "$QUOTA_PART" | $AWK 'NR==1 {print $1;}' )
|
||||||
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
|
|
||||||
|
|
||||||
# Now we get the quota
|
# 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
|
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 the quota aren't activated, I return something anyway
|
||||||
if [ "$UUID" != "$part" ]; then
|
if [ -z "$val" ] ; then
|
||||||
echo -e "0\n0"
|
echo -e "0\n0"
|
||||||
|
else
|
||||||
|
echo -e "0\n0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo -e "$val"
|
echo -e "$val"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue