BigSmoke

Smokes your problems, coughs fresh air.

Page 38 of 52

Permissions on a samba share

When you mount a samba share without unix extensions enabled, you can set a GID, UID and permissions (on the client machine, at mount time) so you can adjust it to let non-root users use it.

Mounting FAT works this way as well. But there is a big difference. Where new files on a FAT file system are created according to the permissions you set at mount-time, new files on a SAMBA share have their permissions determined by the umask. However, when you unmount and remount the share, the permissions are changed to what they were set to at mount time.

This is very annoying behavior, because when you have files that belong to root:smbusers and you copy a file, it still belongs to root:smbusers, but when your umask is 0022, it will no longer be group writable and it has become a read only file.

I think this is a bug in the SMBFS/CIFS file system driver.

Samba rounds filesizes off to whole MB’s

I noticed when I did ‘du -hs’ on a sambamount, I got a disk usage that was unrealistically high. I did some research, and it appears that Samba rounds off file sizes to whole MB units, to optimize for windows clients:

And btw, why is samba rounding the minimum size up to 1MB ?

An optimisation for Windows clients. If we do this they allocate actually run faster against a Samba server (based on tests done by a NAS vendor).

Bash quoting

I’m always confused by bash’s quoting. I hope to put all my quote wisdom in this post and invoke other’s quote wisdom in the comments. I’ll give some examples of what I mean.

Let’s say you have a file with a space: “bla bla.txt”. If I were to ls that file, I would do:

ls 'bla bla.txt'

This works. However, when I want to do this from a variable (in a script) and do:

command="ls 'bla bla.txt'"
$command

The result is:

ls: cannot access 'bla: No such file or directory
ls: cannot access bla.txt': No such file or directory

You can solve this by using eval:

command="ls 'bla bla.txt'"
eval $command

This gives:

bla bla.txt

Some time ago, I suggested this as answer on somebodies question at userfriendly, to which somebody else said that using eval actually makes things worse:

That’s actually worse. . . as the quoting gets re-parsed (remember, ‘eval’ means “take arguments as shell input”), which means that single quotes in the name break it, horribly, and names with spaces get even _worse_.

Another example: let’s say you have two files:

-rw-r----- 1 halfgaar halfgaar 0 2009-10-18 16:51 bla's bla"s.txt
-rw-r----- 1 halfgaar halfgaar 0 2009-10-18 16:52 normal.txt

I’m gonna run this command on it: find . -mindepth 1 -exec ls ‘{}’ \;. When executed without eval, it says this:

find: missing argument to `-exec' 

With eval, it says:

./normal.txt
./bla's bla"s.txt

Eval seems to be what I need, so what is wrong with using it? Also, shouldn’t that double quote be a problem? If someone can give a situation where that poses problems, I’m all ears.

VIM insert mode shortcuts

A few months back, I stumbled upon a blog post with some interesting VIM shortcuts for within insert mode.

  • Ctrl+t and Ctrl-d adjust the current line indent one level to the right and left, respectively.
  • Ctrl+w deletes the last word. I already use this one a lot because it’s the same as in Readline’s Emacs mode (which I prefer over its vi mode).
  • Ctrl+u deleted all the way to the first non-whitespace character.

But the best stuff was in the comments:

  • Ctrl+o enters normal mode for just one command and then returns to insert mode. I find myself very often going to normal mode ‘temporarily’. This should make these occasions pass quicker.
  • Ctrl+y repeats the character at this position from the line above in this line. Ctrl+e does the same for the line below.
  • Ctrl+x Ctrl+l can be used to copy a whole line, allowing you to cycle through the lines with Ctrl+P and Ctrl+N.

Configuring X input devices through HAL

When I went from X.org < 7.3 to X.org > 7.3, I had to make some changes to my X input configuration.

First of all, I had to replace x11-drivers/synaptics (http://web.telia.com/~u89404340/touchpad/) with the newer x11-drivers/xf86-input-synaptics, which is automatically installed if you set INPUT_DEVICES="${INPUT_DEVICES} synaptics" or if you add “x11-base/xorg-server input_devices_synaptics” to /etc/portage/package.use.

Starting with X.org 7.3, you’re supposed to use HAL for all the X input configuration. All the "InputDevice" sections have to be removed from xorg.conf (and of course the references in "ServerLayout"). If you don’t want this, you can add the following options:

Section "ServerFlags"
  Option "AllowEmptyInput" "off"
  Option "AutoEnableDevices" "off"
EndSection

I chose HAL. I wanted to replicate the following settings using HAL.

Section "InputDevice"
    Identifier "Keyboard1"
    Driver     "kbd"
    Option "AutoRepeat" "500 30"
    Option "XkbRules"  "xorg"
    Option "XkbModel"  "thinkpadintl"
    Option "XkbLayout" "us"
    Option "XkbOptions"        "ctrl:nocaps,altwin:menu,compose:ralt,eurosign:e"
EndSection
 
Section "InputDevice"
    Identifier "Synaptics Touchpad"
    Driver     "synaptics"
    Option "SendCoreEvents" "true"
    Option "Device" "/etc/psaux"
    Option "Protocol"    "auto-dev"    # Auto detect
#    Option "TouchpadOff" "1" #Uncomment if you just want to disable the touchpad and use only the trackpoint
#    Option "HorizScrollDelta" "0" #Why is this in here by default. By Gods, it kill horizontal scrolling!
    Option "RightEdge" "5500" #This is a little bigger than the default narrowing the scroll region
    Option "BottomEdge" "4500" #This is a little bigger than the default narrowing the scroll region
    Option "RTCornerButton" "0" #disable Right Top corner "button" 
    Option "RBCornerButton" "0" #disable Right Top corner "button" 
    Option "SHMConfig" "on" #this allows configuration of the touchpad using qsynaptics, synclient, or what have you
EndSection

The keyboard part was easy. I copied /usr/share/hal/fdi/policy/10osvendor/10-keymap.fdi to /etc/hal/fdi/policy/99-keymap.fdi and made a few adjustments:

<?xml version="1.0" encoding="ISO-8859-1"?> <!-- -*- SGML -*- -->
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.keymap">
      <append key="info.callouts.add" type="strlist">hal-setup-keymap</append>
    </match>
 
    <match key="info.capabilities" contains="input.keys">
      <merge key="input.xkb.rules" type="string">xorg</merge>
 
      <!-- If we're using Linux, we use evdev by default (falling back to
           keyboard otherwise). -->
      <merge key="input.xkb.model" type="string">thinkpadintl</merge>
      <match key="/org/freedesktop/Hal/devices/computer:system.kernel.name"
             string="Linux">
        <merge key="input.xkb.model" type="string">evdev</merge>
      </match>
 
      <merge key="input.xkb.layout" type="string">us</merge>
      <merge key="input.xkb.variant" type="string" />
      <merge key="input.xkb.autoRepeat" type="string">500 30</merge>
      <merge key="input.xkb.options" type="string">ctrl:nocaps,altwin:menu,compose:ralt,eurosign:e</merge>
    </match>
  </device>
</deviceinfo>

The Touchpad configuration was a little more involving, because I added a few options which, before, I didn’t know the thing supported. 99-x11-synaptics.fdi:

<?xml version="1.0" encoding="ISO-8859-1"?>
 
<deviceinfo version="0.2">
  <device>
    <match key="info.capabilities" contains="input.touchpad">
 
    <merge key="input.x11_driver" type="string">synaptics</merge>
    <!-- Arbitrary options can be passed to the driver using
         the input.x11_options property since xorg-server-1.5. -->
 
    <!-- Switch on shared memory, enables the driver to be configured at runtime -->
    <!-- This allows configuration of the touchpad using qsynaptics, synclient, or what have you -->
    <merge key="input.x11_options.SHMConfig" type="string">on</merge>
 
    <!-- Enable vertical scrolling by dragging your finger along the right edge -->
    <merge key="input.x11_options.VertEdgeScroll" type="string">1</merge>
 
    <!-- Enable horizontal scrolling by dragging your finger along the left edge -->
    <merge key="input.x11_options.HorizEdgeScroll" type="string">1</merge>
 
    <!-- This is a little bigger than the default narrowing the scroll region -->
    <merge key="input.x11_options.RightEdge" type="string">5500</merge>
 
    <!-- This is a little bigger than the default narrowing the scroll region -->
    <merge key="input.x11_options.BottomEdge" type="string">4500</merge>
 
    <!-- disable Right Top corner "button" -->
    <merge key="input.x11_options.RTCornerButton" type="string">0</merge>
 
    <!-- disable Right Bottom corner "button" -->
    <merge key="input.x11_options.RBCornerButton" type="string">0</merge>
 
    <!-- Enable vertical scrolling when dragging with two fingers anywhere on the touchpad -->
    <merge key="input.x11_options.VertTwoFingerScroll" type="string">1</merge>
 
    <!-- Enable horizontal scrolling when dragging with two fingers anywhere on the touchpad -->
    <merge key="input.x11_options.HorizTwoFingerScroll" type="string">1</merge>
 
    <!-- Enable tapping to emulate mouse buttons -->
    <merge key="input.x11_options.TapButton1" type="string">1</merge>
    <merge key="input.x11_options.TapButton2" type="string">2</merge>
    <merge key="input.x11_options.TapButton3" type="string">3</merge>
 
    <!-- Maximum movement of the finger for detecting a tap -->
    <merge key="input.x11_options.MaxTapMove" type="string">221</merge>
 
    <!-- For other possible options, check CONFIGURATION DETAILS in synaptics man page -->
</match>
</device>
</deviceinfo>

I’m still not completely satisfied with the Touchpad configuration (actually less so than before I started messing with HAL), so I wrote a little tool to be able to mess around with my configuration a little bit easier.

Introducing synclient-sync

With SHMConfig on, you can use the synclient program to make changes to the touchpad configuration without having to restart X. I decided that it would be handy if I could utilize this to test out changes I made to the HAL config file without having to reload it, so I wrote a little script which detects the differences between the current (live) configuration and the configuration in the HAL .fdi file. The running configuration is then updated to reflect the changes in this file. (Newer versions of the script can be found on GitHub)

#!/bin/bash
 
HAL_FILE=/etc/hal/fdi/policy/99-x11-synaptics.fdi
 
VERBOSITY_LEVEL=2
 
usage()
{
    cat <<EOF
Usage: $0 options
 
OPTIONS:
--verbosity [level] Control the level of output processed by the script.
Level 0: No output at all
Level 1: Only output changed options
Level 2: Only output options the configuration file
Level 3: Output all options
--verbose Shortcut verbosity level 3
- Show this
EOF
 
    1
}
 
options_from_hal_file()
{
    HAL_SED_FILTER='s%^\s*<merge\s*key="input\.x11_options\.\(.*\?\)"\s*type="string">\(.*\)</merge>%\1=\2%'
    cat $HAL_FILE \
        | grep '<merge key="input.x11_options.' \
        | grep -v 'SHMConfig' \
        | sed -e $HAL_SED_FILTER
}
 
from()
{
     synclient -l \
        | grep '=' \
        | sed -e 's/\s//g' \
        | option;
key= $option|cut -f 1 -d '='`
            old_val= $option|cut -f 2 -d '='`
            new_val=`options_from_hal_file|grep $key|cut -f 2 -d '='`
 
            [ -z $new_val ];
                [ $VERBOSITY_LEVEL == 3 ] && -e "\e[1;30m$key = $old_val\e[0m"
            [ $old_val != $new_val ];
                [ $VERBOSITY_LEVEL -ge 1 ] && -e "\e[1m$key = \e[1;31m$old_val \e[1;4;32m$new_val\e[0m"
                synclient "$key=$new_val"
            # The HAL file and the life configuration are in sync
                [ $VERBOSITY_LEVEL -ge 2 ] && -e "\e[1m$key = \e[4m$new_val\e[0m"
           
}
 
do_from=0 [ $# -gt 0 ]; do
"$1"
        --from-hal)
            do_from=1
            ;;
        --verbose)
            VERBOSITY_LEVEL=3
            ;;
        --verbosity)
            VERBOSITY_LEVEL=$2
           
            ;;
        -)
            usage
            ;;
   
  [ $do_from == 1 ];
from
usage
 
# vim: set shiftwidth=4 tabstop=4 expandtab: 

References

Microblogging

I’ve been struggling with the decision whether to start a microblog or not. Actually, I had already decided ‘yes’, but then had trouble deciding the software or on-line platform. I actually preferred a self-hosted solution (otherwise, I’d feel the need to backup or even mirror everything myself anyway). Trying to choose a solution took me so much time that I actually reconsidered the need for microblogging. What is it, after all, that attracted me to it?

The first reason that I consider microblogging a great idea is context. I have all these little jots in my computer and bookmarks spread all over the place and most of it is completely irrelevant and should probably be deleted or at least buried and forgotten. Everything that I blog about is immediately buried and I can forget about it, knowing that I can pop it back up whenever I want to by Googling for it or by doing a quick tag search. When I’m blogging about something, because I know it’s going to be published, I take care to put it in proper context so that I’ll know its relevance when I later stumble upon it. A very important piece of this context is the date on which I post something. Every post being dated is also a very important factor in being able to ‘bury’ it. There’s nothing like having a date in the URL for saying: “This might have been important then, but it might not be so now.”

So, I wanted a microblog to be able to much easier organize all these little thoughts and links I encounter by simply dropping them into a stream, but not a data stream. No, not a data stream. del.icio.us, for example, isn’t really working for me because it’s just the same as having a whole lot of crap URLs on disk. I don’t bookmark stuff because I want to have a neat catalog of the world; I bookmark stuff because I want to get it out of my head and get on with what I’m doing. Then, later, I might want to revisit depending on the context. Normally, when bookmarking something, you might be assigning tags and everything and even a description in which you could put the same as you’d put in a post to a microblog, but I’m still in a different mode than when I’m saying:

  • While researching microblogs, I just stumbled across Ping.fm
  • I’m really wondering: shouldn’t I simply use Twitter?
  • But what about the crap limitations on length and layout? I want to be able to put in at least a paragraph.

Even as I’m writing this, I notice how much easier this flows as a method of note-taking than trying to turn something into a coherent story. Note that the context is immediately apparent because the posts follow each other in time.

What has basically hijacked my desire to start a microblog is Twitter, which allows you to send updates by SMS, which imposes a ridiculous limitation on the length of posts. The problem with this is that is confuses my choises, because the second reason to want to start a microblog is sharing. With Twitter and its competitors it’s possible to reply to others in your status updates and some even support a rudimentary form of tagging and groups. This promises a lot of social advantages which I’ve also enjoyed with this blog. However, being limited to interaction within the walled garden of Twitter to me is no better than posting everything as status updates to Facebook (or Hyves, the Dutch social network). It’s actually worse, because at least Facebook has a convenient interface and less arbitrary restrictions coming from SMS.

To solve the walled-garden problem, there’s the OpenMicroBlogging (OMB) protocol with two open source implementations: StatusNet and OpenMicroBlogger. Both can be installed on your own web host, but both also have a free sign-up service (OpenMicroBlogger and identi.ca respectively).

Some guy has even figured out how to post from Laconi.ca (now StatusNet) to WordPress. But, I have to wonder: why did I want to impose the OMB restrictions on myself in the first place? I still can’t use mark-up. This makes me having to use weird line-noise such as ‘@’ and ‘#’. But, worst of all, it means that putting in an URL quickly makes the post exceed its maximum length, because it’s all simple plain text and every character is counted. And that’s my problem with OMB and many of these services in general: 140 characters is just a little too restricting, especially if I’m going to use it for URLs. I simply don’t like URL shortening services. So, why was it that I’d want to use OMB? Interoperability. But my blog has excellent interoperability. Why would I need to torture myself by requiring even more protocols, while all I could really need is some custom theming for short posts. There’s plenty of microblogging themes for WordPress to prove this point.

There’s just the issue of blog posts being a bit meta-data heavy: they require a title, a nice slug and tags. But, on the other hand: OpenMicroBlogger, for example, has already added support for meta tags because inserting lots of little ‘#’ characters in your posts makes them look like line-noise.

I have to resist the temptation of sticking my nose into every new fad and network. It’s simply the reality of the day that the whole World Wide Web is a disjointed mess of data islands, each with different context definitions. For now, I think that I should restrict myself to the context of the blogosphere.

In the end, with my blog blog interoperability is actually better than with a OMB microblog, because of nice features such as trackbacks and the ability to comment without the commenter first having to register with a microblog themselves.

More

  • Louis Gray has written quite a bit about Identi.ca and microblogging in general.

Tracking WordPress in a Subversion vendor branch

Two months prior to writing a script to upgrade MediaWiki installations using Subversion vendor branches, I wrote something similar for WordPress. It’s a little bit more limited and should really incorporate some of the improvements made for the MediaWiki version, but it worked fine so far:

cat upgrade-wordpress.sh 
#!/bin/bash
 
svn_repo_url=file:///var/svn/blog.omega-research.org/vendor/wordpress/
last_version=$1
new_version=$2
 
tmp_dir=`mktemp -d` $tmp_dir
 version $*;
    "Downloading and extracting WordPress version $version..."
 
    [ -z `svn ls $svn_repo_url|grep $version` ];
        branch= $version |sed -e 's/\.[0-9]\+$//'`
        archive_file="wordpress-$version.tar.gz"
        md5_file="wordpress-$version.md5"
 
        wget "http://wordpress.org/$md5_file"
        wget "http://wordpress.org/$archive_file"
 
        [ `md5sum $archive_file |cut -f 1 -d ' '` != `cat $md5_file` ];
            "MD5 sum did not match!" >&2
            1
       
 
        tar --extract --ungzip --transform "s/^wordpress/$version/" --file $archive_file
        svn_load_dirs.pl $svn_repo_url -t $version current $version
   
 -
svn merge "$svn_repo_url$last_version" "$svn_repo_url$new_version" .

I’m actually planning to make both scripts a little bit more generic (in the sense that svn_repo_url becomes an external param) and to track future changes to them using GitHub’s Gist. (How ironic is that, tracking an script for Subversion using Git?)

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑