Current File : //root/12122023.sh
mkdir -p /patch/
filechk="/patch/patch12122023.log"
if [ -f "$filechk" ]
then
    echo "Patch 12122023 Already Updated" >> /patch/patch12122023.log
    exit
fi
echo "patch started " > /patch/patch12122023.log

# Read the version from the file

version=$(awk -F 'Version : ' '/Version :/ {print $2}' /etc/sentora/panel/version.txt | tr -d '\n' | tr -d ' ')

# Check the version and run the same command for all versions
if [ "$version" = "3.9" ]; then
cd /scripts/
wget -O unwanted_dovecot_conf_delete.sh http://d.ovipanel.in/Patch/unwanted_dovecot_conf_delete.sh 
echo '0 7 * * * /usr/bin/sh /scripts/unwanted_dovecot_conf_delete.sh > /scripts/unwanted_dovecot_conf_delete.log' >> /var/spool/cron/root
/usr/bin/sh /scripts/unwanted_dovecot_conf_delete.sh > /scripts/unwanted_dovecot_conf_delete.log
fi
# Set the MySQL socket
MYSQL_SOCKET="/usr/local/mysql/mysql.sock"

# MySQL connection command with the database selection
MYSQL_CMD="/usr/local/mysql/bin/mysql --socket=$MYSQL_SOCKET sentora_core"

# Check x_weebly for non-empty we_created_ts
$MYSQL_CMD -e "SELECT * FROM x_weebly WHERE we_created_ts IS NOT NULL;"

# Check if x_weebly_user is empty
WEEBLY_USER_COUNT=$($MYSQL_CMD -N -e "SELECT COUNT(*) FROM x_weebly_user;")

# If x_weebly_user has any values, perform actions
if [ $WEEBLY_USER_COUNT -gt 0 ]; then

    # Store the IP address in a variable
    WEEBLY_USER_IP=$($MYSQL_CMD -N -e "SELECT weebly_user_ip FROM x_weebly_user LIMIT 1;")
    echo "IP address found for x_weebly_user: $WEEBLY_USER_IP" >> /patch/patch12122023.log

else
    
	# If x_weebly_user is empty, perform actions
    # Set weebly module to false in x_modules using case-insensitive comparison
    $MYSQL_CMD -e "UPDATE x_modules SET mo_enabled_en = 'false' WHERE LOWER(mo_name_vc) = 'weebly';"
    
	# Check the updated values in x_modules
    $MYSQL_CMD -e "SELECT * FROM x_modules WHERE LOWER(mo_name_vc) = 'weebly';"
    
	# Find the mo_id_pk for the weebly module using case-insensitive comparison
    MO_ID=$($MYSQL_CMD -N -e "SELECT mo_id_pk FROM x_modules WHERE LOWER(mo_name_vc) = 'weebly' LIMIT 1;")
    
	# If mo_id_pk is found, delete permissions in x_permissions
    if [ ! -z "$MO_ID" ]; then
        $MYSQL_CMD -e "DELETE FROM x_permissions WHERE pe_module_fk = $MO_ID;"
    fi

fi

echo "Patch End" >> /patch/patch12122023.log