#!/bin/sh # file: # redo_menu.sh # author: # Marcus Fritzsch # date: # 20040601 # purpose: # replace the menu in HTML-files surrounded by @PAGEMENU-START and @PAGEMENU-END # by the menu contained in menu.txt # usage: # redo_menu.sh filename.html xyz.html ... # uses a file called menu.txt as the menu and inserts it between the lines # @PAGEMENU-START # and # @PAGEMENU-END # that have to be in the html as comments... (see my html code) # and in the menu template (they're wiped when inserting the menu) #NOT_REALLY="ARGH" start='@PAGEMENU-START' ende='@PAGEMENU-END' MENUFILE=menu.txt RND=$RANDOM DIR=/tmp/menu_$RND LOG=/tmp/menu_$RND.log notice () { echo "[+] $*" } error () { echo "[-] $*" } eexit () { echo "[!] $*" exit 1 } redo_menu () { notice "tempfolder is $DIR" mkdir $DIR || eexit "could not mkdir $DIR" test -e $MENUFILE || eexit "could not find menu-file $MENUFILE" for i in $*; do # it was planned to have the link-name directly from the file... well, # i never used it that way... though it is still here :) #file=$(echo $i|cut -d, -f2) #name=$(echo $i|cut -d, -f1) file=$i test -e $file || { error "file $file does not exist"; continue; } menu_begin=$(grep -n $start < $file|cut -d: -f1) test -z $menu_begin && { error "file $file contains no $start, skipping file!"; continue; } menu_end=$(grep -n $start < $file|cut -d: -f1) test -z $menu_end && { error "file $file contains no $start, skipping file!"; continue; } menu_len=$(expr $menu_end - $menu_begin) # write everything before $start to new file grep -B $menu_begin $start < $file|grep -v $start > $DIR/$file #sed -r "s/($start|$ende)/\\1 ($MENUFILE)/g;s#.[^<]+#$name#g" < $MENUFILE >> $DIR/$file sed -r "s/($start|$ende)/\\1 ($MENUFILE)/g" < $MENUFILE >> $DIR/$file # same as above... grep -A 999999 $ende < $file|grep -v $ende >> $DIR/$file # copy new file back... if test -z "$NOT_REALLY"; then cp $DIR/$file $file rm $DIR/$file fi notice "redone menu for $file" done if test -z "$NOT_REALLY"; then notice "cleaning up temp-dir $DIR" rmdir $DIR fi } redo_menu $* 2> $LOG