[Home] You are not logged in. You can create an account here or login here

Just my stuff

Automating svn delete and svn add

Patrick asked me on Friday if I could somehow make
svn move file
svn delete file
and
svn add file
somehow transparent to his not-so-computer-savy secretary. He is using svn to centrally store documents and files other people in his company edit and create, so the people can comment on changes, and work on the files while offline.
We thought a bit about it, and this is what came out:

#!/bin/bash
#this depends on inotify-tools
#folder to watch
FOLDER=~/tmp/svn_test/repo
###############################

inotifywait -m --format '%e %w %f' -r $FOLDER -e move -e create -e delete --exclude .svn 2>/dev/null|
while read EVENT
do
  EV=`echo $EVENT|cut -d' ' -f1|cut -d',' -f1`
  FOLDER=`echo $EVENT|cut -d' ' -f2`
  FILE=`echo $EVENT|cut -d' ' -f3`
  echo event $EVENT
  #continue
  if [ "$EV" == "CREATE" ] || [ "$EV" == "MOVED_TO" ]; then
    svn add --force "$FOLDER/$FILE" 
  elif [ "$EV" == "DELETE" ] || [ "$EV" == "MOVED_FROM" ]; then
    svn delete "$FOLDER/$FILE" 
  fi
done

This way, if Ms. Secretary works on files on her working copy of the svn repository, and this script is running, for every file creation, move or delete the corresponding svn command is executed.
This of course works while offline too, so when Ms. Secretary is back in the office, she can just execute the svn update && svn commit command and everything is back in sync.

acpi time wakup in linux

Get a computer to wakup is always a challenge, even if you know what to do. This is how I did it on an Asus M2N-VM DH.
First of all I had to disable wake on timer in the bios. Then I tested
[1]

echo "+00-00-00 00:05:00">/proc/acpi/alarm
poweroff

This shoud wake the computer up after 5 minutes.
If this works you can
[2]
echo "+00-00-00 00:05:00">/proc/acpi/alarm
cat /proc/acpi/alarm

Sometimes there is a difference between your hardware clock and the linux time, so you have to account for this difference when you echo the time to /proc/acpi/alarm.
If [1] does not work, you probably have some code in your init scripts that set the hwclock after you echoed the time to /proc/acpi/alarm. You can test if that is the case with
cat /proc/interrupts |grep rtc
echo "+00-00-00 00:00:10">/proc/acpi/alarm
sleep 11
cat /proc/interrupts |grep rtc

Look at the number: does it increment? If it does, the alarm does fire the interrupt, so your problem are probably the init scripts (that was my case on ubuntu). You have to patch /etc/init.d/hwclock.sh like this:
if [ "$HWCLOCKACCESS" != no ]; then
  # Copies Hardware Clock time to System Clock using the correct
  # timezone for hardware clocks in local time, and sets kernel
  # timezone. DO NOT REMOVE.
  ACPITIME=`cat /proc/acpi/alarm` ########INSERT THIS LINE!!!!
  /sbin/hwclock --hctosys $GMT $HWCLOCKPARS $BADYEAR

  if /sbin/hwclock --show $GMT $HWCLOCKPARS $BADYEAR 2>&1 > /dev/null |
    grep -q '^The Hardware Clock registers contain values that are either invalid'; then
    echo "Invalid system date -- setting to 1/1/2002" 
    /sbin/hwclock --set --date '1/1/2002 00:00:00' $GMT $HWCLOCKPARS $BADYEAR
  fi
  echo "$ACPITIME" > /proc/acpi/alarm ########INSERT THIS LINE!!!!
fi

This re-sets the acpi alarm time after setting the hwclock, so now it should work.

Create a swap file

Need a swap file quick!?

dd if=/dev/zero of=/swapfile1 bs=1024 count=524288
mkswap /swapfile1
swapon /swapfile1

and done.

dnsmasq and wildcard records

If you want dnsmasq to resolve WHATEWER_YOU_PUT_HERE.yourmachine.yourdomain to the same ip (maybe for apache vhosts) just add
address=/.yourmachine.yourdomain/192.168.2.58
to dnsmasq.conf