makeInstallImage.sh.in 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #!/bin/sh
  2. #
  3. # The contents of this file are subject to the Initial
  4. # Developer's Public License Version 1.0 (the "License");
  5. # you may not use this file except in compliance with the
  6. # License. You may obtain a copy of the License at
  7. # http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
  8. #
  9. # Software distributed under the License is distributed AS IS,
  10. # WITHOUT WARRANTY OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing rights
  12. # and limitations under the License.
  13. #
  14. # The Original Code was created by Mark O'Donohue
  15. # for the Firebird Open Source RDBMS project.
  16. #
  17. # Copyright (c) Mark O'Donohue <[email protected]>
  18. # and all contributors signed below.
  19. #
  20. # All Rights Reserved.
  21. # Contributor(s): ______________________________________.
  22. # Alex Peshkoff
  23. #
  24. fb_install_prefix=@prefix@
  25. # Script to copy install files from the build/transport area
  26. # This script builds an image of the installed system into
  27. # the gen/buildroot directory.
  28. # Making an assumption that this program is being run in the gen directory
  29. BuildRootDir=..
  30. BuiltFBDir=Release/firebird # Where the just build fb exists.
  31. TargetDir=buildroot # Where we want to build the install image
  32. SecurityDatabase=security4.fdb
  33. TomMathBuild="@TOMMATH_BUILD@"
  34. TomCryptBuild="@TOMCRYPT_BUILD@"
  35. #------------------------------------------------------------------------
  36. # addLibs
  37. # Add required libraries in the beginning of script.
  38. # Place it to target directory.
  39. addLibs() {
  40. libSdir=$1
  41. libScript=$2
  42. libTdir=$3
  43. libTarget=$libTdir/$libScript
  44. rm -f $libTarget
  45. touch $libTarget
  46. echo "#!/bin/sh" >>$libTarget
  47. echo >>$libTarget
  48. LIB=`objdump -p $libSdir/firebird|grep NEEDED|grep tomcrypt|awk '{print $2;}'`
  49. [ "$LIB" ] && echo "export LIBTOMCRYPT=$LIB" >>$libTarget
  50. LIB=`objdump -p $libSdir/isql|grep NEEDED|egrep "(curses|termcap|tinfo)"|awk '{print $2;}'`
  51. [ "$LIB" ] && echo "export LIBCURSES=$LIB" >>$libTarget
  52. echo >>$libTarget
  53. for i in posixLibrary.sh linuxLibrary.sh
  54. do
  55. echo "# $i" >>$libTarget
  56. cat $libSdir/$i >>$libTarget
  57. echo "" >>$libTarget # avoid missing linefeed
  58. done
  59. cat $libSdir/$libScript >>$libTarget
  60. }
  61. #------------------------------------------------------------------------
  62. # copyIfExists
  63. # Copy file if it exists
  64. #
  65. copyIfExists() {
  66. Files=""
  67. while [ ${#} -gt 1 ]; do
  68. Files="$Files ${1}"
  69. shift
  70. done
  71. NewDir=${1}
  72. for OldFile in $Files; do
  73. if [ -f $OldFile ]; then
  74. cp -df $OldFile $NewDir
  75. fi
  76. done
  77. }
  78. #------------------------------------------------------------------------
  79. # linkFiles
  80. # This function creates soft links
  81. linkFiles() {
  82. From=$1
  83. Files=$2
  84. To=$3
  85. Check=$4
  86. if [ "$To" = "$Check" ]; then
  87. return 0
  88. fi
  89. for file in $Files; do
  90. ln -s $From/$file $To/$file
  91. done
  92. }
  93. #------------------------------------------------------------------------
  94. # makeDirs
  95. # Make paths, passed as a list in 1st arg
  96. makeDirs() {
  97. Dirs=$1
  98. for d in $Dirs; do
  99. Dir=${TargetDir}${d}
  100. mkdir -p $Dir
  101. chmod 0755 $Dir
  102. done
  103. }
  104. #------------------------------------------------------------------------
  105. # ReadOnlyTree
  106. # Set correct rights to files in given subtree
  107. ReadOnlyTree() {
  108. Tree=$1
  109. for i in `find ${Tree} -type d -print`
  110. do
  111. chmod 0755 $i
  112. done
  113. for i in `find ${Tree} -type f -print`
  114. do
  115. chmod 0644 $i
  116. done
  117. }
  118. #------------------------------------------------------------------------
  119. # copyFiles
  120. # This function copies all the files for a distribution into a
  121. # directory heirachy mirroring the installation.
  122. copyFiles() {
  123. # The guts of the tranfer of files and other directories
  124. #cleanup
  125. if [ -d $TargetDir ]
  126. then
  127. chmod -R +xw $TargetDir
  128. rm -fr $TargetDir
  129. fi
  130. #directories
  131. makeDirs "@FB_BINDIR@ @FB_SBINDIR@ @FB_CONFDIR@ @FB_LIBDIR@ @FB_INCDIR@/firebird @FB_DOCDIR@/sql.extensions \
  132. @FB_SAMPLEDIR@ @FB_SAMPLEDBDIR@ @FB_HELPDIR@ @FB_INTLDIR@ @FB_MISCDIR@ @FB_SECDBDIR@ @FB_MSGDIR@ @FB_LOGDIR@ \
  133. @FB_GUARDDIR@ @FB_PLUGDIR@ @FB_TZDATADIR@"
  134. for i in udf; do
  135. makeDirs @FB_MISCDIR@/upgrade/$i
  136. done
  137. makeDirs /usr/include
  138. #bin
  139. cp $BuiltFBDir/bin/gbak ${TargetDir}@FB_BINDIR@/gbak
  140. cp $BuiltFBDir/bin/gfix ${TargetDir}@FB_BINDIR@/gfix
  141. cp $BuiltFBDir/bin/gpre ${TargetDir}@FB_BINDIR@/gpre
  142. cp $BuiltFBDir/bin/gsec ${TargetDir}@FB_BINDIR@/gsec
  143. cp $BuiltFBDir/bin/nbackup ${TargetDir}@FB_BINDIR@/nbackup
  144. copyIfExists $BuiltFBDir/bin/gsplit ${TargetDir}@FB_BINDIR@
  145. cp $BuiltFBDir/bin/gstat ${TargetDir}@FB_BINDIR@/gstat
  146. copyIfExists $BuiltFBDir/bin/fbsvcmgr ${TargetDir}@FB_BINDIR@
  147. copyIfExists $BuiltFBDir/bin/fbtracemgr ${TargetDir}@FB_BINDIR@
  148. cp $BuiltFBDir/bin/isql ${TargetDir}@FB_BINDIR@/isql
  149. cp $BuiltFBDir/bin/qli ${TargetDir}@FB_BINDIR@/qli
  150. chmod 0755 ${TargetDir}@FB_BINDIR@/*
  151. #sbin
  152. cp -f $BuiltFBDir/bin/firebird ${TargetDir}@FB_SBINDIR@/firebird
  153. cp -f $BuiltFBDir/bin/fbguard ${TargetDir}@FB_SBINDIR@
  154. copyIfExists $BuiltFBDir/bin/fb_lock_print ${TargetDir}@FB_SBINDIR@
  155. addLibs $BuiltFBDir/bin changeServerMode.sh ${TargetDir}@FB_SBINDIR@
  156. cp $BuiltFBDir/bin/registerDatabase.sh ${TargetDir}@FB_SBINDIR@
  157. cp $BuiltFBDir/bin/fb_config ${TargetDir}@FB_SBINDIR@
  158. addLibs $BuiltFBDir/bin FirebirdUninstall.sh ${TargetDir}@FB_SBINDIR@
  159. chmod 0755 ${TargetDir}@FB_SBINDIR@/*
  160. chmod 0700 ${TargetDir}@FB_SBINDIR@/*.sh
  161. #install script
  162. addLibs $BuiltFBDir/bin install.sh $BuildRootDir/gen/install
  163. #examples - copy only if we have them
  164. exampleFiles=`find $BuiltFBDir/examples/README -type f -print`
  165. if [ -z "$exampleFiles" ]; then
  166. echo "Example files have not been built!"
  167. else
  168. (cd $BuiltFBDir/examples; tar cf - .) | (cd ${TargetDir}@FB_SAMPLEDIR@; tar xf -)
  169. rm -rf ${TargetDir}@FB_SAMPLEDIR@/empbuild
  170. makeDirs @FB_SAMPLEDBDIR@
  171. cp $BuiltFBDir/examples/empbuild/*.fdb ${TargetDir}@FB_SAMPLEDBDIR@
  172. ReadOnlyTree ${TargetDir}@FB_SAMPLEDIR@
  173. chmod 0664 ${TargetDir}@FB_SAMPLEDBDIR@/*.fdb
  174. #plugins samples
  175. makeDirs ${TargetDir}@FB_SAMPLEDIR@/prebuilt
  176. cp $BuiltFBDir/plugins/*fbSample* ${TargetDir}@FB_SAMPLEDIR@/prebuilt/plugins
  177. cp $BuiltFBDir/bin/*fbSample* ${TargetDir}@FB_SAMPLEDIR@/prebuilt/bin
  178. chmod 0644 ${TargetDir}@FB_SAMPLEDIR@/prebuilt/plugins/*
  179. # exec bit for sample binaries
  180. chmod 0755 ${TargetDir}@FB_SAMPLEDIR@/prebuilt/bin/*
  181. fi
  182. #QLI help
  183. copyIfExists $BuiltFBDir/help/help.gbak ${TargetDir}@FB_HELPDIR@
  184. cp $BuiltFBDir/help/help.fdb ${TargetDir}@FB_HELPDIR@
  185. chmod 0444 ${TargetDir}@FB_HELPDIR@/*.fdb
  186. #message file
  187. cp $BuiltFBDir/*.msg ${TargetDir}@FB_MSGDIR@
  188. chmod 0444 ${TargetDir}@FB_MSGDIR@/*.msg
  189. #secureDB (access rights will be set at install time)
  190. cp $BuiltFBDir/$SecurityDatabase ${TargetDir}@FB_SECDBDIR@
  191. #include (.h .pas files)
  192. cp $BuiltFBDir/include/*.h ${TargetDir}@FB_INCDIR@
  193. cp $BuildRootDir/src/include/firebird/*.h ${TargetDir}@FB_INCDIR@/firebird
  194. tar -C $BuildRootDir/src/include/firebird -cf - impl | tar -C ${TargetDir}@FB_INCDIR@/firebird -x
  195. cp $BuildRootDir/src/include/gen/Firebird.pas ${TargetDir}@FB_INCDIR@/firebird
  196. ReadOnlyTree ${TargetDir}@FB_INCDIR@
  197. #lib
  198. cp -df $BuiltFBDir/lib/libfbclient.so* ${TargetDir}@FB_LIBDIR@
  199. cp -f $BuiltFBDir/lib/libib_util.so ${TargetDir}@FB_LIBDIR@/libib_util.so
  200. if [ "$TomMathBuild" = "Y" ]; then
  201. makeDirs @FB_LIBDIR@/.tm
  202. cp -df $BuildRootDir/extern/libtommath/.libs/libtommath.so* ${TargetDir}@FB_LIBDIR@/.tm
  203. fi
  204. if [ "$TomCryptBuild" = "Y" ]; then
  205. makeDirs @FB_LIBDIR@/.tm
  206. cp -df $BuildRootDir/extern/libtomcrypt/.libs/libtomcrypt.so* ${TargetDir}@FB_LIBDIR@/.tm
  207. fi
  208. chmod 0755 ${TargetDir}@FB_LIBDIR@/*.so*
  209. #plugins
  210. (cd $BuiltFBDir/plugins;tar cf - --exclude='*fbSample*' .) | (cd ${TargetDir}@FB_PLUGDIR@; tar xvf -)
  211. for file in `find ${TargetDir}@FB_PLUGDIR@ -name '*.so*' -print`; do
  212. chmod 0755 ${file}
  213. done
  214. makeDirs ${TargetDir}@FB_TZDATADIR@
  215. cp $BuiltFBDir/tzdata/*.res ${TargetDir}@FB_TZDATADIR@
  216. chmod 0444 ${TargetDir}@FB_TZDATADIR@/*.res
  217. #intl
  218. cp $BuiltFBDir/intl/libfbintl.so ${TargetDir}@FB_INTLDIR@/fbintl
  219. cp $BuiltFBDir/intl/fbintl.conf ${TargetDir}@FB_INTLDIR@
  220. chmod 0755 ${TargetDir}@FB_INTLDIR@/fbintl
  221. chmod 0644 ${TargetDir}@FB_INTLDIR@/fbintl.conf
  222. # Note that the following items copy files from outside the build tree.
  223. # Copy the sql-declarations into the UDF-directory
  224. #doc
  225. cp $BuildRootDir/doc/*.pdf ${TargetDir}@FB_DOCDIR@
  226. cp $BuildRootDir/doc/README.* ${TargetDir}@FB_DOCDIR@
  227. cp $BuildRootDir/doc/sql.extensions/README* ${TargetDir}@FB_DOCDIR@/sql.extensions
  228. cp $BuildRootDir/*.md ${TargetDir}@FB_CONFDIR@
  229. for i in `find ${TargetDir}@FB_MISCDIR@ -print`; do
  230. if [ -d $i ]; then
  231. chmod 0755 $i
  232. else
  233. chmod 0644 $i
  234. fi
  235. done
  236. #misc
  237. cp $BuildRootDir/src/misc/intl.sql ${TargetDir}@FB_MISCDIR@
  238. cp $BuildRootDir/src/misc/upgrade/v4.0/udf_replace* ${TargetDir}@FB_MISCDIR@/upgrade/udf
  239. cp $BuildRootDir/gen/install/misc/firebird.init.d.* ${TargetDir}@FB_MISCDIR@
  240. cp $BuildRootDir/gen/install/misc/rc.config.firebird ${TargetDir}@FB_MISCDIR@
  241. cp $BuildRootDir/gen/install/misc/firebird.service ${TargetDir}@FB_MISCDIR@
  242. chmod -R go-rwx ${TargetDir}@FB_MISCDIR@
  243. #conf
  244. cp $BuiltFBDir/firebird.conf ${TargetDir}@FB_CONFDIR@
  245. cp $BuiltFBDir/databases.conf ${TargetDir}@FB_CONFDIR@
  246. cp $BuiltFBDir/fbtrace.conf ${TargetDir}@FB_CONFDIR@
  247. cp $BuiltFBDir/plugins.conf ${TargetDir}@FB_CONFDIR@
  248. cp $BuiltFBDir/replication.conf ${TargetDir}@FB_CONFDIR@
  249. chmod 0644 ${TargetDir}@FB_CONFDIR@/*.conf
  250. #license
  251. cp $BuildRootDir/builds/install/misc/*License.txt ${TargetDir}@FB_CONFDIR@
  252. chmod 0444 ${TargetDir}@FB_CONFDIR@/*License.txt
  253. # link include files to /usr/include
  254. linkFiles "@FB_INCDIR@" "firebird iberror.h ibase.h ib_util.h" "${TargetDir}/usr/include" "${TargetDir}@FB_INCDIR@"
  255. }
  256. #=== MAIN ====================================================================
  257. copyFiles