LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-20-2012, 05:29 AM   #16
pablgonz
LQ Newbie
 
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled

I made some modifications, "-h" now out of case, getopt displays an error and then throws the information on how to use the script.
Eliminate long options (--book, --etc) are not relevant to the task, for now solve the problem of input parameter without "-", "--" except for b, f, l and s.
Code:
#!/bin/bash
# Compile big TeX proyect 2012
# mycomp.sh
# Set work dir (good idea) 
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Help funtion
HELP(){
echo "The big TeX Proyect 2012"
                echo "Uso:sh $0 -b -l -f -s -h"
                echo "	-b|book     : Crea libro con marcas de agua."
                echo "	-l|legal    : Crea las guías en formato legal."	
                echo "	-s|screen   : Crea las presentaciones en pdf."
                echo "	-f|facsimil : Crea los facsímiles en pdf."                
		echo "	-h|help     : Muestra la ayuda y sale."
}
# end help funtion
# If no argument or -h show HELP and exit
# Regexxx
REGEX="[^-[:blank:]bfls]"
if [ $# -lt 1 ]||[ "$*" = '-help' ]||[ "$*" = '-h' ]||[[ "$*" =~ $REGEX ]];then
HELP
exit 0
fi
# Declaring getopt options
if ! options=$(getopt -o blsf -- "$@");then
    # getopt will put out an error message
echo "Uso:sh $0 -b -l -f -s -h"
exit 0
fi
# Take proyect name from input
echo Ingrese el nombre del proyecto
read NAME
if [ -d "$DIR/store/$NAME" ]; then
    echo "Ya existe $NAME intente con otro nombre"
    exit 0
fi
set --$options
# start script options
while [ $# -gt 0 ]; do
# Case for paramet
case $1 in
# Crea el libro desde source
	-b) 
		mkdir -p $DIR/backup/$NAME/book &&
		echo "Creando book $NAME"
		for file in $DIR/source/book/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1 &&
		pdflatex -output-directory=$DIR/backup/$NAME/book/ "$file" >/dev/null 2>&1
	done
		echo "BOOK Done!";;
# Crea las guias en formato 8.5x13 pulgadas
    -l) 
		mkdir -p $DIR/backup/$NAME/legal &&
		echo "Creando Legal $NAME"
		for file in $DIR/source/legal/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/legal/ "$file" >/dev/null 2>&1
	done
		echo "LEGAL Done!";;
# Crea las guias tipo libro plegado 6.5x8.5 in
	-f) 
		mkdir -p $DIR/backup/$NAME/booklet &&
		echo "Creando facsimil $NAME"
           	cp -R $DIR/source/facsimil/ /$DIR/backup/$NAME/ &&
		for file in $DIR/source/booklet/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/facsimil "$file" >/dev/null 2>&1
	done &&
		cd $DIR/backup/$NAME/facsimil &&
		for file in *.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/booklet/ "$file" >/dev/null 2>&1
	done &&
		cd $DIR/
		rm -rf $DIR/backup/$NAME/facsimil/
		echo "FACSIMIL Done!";;
# Crea las presentaciones usando pdfscreen
	-s) 
		mkdir -p $DIR/backup/$NAME/screen &&
		echo "Creando screen $NAME"
        for file in $DIR/source/screen/*.tex 
		do pdflatex -output-directory=$DIR/backup/$NAME/screen/ "$file" >/dev/null 2>&1
	done
		echo "SCREEN Done!";;
# various
	--) shift; break;;
    -*) echo "$0: error - $1" 1>&2; exit 1;;
	 *) break;;
	esac
shift
done
# Clean temp files
find $DIR/backup/$NAME/ -regextype posix-awk -regex "(.*.log|.*.toc|.*.xwm|.*.out|.*.aux)" -exec rm -rf {} \; &&
cd $DIR/backup/ &&
# Create backup folder
tar -c --xz -f $NAME-$(date +%Y%m%d).tar.xz $NAME/ 
echo "El respaldo del proyecto $NAME ha creado con exito!"
# Move proyect to store 
mv $DIR/backup/$NAME/ $DIR/store/
echo "FINISH"
exit 0
It's not perfect, but it works, I would like to fix the regular expression to only accept "-b,-l,-s,-f" and "single space -b, single space -f, etc ..." and who does not accept "-" and "--" without a character preceding it (b,l,s,f). if this is possible in bash? ...
Best for all and many thanks for links and ideas.
Pablo
PD: " --book option you have called pdflatex twice using the exact same information ..." yes necessary for pdftex (table of contents and cross references).

Last edited by pablgonz; 08-21-2012 at 08:37 PM. Reason: correct spelling, change to solved
 
  


Reply

Tags
bash scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help about dd command new options to put in bash script destinytia1 Linux - Newbie 10 03-08-2012 01:54 AM
bash script to rsync remote dir with options uopjohnson Linux - General 3 04-23-2010 01:16 AM
Handling null options in a bash script which ought to have a value dairo Linux - General 2 03-16-2009 12:27 PM
bash script: making options? johngreenwood Programming 4 01-04-2007 01:55 PM
add reload and restart options to the firewall script cccc Debian 2 09-27-2006 04:11 AM


All times are GMT -5. The time now is 07:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration