|
| 1 | +#!/bin/bash |
| 2 | +# info: add system quota |
| 3 | +# opions: NONE |
| 4 | +# |
| 5 | +# The script enables filesystem quota on /home patition |
| 6 | + |
| 7 | + |
| 8 | +#----------------------------------------------------------# |
| 9 | +# Variable&Function # |
| 10 | +#----------------------------------------------------------# |
| 11 | + |
| 12 | +# Includes |
| 13 | +source $VESTA/func/main.sh |
| 14 | +source $VESTA/conf/vesta.conf |
| 15 | + |
| 16 | + |
| 17 | +#----------------------------------------------------------# |
| 18 | +# Verifications # |
| 19 | +#----------------------------------------------------------# |
| 20 | + |
| 21 | +# Checking quota package |
| 22 | +if [ ! -e "/usr/sbin/setquota" ]; then |
| 23 | + if [ -e "/etc/redhat-release" ]; then |
| 24 | + yum -y install quota >/dev/null 2>&1 |
| 25 | + result=$? |
| 26 | + else |
| 27 | + export DEBIAN_FRONTEND=noninteractive |
| 28 | + apt-get -y install quota >/dev/null 2>&1 |
| 29 | + result=$? |
| 30 | + fi |
| 31 | + |
| 32 | + # Checking installation status |
| 33 | + if [ "$result" -ne 0 ]; then |
| 34 | + echo "Error: quota package wasn't successfully installed" |
| 35 | + log_event "$E_UPDATE" "$EVENT" |
| 36 | + exit $E_UPDATE |
| 37 | + fi |
| 38 | +fi |
| 39 | + |
| 40 | + |
| 41 | +#----------------------------------------------------------# |
| 42 | +# Action # |
| 43 | +#----------------------------------------------------------# |
| 44 | + |
| 45 | +# Adding usrquota option on /home partition |
| 46 | +mnt=$(df -P /home |awk '{print $6}' |tail -n1) |
| 47 | +lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ') |
| 48 | +options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}') |
| 49 | +if [ -z "$(echo $options |grep usrquota)" ]; then |
| 50 | + sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab |
| 51 | + mount -o remount $mnt |
| 52 | +fi |
| 53 | + |
| 54 | +# Adding aquota.user file |
| 55 | +if [ ! -e "$mnt/aquota.user" ]; then |
| 56 | + quotacheck -cu $mnt >/dev/null 2>&1 |
| 57 | +fi |
| 58 | + |
| 59 | +# Building fs quota index |
| 60 | +quotacheck -um $mnt |
| 61 | + |
| 62 | +# Adding weekly cron job |
| 63 | +echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck |
| 64 | +chmod a+x /etc/cron.daily/quotacheck |
| 65 | + |
| 66 | +# Enabling fs quota |
| 67 | +if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then |
| 68 | + quotaon $mnt |
| 69 | +fi |
| 70 | + |
| 71 | +# Updating DISK_QUOTA value |
| 72 | +if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then |
| 73 | + echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf |
| 74 | +else |
| 75 | + sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $VESTA/conf/vesta.conf |
| 76 | +fi |
| 77 | + |
| 78 | +# Rebuilding user quota |
| 79 | +for user in $(ls $VESTA/data/users); do |
| 80 | + $BIN/v-update-user-quota $user |
| 81 | +done |
| 82 | + |
| 83 | + |
| 84 | +#----------------------------------------------------------# |
| 85 | +# Vesta # |
| 86 | +#----------------------------------------------------------# |
| 87 | + |
| 88 | +# Logging |
| 89 | +log_event "$OK" "$EVENT" |
| 90 | + |
| 91 | +exit |
0 commit comments