Categories

Here’s what I need to do after installing Veno File Manager on Ubuntu

Author

I recently bought Veno File Manager, and everything was fine until I tried using it with Transmission torrent client. I wanted to use Veno to show the files I downloaded using Transmission. Overall, it’s been good, but Veno shows an ajax error when my downloaded file has folders with [ and ] characters.

By default, when you make a folder using Veno and you try to use [ and ] characters, it’ll automatically change the folder name by taking out the [ ] and replacing them with -. So, for example, [test] becomes -test-. However, this doesn’t happen if you already have a folder with a name you’ve chosen before and you move it into the Veno directory. In that case, it gives you an ajax error specifically related to the folder table.

After trying different things and making some mistakes, I managed to create a script that can get rid of all the ‘bad’ names using ‘transliterate’. But before we can use it, we need to install pip. You can do that by typing:

				
					sudo apt install -y python3-pip
pip install transliterate
				
			

And then we can create a script, let’s call it rename.sh. To do that, open the text editor by typing:

				
					nano rename.sh
				
			

and paste the following inside:

				
					IFS=$'\n'

folder="/path/to/veno/uploads"
allowed_characters="a-zA-Z0-9_\. \/()-"
normalize_cmd="
import re
from transliterate import translit
normalized = translit(input(), 'ru', reversed=True)
stripped = re.sub('[^$allowed_characters]', '', normalized)
print(stripped)"

badfolders=$(find "$folder" -type d | grep ".*[^$allowed_characters].*" | awk '{ print -length, $0 }' | sort -n -s | cut -d" " -f2-)

for path in $badfolders; do
    oldpath="$path"
    newpath=$(echo "$oldpath" | python3 -c "$normalize_cmd")
    echo "From: $oldpath"
    echo "To:   $newpath"
    mv -vi -- "$oldpath" "$newpath"
    echo "--------------------------------------------"
done

				
			

The ‘ru’ in this script refers to the language code for Russian. It is used as an argument in the ‘translit’ function from the ‘transliterate’ module. This function transliterates the input text from Russian characters to their Latin equivalents.

In this script, the ‘normalize_cmd’ variable holds a Python code snippet that uses the ‘translit’ function to normalize the folder names by transliterating any Russian characters to their Latin counterparts. It also removes any characters that are not included in the ‘allowed_characters’ variable, which consists of alphanumeric characters, underscores, dots, spaces, forward slashes, hyphens, and parentheses.

The script then searches for folders within the specified ‘folder’ path that contain characters not included in the ‘allowed_characters’ variable. It loops through these ‘badfolders’, applies the normalization process using the ‘normalize_cmd’, and renames each folder accordingly using the ‘mv’ command.

Now, I want this script to run every 10 minutes. So, we need to set up a cron job. However, if we only run it as a sudoer, we won’t have sufficient permissions. Therefore, we really need to run it as the root user. Type following commands one by one:

				
					sudo su
crontab -e
				
			

And then, just add these lines to the crontab.

				
					*/10 * * * * chmod -R 777 /path/to/veno/uploads
*/10 * * * * sh /path/to/rename.sh
				
			

These cron jobs execute certain commands at intervals of every 10 minutes. Here’s an explanation of each job:

  1. */10 * * * * chmod -R 777 /path/to/veno/uploads This command sets the permissions of the /path/to/veno/uploads directory and all its contents to 777. The chmod command is used to change file permissions, and the -R option applies the permission change recursively to all files and directories within the specified path.

  2. */10 * * * * sh /path/to/rename.sh This command executes the rename.sh script located at /path/to/rename.sh using the shell (sh). The script contains the logic to rename folders based on the specified rules, as discussed earlier.

These cron jobs are scheduled to run every 10 minutes, denoted by */10 * * * *. The asterisks represent the time and date fields for minute, hour, day of the month, month, and day of the week, respectively.

Edit:

So, my friend mentioned that when he has a longer path, the script ends up stripping the folder path, which causes it to fail. I came up with two possible solutions: either rename the folder or switch to using rsync in the script. If you decide to go with the second option, here’s the modified script that should hopefully work. Just give it a try and let me know if you encounter any issues.

				
					IFS=$'\n'

folder="/path/to/veno/uploads"
allowed_characters="a-zA-Z0-9_\. \/()-"
normalize_cmd="
import re
from transliterate import translit
normalized = translit(input(), 'ru', reversed=True)
stripped = re.sub('[^$allowed_characters]', '', normalized)
print(stripped)"

badfolders=$(find "$folder" -type d | grep ".*[^$allowed_characters].*" | awk '{ print -length, $0 }' | sort -n -s | cut -d" " -f2-)

for path in $badfolders; do
    oldpath="$path"
    newpath=$(echo "$oldpath" | python3 -c "$normalize_cmd")
    echo "From: $oldpath"
    echo "To:   $newpath"
    rsync -av "$oldpath" "$newpath"
    rm -r "$oldpath"
    echo "--------------------------------------------"
done

				
			

In this modified version, the mv command is replaced with rsync -av, which copies the directories from the old path to the new path while preserving their attributes and structure. After the copy operation, the old directory is removed using rm -r.

Make sure to test the modified script on a test system or backup data before running it on production.