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