Menu

[efa3d9]: / scripts / vivym  Maximize  Restore  History

Download this file

69 lines (57 with data), 1.3 kB

#!/usr/bin/bash

OLD=`pwd`

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for MAP in $*; do
    # Convert rel to abs path
    case $MAP in 
	    /*)  ;;
	    *) MAP=$PWD/$MAP  ;;
    esac
    #echo MAP1=$MAP
    # Create directory
    DIR=`mktemp -d /tmp/vivym.XXXXXX`
    unzip $MAP -d $DIR
    FILE=${MAP##*/}
    EXT=${FILE#*.}
    BASE=${FILE%%.*}

    if ! [ -e $DIR/$BASE.xml ] ; then 
        # echo "Map is renamed, setting BASE=$BASE"
        BASE=$(ls -1 $DIR/*.xml)
        BASE=${BASE##*/}
        BASE=${BASE%%.*}
    fi
    
    #echo MAP=$MAP
    #echo FILE=$FILE
    #echo BASE=$BASE
    #echo EXT=$EXT

    # Count images
    IMGCOUNT=$(ls $DIR/images |wc -l)
    SLIDECOUNT=$(grep "<slide" $DIR/$BASE.xml | wc -l)
    #echo "Found $IMGCOUNT images." 
    #echo "Found $SLIDECOUNT slides."
    #read

    # Create backup for comparison after edit
    BAK=$DIR/$BASE.xml.bak
    cp $DIR/$BASE.xml $BAK

    # Edit
    if [ -z "$EDITOR" ] ; then
        echo "\$EDITOR is not set"
    else
        $EDITOR $DIR/$BASE.xml
    fi

    # Compare
    if cmp $DIR/$BASE.xml $DIR/$BASE.xml.bak  &> /dev/null ; then 
	echo "Map not changed." 
    else  
	# Missing: Zip again
        echo Removing Backup: $BAK
	rm $BAK
	cd $DIR
	zip -r $MAP .

    fi

    #Clean up
    cd $OLD
    rm -rf $DIR
done

IFS=$SAVEIFS
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.