You are not logged in.
I recently came across the fantastic FATSort utility (already in the Fedora, Debian, Ubuntu, and Gentoo repositories) to sort the files in FAT partitions.
I find it really useful when you have to play music, videos or whatever in proper order in some dumb device with a USB port.
As I have installed Xubuntu (14.04) on some friends and relatives' computers, I wanted to use the command, and turn it into a simple button/launcher, which proved not so easy for my actual skills (I tried with
sudo fatsort -f /dev/sdb1
but there are some variables to account for, as the actual mount point not being fixed, etc, which makes it sub-optimal).
Anyway, shortly after that I stumbled upon fatsort-gui.py (blog post and source code) but, unfortunately, it seems outdated, and fails quickly with a
/bin/sh: 1: hal-device: not found
showing me a beautiful, but empty GUI :-(
So I wondered if, being the Python script quite short (under 100 lines with notice and all), any of you could help me updating it and adding this simple button to the panel of some new users. Just that, thanks, cheers!
Last edited by alcornoqui (2015-01-21 01:07:08)
Offline
Usage: fatsort [options] device
Options:
-c Ignore case of file names
-f Force sorting even if filesystem is mounted
-h Print some help
-i Print file system information only
-I Ignore prefixes "a" and "the"
-l Print current order of files only
-o flag Sort order of files where flag is one of
d : directories first (default)
f : files first
a : files and directories are not differentiated
-n Natural order sorting
-q Be quiet
-r Sort in reverse order
-R Sort in random order
-v Print version information
The following options can be specified multiple times:
-d dir Sort directory dir only
-D dir Sort directory dir and all subdirectories
-x dir Don't sort directory dir
-X dir Don't sort directory dir and its subdirectories
-h, -i, -l, -q and -v is basically useless for sorting, -f, -r, -c, -n and -R is probably not wanted, -o will be most time d(which is default) and I don't really see a point in ignoring dirs or folders on an mp3 player. So this would bring us to this two possible commands:
sudo fatsort /dev/sdX
or
sudo fatsort -I /dev/sdX
as you can see every script here would be a waste of time
Offline
Well, the point of the GUI is mostly to select the right device to be sorted. If this is going to be used by people with even less computer skills than me, I feel like I can't assume that it's always going to be /dev/sdb1 (I use the terminal myself, and know when to change the command to /dev/sdc1 or whatever if necessary, but I still unmount and eject the drive through Thunar, for example, and those actions can be scripted).
There are, then, I think, three or four parts here: identify/select the device to sort, unmount it, and eject it after the command is executed. The linked fatsort-gui script goes in that direction (I'm not sure if it ejects the device), and I think it's perfect for my usecase but, alas, I can't make it work...
Thanks for your comment, though, I'll keep digging, I should learn how to do these kind of things!
Last edited by alcornoqui (2015-01-21 02:31:50)
Offline
so you would need something like:
#!/bin/sh
if [ ! -t 0 ]; then
x-terminal-emulator -e "$0"
exit 0
fi
findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat
printf "\n"
read -p "Please enter the device name(eg:/dev/sdc) :" disk
printf "\n"
read -p "Ignore prefixes? [y/n] :" ignprefixes
if [ `echo $ignprefixes` = "y" ]; then
printf "ignoring prefixes\n"
opt1="-I"
fi
printf "\n"
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
printf "Aborting...\n"
sleep 3
exit 1
fi
#sudo umount $disk && fatsort $opt1 $disk
#su -c "umount $disk && fatsort $opt1 $disk"
printf "\ndone\n"
sleep 3
Last edited by sixsixfive (2015-01-21 16:48:09)
Offline
Wow, thanks a lot... Still, I get this error:
findmnt: opción incorrecta -- «D»
followed by the help text of "findmnt" (which I didn't even know I had installed!).
I guess I'll take a good look at it this evening (GMT here), and try to tweak it without bothering you too much (I see the actual fatsort commands are commented, I guess at one point I should uncomment one of them, am I right?).
I really appreciate your help, I'll keep posting until I grok it! (I won't apologise for my english because I know it's funny, enjoy!)
Offline
the incorrect option is probably because you have an old(very old) udev release
>I guess at one point I should uncomment one of them, am I right?
correct either the su or sudo command
Offline
Away from my computer now, will check tonight... Thanks!
Offline
Hello. I got it working, wooo!
I have quite a hard time with bash builtins and regexes, but it's being nice to scratch this itch... Here's the commented script as of now:
#!/bin/sh
# Let's see if I understand the script:
# This opens a terminal if needed
if [ ! -t 0 ]; then
x-terminal-emulator -e "$0"
exit 0
fi
# The next line is the one that threw the error.
# I changed "D" for "m", after RTFM. The output was:
# /media/alcornoqui/USBSTICK /dev/sdb1 vfat
findmnt -mo TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat
#
printf "\n"
read -p "Please enter the device name(eg:/dev/sdc) :" disk
printf "\n"
# I could ignore this, a's and the's are fine.
#read -p "Ignore prefixes? [y/n] :" ignprefixes
#if [ `echo $ignprefixes` = "y" ]; then
# printf "ignoring prefixes\n"
# opt1="-I"
#fi
#printf "\n"
# But this should stay
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
printf "Aborting...\n"
sleep 3
exit 1
fi
# These two next lines came commented, I've uncommented
# the first (but I've removed $opt1 for now)
sudo umount $disk && sudo fatsort $disk #removed the trailing "
# I had to put sudo before fatsort, but it worked!!!
#su -c "umount $disk && fatsort $opt1 $disk"
# I wonder if I could include the "eject" command in the same way:
# sudo eject $disk
# I tried but I'm not sure it worked
printf "\ndone\n"
sleep 3
BTW, my version of udev is 204-5ubuntu20.9 from the Trusty updates repository.
Lastly, did you take a look at fatsort-gui? The window that shows (through Zenity) looks great, and would allow my terminal-fearing family to sleep tight-er...
Couldn't we somehow shoehorne it in?
Anyway, I'll keep digging tomorrow, thanks a lot! It's being fun...
Offline
for yad this would be: (zenity is like gtk3, it breaks things in every release)
disk=$(yad --list --title="Please choose your device" --column="Mountpoint" --column="Device" --column="fs type" `findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]" | grep vfat` --geometry 640x480 | cut -d'|' -f2)
Offline
Thank you! No wonder you're just one step beyond the devil
That line did it. Minimal version:
#!/bin/sh
if [ ! -t 0 ]; then
x-terminal-emulator -e "$0"
exit 0
fi
disk=$(yad --list --title="Please choose your device" --column="Mountpoint" --column="Device" --column="fs type" `findmnt -mo TARGET,SOURCE,FSTYPE | grep vfat` --geometry 480x320 | cut -d'|' -f2)
read -p "I will now unmount and fatsort $disk, OK? [y/n] :" input
if [ `echo $input` != "y" ]; then
printf "Aborting...\n"
sleep 3
exit 1
fi
sudo umount $disk && sudo fatsort $disk && sudo eject $disk
printf "\ndone\n"
sleep 3
The changes (feel free to comment on them, of course):
1. Removed the first "grep" (as I don't have any internal FAT partition).
2. Removed the question about prefixes.
3. Added the eject command to the chain (it worked!)
Ideally, I should keep improving it (I really think I will), but I consider the problem solved.
Again, thank you and all the makers and maintainers & family of FOSS, you rock!!!
Offline
I should mention that this works through a nice button within my panel, etc. When I get some more time I'll post some screenshots and instructions for other new users. Bye!
Offline
[ Generated in 0.009 seconds, 8 queries executed - Memory usage: 601.84 KiB (Peak: 618.69 KiB) ]