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
|
||||
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 <uid> <size>"
|
||||
echo "Edit the quota of the AlternC account having uid <uid> the the available space to <size>"
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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 <uid>"
|
||||
echo "Get the quota of the AlternC account having uid <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
|
||||
|
||||
|
|
Loading…
Reference in New Issue