Skip to content

Commit 070a62b

Browse files
committed
Merge pull request hestiacp#517 from ionescu-bogdan/patch-1
Sys quota - Patch 1
2 parents 49a18fb + 04f497d commit 070a62b

File tree

2 files changed

+49
-37
lines changed

2 files changed

+49
-37
lines changed

bin/v-add-sys-quota

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22
# info: add system quota
3-
# opions: NONE
3+
# options: NONE
44
#
55
# The script enables filesystem quota on /home patition
66

77

88
#----------------------------------------------------------#
9-
# Variable&Function #
9+
# Variable & Function #
1010
#----------------------------------------------------------#
1111

1212
# Includes
@@ -19,7 +19,8 @@ source $VESTA/conf/vesta.conf
1919
#----------------------------------------------------------#
2020

2121
# Checking quota package
22-
if [ ! -e "/usr/sbin/setquota" ]; then
22+
quota=$(which --skip-alias --skip-functions quota 2>/dev/null)
23+
if [ $? -ne 0 ]; then
2324
if [ -e "/etc/redhat-release" ]; then
2425
yum -y install quota >/dev/null 2>&1
2526
check_result $? "quota package installation failed" $E_UPDATE
@@ -35,34 +36,40 @@ fi
3536
# Action #
3637
#----------------------------------------------------------#
3738

38-
# Adding usrquota option on /home partition
39-
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
40-
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
41-
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
42-
if [ -z "$(echo $options |grep usrquota)" ]; then
43-
sed -i "$lnr s/$options/$options,usrquota/" /etc/fstab
39+
# Adding group and user quota on /home partition
40+
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
41+
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
42+
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
43+
fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
44+
if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
45+
old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
46+
new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
47+
sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
4448
mount -o remount $mnt
4549
fi
4650

47-
# Adding aquota.user file
48-
if [ ! -e "$mnt/aquota.user" ]; then
49-
quotacheck -cu $mnt >/dev/null 2>&1
51+
# Adding v2 group and user quota index
52+
if [ ! -e "$mnt/aquota.user" ] || [ ! -e "$mnt/aquota.group" ]; then
53+
quotaoff $mnt
54+
quotacheck -cug $mnt >/dev/null 2>&1
55+
quotacheck -aug >/dev/null 2>&1
5056
fi
5157

52-
# Building fs quota index
53-
quotacheck -um $mnt
58+
# Adding quotacheck on reboot
59+
touch /forcequotacheck
5460

55-
# Adding weekly cron job
56-
echo "quotacheck -um $mnt" > /etc/cron.daily/quotacheck
61+
# Adding cron job
62+
echo '#!/bin/bash' > /etc/cron.daily/quotacheck
63+
echo 'touch /forcequotacheck' >> /etc/cron.daily/quotacheck
5764
chmod a+x /etc/cron.daily/quotacheck
5865

59-
# Enabling fs quota
60-
if [ ! -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
66+
# Enabling group and user quota
67+
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ]; then
6168
quotaon $mnt
62-
check_result $? "quota can't be enabled in $mtn" $E_DISK
69+
check_result $? "quota can't be enabled in $mnt" $E_DISK
6370
fi
6471

65-
# Updating DISK_QUOTA value
72+
# Updating vesta.conf value
6673
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
6774
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
6875
else

bin/v-delete-sys-quota

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22
# info: delete system quota
3-
# opions: NONE
3+
# options: NONE
44
#
55
# The script disables filesystem quota on /home patition
66

77

88
#----------------------------------------------------------#
9-
# Variable&Function #
9+
# Variable & Function #
1010
#----------------------------------------------------------#
1111

1212
# Includes
@@ -23,29 +23,34 @@ source $VESTA/conf/vesta.conf
2323
# Action #
2424
#----------------------------------------------------------#
2525

26-
# Deleting usrquota on /home partition
27-
mnt=$(df -P /home |awk '{print $6}' |tail -n1)
28-
lnr=$(cat -n /etc/fstab |awk '{print $1,$3}' |grep "$mnt$" |cut -f 1 -d ' ')
29-
options=$(sed -n ${lnr}p /etc/fstab |awk '{print $4}')
30-
if [ ! -z "$(echo $options |grep usrquota)" ]; then
31-
sed -i "$lnr s/,usrquota//" /etc/fstab
26+
# Deleting group and user quota on /home partition
27+
mnt=$(df -P /home | awk '{print $6}' | tail -n1)
28+
lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
29+
opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
30+
fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt='
31+
if [ ! -z "$(echo $opt | grep $fnd)" ]; then
32+
rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',')
33+
sed -i "$lnr s/$opt/$rep/" /etc/fstab
3234
mount -o remount $mnt
3335
fi
3436

35-
# Disabling fs quota
36-
if [ -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then
37-
quotaoff $mnt
37+
# Disabling group and user quota
38+
quotaoff=$(which --skip-alias --skip-functions quotaoff 2>/dev/null)
39+
if [ $? -eq 0 ]; then
40+
if [ ! -z "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is on')" ]; then
41+
$quotaoff $mnt
42+
fi
3843
fi
3944

40-
# Deleting quota index
41-
if [ -e "$mnt/aquota.user" ]; then
42-
rm $mnt/aquota.user
43-
fi
45+
# Deleting v1 + v2 group and user quota index
46+
for idx in $(echo 'quota.user quota.group aquota.user aquota.group'); do
47+
[ -e "$mnt/$idx" ] && rm -f $mnt/$idx
48+
done
4449

45-
# Deleting weekly cron job
50+
# Deleting cron job
4651
rm -f /etc/cron.daily/quotacheck
4752

48-
# Updating DISK_QUOTA value
53+
# Updating vesta.conf value
4954
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
5055
echo "DISK_QUOTA='no'" >> $VESTA/conf/vesta.conf
5156
else

0 commit comments

Comments
 (0)