diff --git a/bin/v-add-sys-quota b/bin/v-add-sys-quota new file mode 100755 index 00000000..bac5b2bd --- /dev/null +++ b/bin/v-add-sys-quota @@ -0,0 +1,91 @@ +#!/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 +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 diff --git a/bin/v-add-user b/bin/v-add-user index aa1c0acc..732fde24 100755 --- a/bin/v-add-user +++ b/bin/v-add-user @@ -97,17 +97,10 @@ if [ ! -z "$DNS_SYSTEM" ]; then chmod 751 $HOMEDIR/$user/conf/dns fi - # Set permissions chmod a+x $HOMEDIR/$user chattr +i $HOMEDIR/$user/conf -# Checking quota -if [ ! -z "$DISK_QUOTA" ]; then - DISK_QUOTA=$(echo "$pkg_data" | grep 'DISK_QUOTA' | cut -f 2 -d \') - #$BIN/v-add-user_quota "$user" "$DISK_QUOTA" -fi - #----------------------------------------------------------# # Vesta # @@ -212,6 +205,12 @@ TIME='$TIME' DATE='$DATE'" > $USER_DATA/user.conf chmod 660 $USER_DATA/user.conf +# Updating quota +if [ "$DISK_QUOTA" = 'yes' ]; then + echo "Setting quota" + $BIN/v-update-user-quota "$user" +fi + # Updating admin counter if [ "$user" != 'admin' ]; then increase_user_value 'admin' '$U_USERS' diff --git a/bin/v-delete-sys-quota b/bin/v-delete-sys-quota new file mode 100755 index 00000000..13f23e9c --- /dev/null +++ b/bin/v-delete-sys-quota @@ -0,0 +1,63 @@ +#!/bin/bash +# info: delete system quota +# opions: NONE +# +# The script disables filesystem quota on /home patition + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + + +#----------------------------------------------------------# +# 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 + mount -o remount $mnt +fi + +# Disabling fs quota +if [ -z "$(quotaon -pa|grep " $mnt "|grep user|grep 'off')" ]; then + quotaoff $mnt +fi + +# Deleting quota index +if [ -e "$mnt/aquota.user" ]; then + rm $mnt/aquota.user +fi + +# Deleting weekly cron job +rm -f /etc/cron.daily/quotacheck + +# Updating DISK_QUOTA value +if [ -z "$(grep DISK_QUOTA $VESTA/conf/vesta.conf)" ]; then + echo "DISK_QUOTA='no'" >> $VESTA/conf/vesta.conf +else + sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='no'/g" $VESTA/conf/vesta.conf +fi + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event "$OK" "$EVENT" + +exit diff --git a/bin/v-rebuild-user b/bin/v-rebuild-user index 63aaa35d..2d57f6ae 100755 --- a/bin/v-rebuild-user +++ b/bin/v-rebuild-user @@ -36,6 +36,11 @@ is_object_unsuspended 'user' 'USER' "$user" # Action # #----------------------------------------------------------# +# Update disk quota +if [ "$DISK_QUOTA" = 'yes' ]; then + $BIN/v-update-user-quota $user +fi + # Rebuild user rebuild_user_conf diff --git a/bin/v-update-user-quota b/bin/v-update-user-quota new file mode 100755 index 00000000..99b2e11d --- /dev/null +++ b/bin/v-update-user-quota @@ -0,0 +1,49 @@ +#!/bin/bash +# info: update user disk quota +# options: USER +# +# The functions upates disk quota for specific user + + +#----------------------------------------------------------# +# Variable&Function # +#----------------------------------------------------------# + +# Argument defenition +user=$1 + +# Includes +source $VESTA/func/main.sh +source $VESTA/conf/vesta.conf + + +#----------------------------------------------------------# +# Verifications # +#----------------------------------------------------------# + +check_args '1' "$#" 'USER' +validate_format 'user' +is_object_valid 'user' 'USER' "$user" + + +#----------------------------------------------------------# +# Action # +#----------------------------------------------------------# + +# Updating disk quota +soft=$(get_user_value '$DISK_QUOTA') +soft=$((soft * 100)) +hard=$((soft + 50000)) + +mnt=$(df -P /home |awk '{print $6}' |tail -n1) +setquota $user $soft $hard 0 0 $mnt + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Logging +log_event "$OK" "$EVENT" + +exit