AlternC/src/quota_edit

41 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/bin/bash
. /etc/alternc/local.sh
# Set disk quota to an user
# Won't work over NFS
MID=$1
SIZE=$2
AWK=/usr/bin/awk
MOUNT=/bin/mount
SED=/bin/sed
QUOTA=/usr/sbin/setquota
DF=/bin/df
source /etc/alternc/local.sh
#checking if quotas are installed
2013-02-07 17:39:05 +00:00
command -v $QUOTA >/dev/null || { 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
fi
2013-02-18 13:54:00 +00:00
DATA_PART=`$DF "${ALTERNC_HTML}" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
# quota will give over NFS will print the partition using the full NFS name
2013-02-18 14:43:55 +00:00
# (e.g. 10.0.0.1:/var/www/alternc) so we need to lookup first with mount
# to convert DATA_PART if needed.
2013-02-18 13:54:00 +00:00
QUOTA_PART=`$MOUNT | $SED -n -e "s,\([^ ]*\) on ${ALTERNC_HTML} type nfs.*,\1,p"`
echo $QUOTA_PART
if [ -z "$QUOTA_PART" ]; then
2013-02-18 14:43:55 +00:00
`sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 $DATA_PART 2>/dev/null || echo "Group quota are not enabled on $ALTERNC_HTML." >&2`
else
`sudo $QUOTA -r -g $MID $SIZE $SIZE 0 0 "$ALTERNC_HTML" 2>/dev/null || echo "Group quota are not enabled on $ALTERNC_HTML." >&2`
fi