Benutzer-Werkzeuge

Webseiten-Werkzeuge


linux:tuxcmd-udev

TuxCommander & Udev & mount

Summary

Mounting usb drives using mountbar of TuyCommander.

Main

I'm using TuxCommander and I like it. That is why I've worked some time to be able to mount usb drives using the mountbar of it. And here is the result of my work. It was a bit tricky because I had to change the source code of TuxCommander. But don't be afraid I'll release here all you need to get it working.

Patch for UConfig.pas

First apply the patch to the sources of TuxCommander.

  • get source:
    git clone git://git.bzatek.net/tuxcmd
  • change into the directory
  • apply Patch:
    patch -Ni <path-to>mounter.patch
  • compile sources:
    make && make install

If you are using ArchLinux you can use tuxcmd-git in my repository

mounter.patch
diff --git a/UConfig.pas b/UConfig.pas
index 9ee6f16..a878bb9 100644
--- a/UConfig.pas
+++ b/UConfig.pas
@@ -800,6 +800,9 @@ end;
 (********************************************************************************************************************************)
 procedure ReadMounter;
 var s: string;
+    MountDir: string;
+		Handle: PDIR;
+		DirEnt: PDirent64;
     IniFile: TMyIniFile;
     Sections: TStringList;
     i: integer;
@@ -847,6 +850,38 @@ begin
     InternalMounterConfmtime := GetFileTime(IncludeTrailingPathDelimiter(s) + 'mounter');
   end;
   except end;
+  MountDir := IncludeTrailingPathDelimiter(s) + 'mounters';
+  if DirectoryExists(MountDir) then begin
+    Handle := opendir(PChar(MountDir));
+    repeat
+      DirEnt := readdir64(Handle);
+			if not (DirEnt = nil) then begin
+        IniFile := TMyIniFile.Create(IncludeTrailingPathDelimiter(MountDir) + string(PChar(@DirEnt^.d_name[0])), True);
+        try
+          Sections := TStringList.Create;
+          IniFile.ReadSections(Sections);
+          if Sections.Count > 0 then
+            for i := 0 to Sections.Count - 1 do
+  					  begin
+                Item := TMounterItem.Create;
+                with Item do
+  							  begin
+                    Device := Sections[i];
+                    DisplayText := IniFile.ReadString(Sections[i], 'DisplayText', '');
+                    MountPath := IniFile.ReadString(Sections[i], 'MountPath', '');
+                    IconPath := IniFile.ReadString(Sections[i], 'IconPath', '');
+                    MountCommand := IniFile.ReadString(Sections[i], 'MountCommand', '');
+                    UmountCommand := IniFile.ReadString(Sections[i], 'UmountCommand', '');
+                    DeviceType := IniFile.ReadInteger(Sections[i], 'DeviceType', 0);
+                  end;
+                  MounterList.Add(Item);
+							end;
+            Sections.Free;
+        except end;
+			end;
+    until DirEnt = nil;
+		closedir(Handle);
+  end;
 end;
 
 procedure WriteMounter;

Mount script

Download this script and change the variables „mounter“ and „sudocmd“ in it. „mounter“ has to be the directory $HOME/.tuxcmd/mounters which you may have to create first. „sudocmd“ is the command to run some commands in the script as root. It produces the needed files for each usb drive for TuxCommander.

media-mount.sh
#!/bin/bash
 
mounter="/home/alw/.tuxcmd/mounters"
sudocmd="sudo"
option=${4}
dev=${2}
dir=${3}
 
case ${1} in
	a)
		/bin/echo -e "[${dev}]\nDisplayText=$(basename ${dir})\nMountPath=${dir}\nMountCommand=${sudocmd} /scripts/media-mount.sh m %dev %dir ${option} ${5}\nUmountCommand=${sudocmd} /scripts/media-mount.sh u ${dev} ${dir}\nDeviceType=1\n" >> ${mounter}/$(basename ${dev})
		touch ${mounter}/../mounter
		;;
	m)
		[ "${5}" != "" ] && xterm -e "${sudocmd} cryptsetup luksOpen ${5} ${6} &&	${sudocmd} mkdir -p ${dir} && §{sudocmd} mount -o ${option} ${dev} ${dir}"
		[ "${5}" == "" ] && ${sudocmd} mkdir -p ${dir} && ${sudocmd} mount -o ${option} ${dev} ${dir}
		;;
	u)
		while [ "$(mount | grep ${dev})" != "" ]
		do
			[ "$(mount | grep ${dev})" != "" ] && ${sudocmd} umount ${dev}
		done
		[[ "${dev}" =~ ".*\/mapper\/.*" ]] && ${sudocmd} cryptsetup luksClose $(basename ${dev})
		rm -r ${dir}
		;;
	r)
		while [ "$(mount | grep ${dev})" != "" ]
		do
			[ "$(mount | grep ${dev})" != "" ] && umount ${dev}
		done
		cryptsetup luksClose $(basename ${dev})
		rm ${mounter}/$(basename ${dev})
		rm -r ${dir}
		touch ${mounter}/../mounter
		;;
esac

Udev Rule

The last file you need is the udev rule. Download this file and save it to /etc/udev/rules.d/11-media-by-label-auto-mount.rules. Then change the pathes for the script in the lines 24 and 26 (replace /scripts/ with your path).

11-media-by-label-auto-mount.rules
KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"
 
# Do not mount devices on boot because otherwise fsck may fail
ACTION=="add", PROGRAM!="/bin/grep ' / / rw[, ]' /proc/self/mountinfo", GOTO="media_by_label_auto_mount_end"
 
# Open LUKS partition if necessary
PROGRAM=="/sbin/blkid -o value -s TYPE %N",  RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"
ENV{crypto}=="", ENV{device}="%N"
ACTION=="add", ENV{crypto}!="", ENV{mount}="%N %k "
 
# Global mount options
ACTION=="add", ENV{mount_options}="noatime"
# Filesystem-specific mount options
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"
 
# Get label if present, otherwise assign one
PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"
# Use basename to correctly handle labels such as ../mnt/foo
PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"
ENV{dir_name}=="", ENV{dir_name}="usbhd-%k"
 
# Mount the device
ACTION=="add", ENV{dir_name}!="", RUN+="/scripts/media-mount.sh a '/dev/%E{crypto}%k' '/media/%E{dir_name}' '%E{mount_options}' '%E{mount}'"
 
ACTION=="remove", ENV{dir_name}!="", RUN+="/scripts/media-mount.sh r '/dev/%E{crypto}%k' '/media/%E{dir_name}'"
 
# Exit
LABEL="media_by_label_auto_mount_end"

Now run

udevadm control restart

as root and now you should get a request by TuxCommander after pluging in a usb drive whether he should reload the config. After reloading a button should appear in the mountbar with the name of the usb drive label or something like usb-.

Comments



L X​ O᠎ D O
linux/tuxcmd-udev.txt · Zuletzt geändert: 2010/11/24 21:28 (Externe Bearbeitung)