Explorar el Código

Fix/v-add-sys-quota and v-delete-sys-quota (#3991)

Add systemctl daemon-reload before mount and use v-change-sys-config-value to modify DISK_QUOTA value
sahsanu hace 2 años
padre
commit
e32a4e550a
Se han modificado 2 ficheros con 19 adiciones y 23 borrados
  1. 5 10
      bin/v-add-sys-quota
  2. 14 13
      bin/v-delete-sys-quota

+ 5 - 10
bin/v-add-sys-quota

@@ -22,8 +22,7 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Ensure that quota kernel modules are installed
 # Ensure that quota kernel modules are installed
-kernel_module_check=$(find /lib/modules/$(uname -r) -type f -name '*quota_v*.ko*' | egrep '.*' && [ $? -eq 0 ])
-if [ -z "$kernel_module_check" ]; then
+if ! find "/lib/modules/$(uname -r)" -type f -name '*quota_v*.ko*' | grep -q '.*'; then
 	# Install kernel modules for quota support.
 	# Install kernel modules for quota support.
 	# Requires reboot to activate updated kernel.
 	# Requires reboot to activate updated kernel.
 	echo "Installing required kernel modules for quota support..."
 	echo "Installing required kernel modules for quota support..."
@@ -33,8 +32,7 @@ if [ -z "$kernel_module_check" ]; then
 fi
 fi
 
 
 # Checking quota package
 # Checking quota package
-quota=$(which --skip-alias --skip-functions quota 2> /dev/null)
-if [ $? -ne 0 ]; then
+if ! type -P quota &>/dev/null; then
 	if [ -f "/etc/redhat-release" ]; then
 	if [ -f "/etc/redhat-release" ]; then
 		dnf -y install quota > /dev/null 2>&1
 		dnf -y install quota > /dev/null 2>&1
 	else
 	else
@@ -56,10 +54,11 @@ mnt=$(df -P /home | awk '{print $6}' | tail -n1)
 lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
 lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
 opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
 opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
 fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
 fnd='usrquota\|grpquota\|usrjquota=aquota.user\|grpjquota=aquota.group\|jqfmt=vfsv0'
-if [ $(echo $opt | tr ',' '\n' | grep -x $fnd | wc -l) -ne 5 ]; then
+if [ "$(echo "$opt" | tr ',' '\n' | grep -c -x $fnd)" -ne 5 ]; then
 	old=$(echo $(echo $opt | tr ',' '\n' | grep -v 'usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt=') | tr ' ' ',')
 	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'
 	new='usrquota,grpquota,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0'
 	sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
 	sed -i "$lnr s/$opt/$old,$new/" /etc/fstab
+	systemctl daemon-reload
 	mount -o remount "$mnt"
 	mount -o remount "$mnt"
 fi
 fi
 
 
@@ -83,11 +82,7 @@ if [ -n "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is off')" ];
 fi
 fi
 
 
 # Updating hestia.conf value
 # Updating hestia.conf value
-if [ -z "$(grep DISK_QUOTA $HESTIA/conf/hestia.conf)" ]; then
-	echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
-else
-	sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='yes'/g" $HESTIA/conf/hestia.conf
-fi
+$BIN/v-change-sys-config-value "DISK_QUOTA" "yes"
 
 
 # Rebuilding user quota
 # Rebuilding user quota
 for user in $($BIN/v-list-sys-users plain); do
 for user in $($BIN/v-list-sys-users plain); do

+ 14 - 13
bin/v-delete-sys-quota

@@ -31,37 +31,38 @@ check_hestia_demo_mode
 
 
 # Deleting group and user quota on /home partition
 # Deleting group and user quota on /home partition
 mnt=$(df -P /home | awk '{print $6}' | tail -n1)
 mnt=$(df -P /home | awk '{print $6}' | tail -n1)
-lnr=$(cat -n /etc/fstab | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
+lnr=$(cat -n /etc/fstab | grep -v "#" | awk '{print $1,$3}' | grep "$mnt$" | cut -f 1 -d ' ')
 opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
 opt=$(sed -n ${lnr}p /etc/fstab | awk '{print $4}')
 fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt='
 fnd='usrquota\|grpquota\|usrjquota=\|grpjquota=\|jqfmt='
 if [ -n "$(echo $opt | grep $fnd)" ]; then
 if [ -n "$(echo $opt | grep $fnd)" ]; then
 	rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',')
 	rep=$(echo $(echo $opt | tr ',' '\n' | grep -v $fnd) | tr ' ' ',')
 	sed -i "$lnr s/$opt/$rep/" /etc/fstab
 	sed -i "$lnr s/$opt/$rep/" /etc/fstab
+	systemctl daemon-reload
 	mount -o remount "$mnt"
 	mount -o remount "$mnt"
 fi
 fi
 
 
 # Disabling group and user quota
 # Disabling group and user quota
-quotaoff=$(which --skip-alias --skip-functions quotaoff 2> /dev/null)
-if [ $? -eq 0 ]; then
-	if [ -n "$(quotaon -pa | grep " $mnt " | grep 'user\|group' | grep 'is on')" ]; then
-		$quotaoff $mnt
+if quotaon="$(type -P quotaon 2>/dev/null)" && quotaoff="$(type -P quotaoff 2>/dev/null)"; then
+        if "${quotaon}" -pa | grep " $mnt " | grep 'user\|group' | grep -q 'is on' &>/dev/null; then
+		"$quotaoff" "$mnt"
 	fi
 	fi
 fi
 fi
 
 
 # Deleting v1 + v2 group and user quota index
 # Deleting v1 + v2 group and user quota index
-for idx in $(echo 'quota.user quota.group aquota.user aquota.group'); do
+for idx in quota.user quota.group aquota.user aquota.group; do
 	[ -e "$mnt/$idx" ] && rm -f "$mnt/$idx"
 	[ -e "$mnt/$idx" ] && rm -f "$mnt/$idx"
 done
 done
 
 
-# Deleting cron job
-rm -f /etc/cron.daily/quotacheck
+# Deleting cron job and forcequotacheck
+if [[ -f "/etc/cron.daily/quotacheck" ]]; then
+        rm -f "/etc/cron.daily/quotacheck"
+fi
+if [[ -f "/forcequotacheck" ]]; then
+        rm -f "/forcequotacheck"
+fi
 
 
 # Updating hestia.conf value
 # Updating hestia.conf value
-if [ -z "$(grep DISK_QUOTA $HESTIA/conf/hestia.conf)" ]; then
-	echo "DISK_QUOTA='no'" >> $HESTIA/conf/hestia.conf
-else
-	sed -i "s/DISK_QUOTA=.*/DISK_QUOTA='no'/g" $HESTIA/conf/hestia.conf
-fi
+$BIN/v-change-sys-config-value "DISK_QUOTA" "no"
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 #                       Hestia                             #
 #                       Hestia                             #