forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-sys-quota
More file actions
executable file
·96 lines (76 loc) · 2.63 KB
/
Copy pathv-add-sys-quota
File metadata and controls
executable file
·96 lines (76 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# info: add system quota
# opions: NONE
#
# The script enables filesystem quota on /home patition
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking quota package
if [ ! -e "/usr/sbin/setquota" ]; then
if [ -e "/etc/redhat-release" ]; then
yum -y install quota >/dev/null 2>&1
result=$?
else
export DEBIAN_FRONTEND=noninteractive
apt-get -y install quota >/dev/null 2>&1
result=$?
fi
# Checking installation status
if [ "$result" -ne 0 ]; then
echo "Error: quota package wasn't successfully installed"
log_event "$E_UPDATE" "$EVENT"
exit $E_UPDATE
fi
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
mount -o remount $mnt
fi
# Adding aquota.user file
if [ ! -e "$mnt/aquota.user" ]; then
quotacheck -cu $mnt >/dev/null 2>&1
fi
# Building fs quota index
quotacheck -um $mnt
# Adding weekly cron job
echo "quotacheck -um $mnt" > /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
quotaon $mnt
if [ $? -ne 0 ]; then
echo "Error: quota can't be enabled on $mnt partition"
log_event "$E_DISK" "$EVENT"
exit $E_DISK
fi
fi
# Updating DISK_QUOTA value
if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then
echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
else
sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $VESTA/conf/vesta.conf
fi
# Rebuilding user quota
for user in $(ls $VESTA/data/users); do
$BIN/v-update-user-quota $user
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit