Rev Author Line No. Line
542 miho 1 #!/bin/sh
2 #
3 # This script takes source files of amforth and call php script which
4 # creates HTML pages. The script may be run by hand on regulerly fox
5 # example once an hour or day.
6 #
7 # (c) miho 2007 / www.mlab.cz
8  
9 # Configuration
10 # =============
11 # WorkingDir - existing directory with rw access
12 # SvnPath - path ro subversion server with source files
1918 root 13 # SvnInfoFileName - name of file to put info about version in
542 miho 14 # WebForthInPath - name of directory with HTML templates and scripts
15 # WebForthOutPath - name of directory to put HTML pages in
16 WorkingDir=/home/miho/amforth
17 SvnPath=https://amforth.svn.sourceforge.net/svnroot/amforth/trunk
1918 root 18 SvnInfoFileName=.svn-info.txt
542 miho 19 WebForthInPath=/var/www/Articles/Forth
20 WebForthOutPath=/var/www/Articles/Forth
21  
22 # Start of script
23 # ===============
24 DateFile=/tmp/amforth.date
25 if [ -f $DateFile ]; then
26 tail -n 400 $DateFile > $DateFile. 2> /dev/nul
27 rm $DateFile 2> /dev/nul
28 mv $DateFile. $DateFile 2> /dev/nul
29 fi
30 date >> $DateFile 2> /dev/nul
31  
32 # Create Log file
33 # ===============
34 if [ ! -d $WorkingDir ]; then
35 echo "--> ERROR: No Workig Directory"
36 exit 1
37 fi
38 cd $WorkingDir
39 if [ ! -d $WorkingDir/Log ]; then
40 mkdir $WorkingDir/Log 2> /dev/nul
41 if (($?)); then
42 echo "--> ERROR: Unable Create Working Directory"
43 exit 1
44 fi
45 fi
46 LogFile=$WorkingDir/Log/amforth.log
47 LogFileGenerate=$WorkingDir/Log/GenerateHTML.log
48 echo "$0" > $LogFile
49 echo "-------------------" >> $LogFile
50  
51 # Remove export directory
52 # =======================
53 echo "Performing: remove export directory" | tee -a $LogFile
54 rm -rf $WorkingDir/source-exported | tee -a $LogFile 2>> $LogFile
55 if (($?)); then
56 echo "--> ERROR: Unable Remove Export Directory" | tee -a $LogFile
57 exit 1
58 fi
59 echo "-------------------" >> $LogFile
60  
61 # svn checkout
62 # ============
63 echo "Performing: svn checkout" | tee $LogFile
64 svn co $SvnPath $WorkingDir/source >> $LogFile 2>> $LogFile
65 if (($?)); then
66 echo "--> ERROR: svn commit" | tee -a $LogFile
67 exit 1
68 fi
69 echo "-------------------" >> $LogFile
70  
71 # svn export
72 # ==========
73 echo "Performing: svn export" | tee -a $LogFile
74 svn export $WorkingDir/source $WorkingDir/source-exported >> $LogFile 2>> $LogFile
75 if (($?)); then
76 echo "--> ERROR: svn export" | tee -a $LogFile
77 exit 1
78 fi
79 echo "-------------------" >> $LogFile
80  
81 # svn info
82 # ========
83 echo "Performing: svn info" | tee -a $LogFile
84 Result=`svn info $WorkingDir/source` 2>> $LogFile
85 echo "$Result" >> $LogFile
86 if (($?)); then
87 echo "--> ERROR: svn export" | tee -a $LogFile
88 exit 1
89 fi
1918 root 90 echo "$Result" > $WorkingDir/source-exported/$SvnInfoFileName
542 miho 91 echo "-------------------" >> $LogFile
92  
93 # Create HTML
94 # ===========
95 echo "Performing: GenerateHTML" | tee -a $LogFile
96 if [ ! -d $WorkingDir/HTML ]; then
97 mkdir $WorkingDir/HTML 2>> $LogFile
98 fi
99 php $WebForthInPath/PHP/GenerateHTML.php \
545 miho 100 EnableApache="0" \
542 miho 101 SourceDir="$WorkingDir/source-exported/" \
102 SourceAsm="amforth.asm" \
1918 root 103 SvnInfoFileName="$SvnInfoFileName" \
542 miho 104 TemplateDir="$WebForthInPath/Templates/" \
1918 root 105 DestinationDir="$WorkingDir/HTML/" \
542 miho 106 > $LogFileGenerate 2>> $LogFile
107 if (($?)); then
108 echo "--> ERROR: GenerateHTML.php" | tee -a $LogFile
109 exit 1
110 fi
111 echo "-------------------" >> $LogFile
112  
113 # Copy result to Web Directory
114 # ============================
115 echo "Performing: copy HTML" | tee -a $LogFile
116 rm -rf $WebForthOutPath/HTML | tee -a $LogFile 2>> $LogFile
117 if (($?)); then
118 echo "--> ERROR: Unable Remove HTML Directory" | tee -a $LogFile
119 exit 1
120 fi
121 if [ ! -d $WebForthOutPath/HTML ] || [ -d $WebForthOutPath ]; then
122 mkdir $WebForthOutPath/HTML | tee -a $LogFile 2>> $LogFile
123 fi
124 cp -r $WorkingDir/HTML/* $WebForthOutPath/HTML | tee -a $LogFile 2>> $LogFile
125 echo "-------------------" >> $LogFile
126 if (($?)); then
127 echo "--> ERROR: Unable Copy HTML Directory" | tee -a $LogFile
128 exit 1
129 fi
130  
131 # Finish
132 # ======
133 echo "O.K."
134 echo "O.K." >> /tmp/amforth.date
135 exit 0