AlternC/src/quota_get

64 lines
1.9 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
. /etc/alternc/local.sh
AWK=/usr/bin/awk
DF=/bin/df
SED=/bin/sed
MOUNT=/bin/mount
QUOTA=/usr/bin/quota
GREP=/bin/grep
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>"
exit 1
fi
#checking if quotas are installed
command -v $QUOTA >/dev/null || { echo "Quotas uninstalled"; exit 0; }
# The second line is the one interesting
# We look precisely on the HTML directory. Why ? because it's surely
# the bigger one, and if someone separate it we need to look this one
# particulary. It should be interesting to cumulate quota of all mounted directory.
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 ${DATA_PART} type nfs.*,\1,p"`
if [ -z "$QUOTA_PART" ]; then
QUOTA_PART="$DATA_PART"
#if the partition is an LVM one we need to adress the partition by its UUID
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
# Now we get the quota
val=$(sudo quota -A -wg "$MID" | awk 'NR==3 { print $2 "\n" $3; }')
if [ -z "$val" ] ; then
# If the quota aren't activated, I return something anyway
if [ "$UUID" != "$part" ]; then
echo -e "0\n0"
fi
else
echo -e "$val"
fi