Alternc  latest
Alternc logiel libre pour l'hébergement
quota_get
Go to the documentation of this file.
1 #!/bin/bash
2 AWK=/usr/bin/awk
3 DF=/bin/df
4 SED=/bin/sed
5 MOUNT=/bin/mount
6 QUOTA=/usr/bin/quota
7 GREP=/bin/grep
8 WC=/usr/bin/wc
9 BLKID=/sbin/blkid
10 MID=$1
11 
12 source /etc/alternc/local.sh
13 
14 if [ "x$MID" == "x" ] ; then
15  echo "Usage: quota_get <uid>"
16  echo "Get the quota of the AlternC account having uid <uid>"
17  exit 1
18 fi
19 
20 QUOTA_OPTIONS="-l"
21 if [ "$NFS_QUOTA" = "yes" -o "$NFS_QUOTA" = "YES" -o "$NFS_QUOTA" = "Yes" ]
22 then
23  QUOTA_OPTIONS=""
24 fi
25 
26 #checking if quotas are installed
27 command -v $QUOTA >/dev/null || { echo "Quotas uninstalled"; exit 0; }
28 
29 
30 # The second line is the one interesting
31 # We look precisely on the HTML directory. Why ? because it's surely
32 # the bigger one, and if someone separate it we need to look this one
33 # particulary. It should be interesting to cumulate quota of all mounted directory.
34 
35 DATA_PART=`$DF "${ALTERNC_HTML}" 2>/dev/null | $AWK 'NR==2 { print $1 }'`
36 
37 # quota will give over NFS will print the partition using the full NFS name
38 # (e.g. 10.0.0.1:/var/www/alternc) so we need to lookup first with mount
39 # to convert DATA_PART if needed.
40 
41 QUOTA_PART=`$MOUNT | $SED -n -e "s,\‍([^ ]*\‍) on ${DATA_PART} type nfs.*,\1,p"`
42 
43 if [ -z "$QUOTA_PART" ]; then
44  QUOTA_PART="$DATA_PART"
45  #if the partition is an LVM one we need to adress the partition by its UUID
46  UUID=$( $BLKID | grep "$QUOTA_PART" | cut -f2 -s -d" " | sed 's/\‍(UUID="\‍)\‍(.*\‍)\‍(\"$\‍)/\2/')
47 fi
48 
49 quot=$(sudo quota $QUOTA_OPTIONS -wvg "$MID" | grep "$QUOTA_PART" | $AWK 'NR==1 {print $1;}' )
50 
51 # Now we get the quota
52 #first by testing if the partition is referenced by UUID
53 val=$(sudo quota $QUOTA_OPTIONS -vwg "$MID" |grep "$UUID" | awk 'END { print $2 "\n" $3; }')
54 if [ -z "$val" ] ; then
55  val=$(sudo quota $QUOTA_OPTIONS -A -wg "$MID" |grep "$QUOTA_PART" | awk 'END { print $2 "\n" $3; }')
56 
57  # If the quota aren't activated, I return something anyway
58  if [ -z "$val" ] ; then
59  echo -e "0\n0"
60  else
61  echo -e "$val"
62  fi
63 
64 else
65  echo -e "$val"
66 fi
67