]> git.sven.stormbind.net Git - sven/vym.git/blob - scripts/vivym
Replace Pierre as the maintainer
[sven/vym.git] / scripts / vivym
1 #!/bin/bash
2
3 OLD=`pwd`
4
5 SAVEIFS=$IFS
6 IFS=$(echo -en "\n\b")
7
8 for MAP in $*; do
9     # Convert rel to abs path
10     case $MAP in 
11             /*)  ;;
12             *) MAP=$PWD/$MAP  ;;
13     esac
14     #echo MAP1=$MAP
15     # Create directory
16     DIR=`mktemp -d /tmp/vivym.XXXXXX`
17     unzip $MAP -d $DIR
18     FILE=${MAP##*/}
19     EXT=${FILE#*.}
20     BASE=${FILE%%.*}
21
22     if ! [ -e $DIR/$BASE.xml ] ; then 
23         # echo "Map is renamed, setting BASE=$BASE"
24         BASE=$(ls -1 $DIR/*.xml)
25         BASE=${BASE##*/}
26         BASE=${BASE%%.*}
27     fi
28     
29     #echo MAP=$MAP
30     #echo FILE=$FILE
31     #echo BASE=$BASE
32     #echo EXT=$EXT
33
34     # Count images
35     IMGCOUNT=$(ls $DIR/images |wc -l)
36     SLIDECOUNT=$(grep "<slide" $DIR/$BASE.xml | wc -l)
37     #echo "Found $IMGCOUNT images." 
38     #echo "Found $SLIDECOUNT slides."
39     #read
40
41     # Create backup for comparison after edit
42     BAK=$DIR/$BASE.xml.bak
43     cp $DIR/$BASE.xml $BAK
44
45     # Edit
46     $EDITOR $DIR/$BASE.xml
47
48     # Compare
49     if cmp $DIR/$BASE.xml $DIR/$BASE.xml.bak  &> /dev/null ; then 
50         echo "Map not changed." 
51     else  
52         # Missing: Zip again
53         #rm $BAK
54         cd $DIR
55         zip -r $MAP .
56
57     fi
58
59     #Clean up
60     cd $OLD
61     rm -rf $DIR
62 done
63
64 IFS=$SAVEIFS