Merge pull request #517 from ionescu-bogdan/patch-1

Sys quota - Patch 1
This commit is contained in:
Serghey Rodin 2015-12-11 20:50:54 +02:00
commit 070a62b05d
2 changed files with 49 additions and 37 deletions

View file

@ -1,12 +1,12 @@
#!/bin/bash
# info: add system quota
# opions: NONE
# options: NONE
#
# The script enables filesystem quota on /home patition
#----------------------------------------------------------#
# Variable&Function #
# Variable & Function #
#----------------------------------------------------------#
# Includes
@ -19,7 +19,8 @@ source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Checking quota package
if [ ! -e "/usr/sbin/setquota" ]; then
quota=$(which --skip-alias --skip-functions quota 2>/dev/null)
if [ $? -ne 0 ]; then
if [ -e "/etc/redhat-release" ]; then
yum -y install quota >/dev/null 2>&1
check_result $? "quota package installation failed" $E_UPDATE
@ -35,34 +36,40 @@ fi
# Action #
#----------------------------------------------------------#
# Adding usrquota option on /home partition
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
if [ -z "$(echo $options |grep usrquota)" ]; then
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab
# Adding group and user quota on /home partition
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
mount -o remount $mnt
fi
# Adding aquota.user file
if [ ! -e "$mnt/aquota.user" ]; then
quotacheck -cu $mnt >/dev/null 2>&1
# Adding v2 group and user quota index
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
quotaoff $mnt
quotacheck -cug $mnt >/dev/null 2>&1
quotacheck -aug >/dev/null 2>&1
fi
# Building fs quota index
quotacheck -um $mnt
# Adding quotacheck on reboot
touch /forcequotacheck
# Adding weekly cron job
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck
# Adding cron job
echo '#!/bin/bash' > /etc/cron.daily/quotacheck
echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck
chmod a+x /etc/cron.daily/quotacheck
# Enabling fs quota
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
# Enabling group and user quota
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
quotaon $mnt
check_result $? "quota can't be enabled in $mtn" $E_DISK
check_result $? "quota can't be enabled in $mnt" $E_DISK
fi
# Updating DISK_QUOTA value
# Updating vesta.conf value
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
else

View file

@ -1,12 +1,12 @@
#!/bin/bash
# info: delete system quota
# opions: NONE
# options: NONE
#
# The script disables filesystem quota on /home patition
#----------------------------------------------------------#
# Variable&Function #
# Variable & Function #
#----------------------------------------------------------#
# Includes
@ -23,29 +23,34 @@ source $VESTA/conf/vesta.conf
# Action #
#----------------------------------------------------------#
# Deleting usrquota on /home partition
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
if [ ! -z "$(echo $options |grep usrquota)" ]; then
sed -i "$lnr s/,usrquota//" /etc/fstab
# Deleting group and user quota on /home partition
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt='
if [ ! -z "$(echo $opt | grep $fnd)" ]; then
rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',')
sed -i "$lnr s/$opt/$rep/" /etc/fstab
mount -o remount $mnt
fi
# Disabling fs quota
if [ -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
quotaoff $mnt
# Disabling group and user quota
quotaoff=$(which --skip-alias --skip-functions quotaoff 2>/dev/null)
if [ $? -eq 0 ]; then
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is on')" ]; then
$quotaoff $mnt
fi
fi
# Deleting quota index
if [ -e "$mnt/aquota.user" ]; then
rm $mnt/aquota.user
fi
# Deleting v1 + v2 group and user quota index
for idx in $(echo 'quota.user quota.group aquota.user aquota.group'); do
[ -e "$mnt/$idx" ] && rm -f $mnt/$idx
done
# Deleting weekly cron job
# Deleting cron job
rm -f /etc/cron.daily/quotacheck
# Updating DISK_QUOTA value
# Updating vesta.conf value
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
echo "DISK_QUOTA='no'" >> $VESTA/conf/vesta.conf
else