Compare permissions script

7 Comments

Recently I needed to compare some permissions between two directories, I wrote this script that could be useful for someone else:

#!/bin/bash
# This script will go through a list of files and directories and match their
# permissions against another directory, it can also copy the permissions from
# the first directory.
#
# Written by Pablo Fernandez
#

function showusage()
{
        echo "USAGE: $0 OPTS DIR1 DIR2"
        echo
        echo "OPTIONS:"
        echo "-a Apply changes (update permissions of DIR2"
        echo "-w Warning on missing files"
        echo "-q Quiet mode"
        echo "-h Show this help"
        echo "The directory DIR1 will be matched against DIR2. The directory DIR2 will"
        echo "be corrected with all permission differences."
}

apply_changes=""

while [ ! -z "$1" ]; do
        case "$1" in
                -a)
                        apply_changes=1
                        ;;
                -w)
                        warn_on_missing=1
                        ;;
                -q)
                        quiet=1
                        ;;
                -h)
                        showusage
                        exit 0
                        ;;
                *)
                        if [ -z "$orig" ]; then
                                orig=$1
                        elif [ -z "$targ" ]; then
                                targ=$1
                        else
                                echo "Unknown flag $1"
                                showusage
                                exit 1
                        fi
        esac
        shift
done

if [ -z "$orig" -o -z "$targ" ]; then
        showusage
        exit 1
fi

# Change into the directory and get a list of files and dirs
pushd . >/dev/null
cd $orig
list=`find .`
popd >/dev/null

# Go through the list
for i in $list; do
        # Get the permissions of the orig file and targ file
        p=`stat -c %a $orig/$i`
        p1=`stat -c %a $targ/$i 2>/dev/null`

        [ "$quiet" = "" ] && echo -n "$i: "

        if [ "$p1" = "" ]; then
                # No permissions for targ file, targ file doesn't exist
                [ "$quiet" = "" ] && echo "not present"

                if [ "$warn_on_missing" != "" -a "$quiet" != "" ]; then
                        echo "$targ/$i not present"
                fi
        else
                # Permission for targ file, compare
                if [ "$p" != "$p1" ]; then
                        # Permissions are different going to try to set permissions
                        if [ "$apply_changes" != "" ]; then
                                # Set permissions
                                e=`chmod $p $targ/$i 2>&1 >/dev/null`

                                if [ "$?" != "0" ]; then
                                        [ "$quiet" = "" ] && echo "different permission, change to $p failed, $e"
                                        [ "$quiet" != "" ] && echo "$e"
                                else
                                        [ "$quiet" = "" ] && echo "set to $p"
                                fi
                        else
                                # Running just for report
                                [ "$quiet" = "" ] && echo "different, orig is $p targ is $p1"
                                [ "$quiet" != "" ] && echo "Permission of $targ/$i is different than $orig/$i"
                        fi
                else
                        [ "$quiet" = "" ] && echo "Ok"
                fi
        fi
done

Naming Convention

5 Comments

If we were today to rethink the naming convention we use for people (first name, middle name, last name), would we approach it the same way? Would we use a hierarchy to represent people as in john.smith.us?

Definitely street names and cities should be using a more logical naming convention like /America/US/EastCoast/NewYork/Manhattan/5th/472/4.

But of course this is just scratching the surface.

I’m not advocating for a change of this naming convention, I’m just wondering what would naming would look like if we came up with a new convention.

acts_as_authentic nightmare

23 Comments

So I decided to do a few tests on the Server Protectors’ website and noticed a few annoyances with the register form, I decided to delve in and fix it, just a couple of extra validations, not too much.

Half an hour later I was pretty much ready to do some open heart surgery on authlogic, man is the configuration of act_as_authentic confusing! And of course, RTFMing doesn’t work, there is not a single example of how changing the default act_as_authentic configuration works!

Searching around I found a few persons with the same problem and no solutions, so I thought I should share how I did it, or rather, what I did.

This is the resulting code:

acts_as_authentic do |c|
 c.validates_uniqueness_of_email_field_options = {:if => "false"}
 c.validates_length_of_login_field_options = {:if => "false", :minimum => 4}
 c.validates_format_of_login_field_options = {:if => "false", :with => Authlogic::Regex.login}
 c.validates_length_of_email_field_options = {:if => "false", :minimum => 4}
 c.validates_confirmation_of_password_field_options = {:if => "false"}
 c.validates_length_of_password_confirmation_field_options = {:if => "false", :minimum => 4 }
end

So as you can see a couple of options are a bit lame, like having a minimum when the if is being set to false, well, if you remove the minumum validates_length_of will complain (it makes sense from validates_length_of point of view, after all, if you are never going to be using the validation why call the function at all?)

I hope this helps and saves some time.

XBMC issues with smb

3 Comments

I’ve been having issues with XBMC playing files served through samba, I don’t recall when this started, but for sometime I couldn’t even browse the collection of files in my own server. Nothing changed, well, I did upgrade Ubuntu to 10.04 on my server, but I think this was happening before that.

Anyway, I browse the internet and didn’t find anything related to this error or how to fix it.

After looking around in the configuration I’ve found something which caught my attention and I got it working.

The error I was getting was:

23:09:42 T:3077850992 M:1831804928   ERROR: SMBDirectory->GetDirectory: Unable to open directory : 'smb://'
unix_err:'2' error : 'No such file or directory'
23:09:42 T:3077850992 M:1831804928   ERROR: GetDirectory - Error getting smb://

And what I had to do is remove the XML path in $HOME/.xbmc/userdata/guisettings.xml that started with the tag <smb>. Removed that, restart XBMC and things started to work again.

Autoreload

1 Comment

I was working today on a website and looking for a way to use my dual head setup to speed things up I decided to write a quick script to reload a webpage every few seconds. I ended up having a neat HTML and Javascript code that I uploaded to http://www.littleq.net/reload.html. I know, there are Firefox extensions that do that, but I didn’t want to reload my Firefox to install that (yes, I know there’s a Firefox extension that allows you to install addons without reloading, but I didn’t have that installed).

Media Center revisited

178 Comments

I recently wrote a post about my new media center, running off my laptop, well, while that setup was sweet and all, there was some sort of hole in it, that is, my laptop went belly up…

That was quite unfortunate, but it gave me the possibility to play with some new stuff, namely ITX setups.

More

The value of *selectively* listening

11 Comments

I have recently come across this eye opening post. I mean, it probably was eye opening back when it was written in 1995, heck, I bet most Newsweek readers back then yield something like “I knew it, that Internet thing is bullcrap!”.

This article, astonishingly titled Why the internet will fail, runs down through the many reasons why Internet would be something we would all get over soon really quickly, like we did with Tamagotchis (thankfully).

Now, this is not your run of the mill ignorant news reporter who talks about things s/he doesn’t understand, this was written by Clifford Stoll, an astronomer and technology writer, working out of the Lawrence Berkeley National Laboratory. Yet, he can be quoted saying

Yet Nicholas Negroponte, director of the MIT Media Lab, predicts that we’ll soon buy books and newspapers straight over the Intenet. Uh, sure.

This author was an authority, someone that we could think that knows much more than we do, so if we disagree with his view we might want to review our opinion.

And this is something that I have seen over and over again, the number of specialists, analysts, etcists, that express an opinion on their field and its completely wrong, completely off base. Of course, we are all humans, we tend to make mistakes, so don’t take this as being judgmental, I’m just saying, we should listen, but we should selectively listen and always make up our own mind and not act on other’s opinions but our own.

The value of a picture

2 Comments

Yosemite

June 3rd, 2009 — Pablo in Yosemite

Looking at this picture makes me remember the endless horizon, the way things can be put in perspective, how unimportant and trivial things can be, how everything is in balance, since there is no out of balance in real life. Sight unseen, makes me yawn in the presence of rush.

This picture surrounds me.

The value of idle time

3 Comments

I have recently read a quote attributed to Einstein, it reads something along the lines of “the best ideas I have I have them while I shave”. This got me thinking, how much idle time do I have on any given month? More

XBMC

4 Comments

We have recently bought a couch for my place and so we decided to spin off our multi purpose monitor to a new media set, we don’t watch much television, but we do enjoy movies and series, so I bought a new LCD screen and had a small piece of furniture custom made to serve as a TV stand.

I used my old laptop, a Toshiba 15″ Dual Core 2Ghz 2.5 G to serve the media, I have to say, I installed the latest available Ubuntu (9.10) and tested a few media centers. After much playing around I sticked to XBMC, its a great media center, originally designed for X-box, that allows you to manage all of your music, videos, pictures, etc. You can even check the weather and watch youtube right from your media center!

Recommended addons: A remote control (a physical one, you can pick those up for a few bucks at ebay), a remote control for your iPhone, there’s a $3 app “XBMC Remote” that’s great, you can see the synopsis of movies right in your iphone :)

Older Entries