install.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/env bash
  2. # vim: expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:
  3. # kate: space-indent on; indent-width 2; mixedindent off;
  4. NEEDS="git qmake make g++"
  5. DIR_LIBQWCL="libqwclient"
  6. SRCPATH_QWBOT=$(pwd)
  7. # we certainly hope we are in our repository.
  8. cd ${SRCPATH_QWBOT}/${DIR_LIBQWCL}/
  9. SRCPATH_LIBQWCL=$(pwd)
  10. cd ${SRCPATH_QWBOT}
  11. BIN_QWBOT="cmp_qwbot"
  12. CFG_QWBOT="cmp_qwbot.cfg"
  13. STARTER="start_cmp_qwbot.sh"
  14. INST_LOCATION=""
  15. function usage() {
  16. echo "Installation Script for the QWBOT of the community messaging project."
  17. echo "Usage: ${0} <target-directory>"
  18. exit
  19. }
  20. for p in $NEEDS; do
  21. TEST=$(which $p 2> /dev/null)
  22. if [ ! -f "$TEST" ]; then
  23. echo "Sorry, you don't seem to have '$p' installed."
  24. echo "You need these programs before this script will run: $NEEDS"
  25. exit
  26. fi
  27. done
  28. # on first run, we need a target location for binaries, lets explain usage and check for the argument OR the location file.....
  29. # if we have not found the location file, get location from argument.. and go on
  30. if [ "${INST_LOCATION}" == "" ]; then
  31. if [ "$1" != "" ]; then
  32. INST_LOCATION="${1}"
  33. echo "Using target-directory ${INST_LOCATION}"
  34. echo
  35. mkdir -p "${INST_LOCATION}"
  36. if [ -d "${INST_LOCATION}" ]; then
  37. # worked, we save the binary target location in a small file
  38. echo "INST_LOCATION=\"${INST_LOCATION}\"" > install.location
  39. fi
  40. else
  41. # if we found the location file, get location, go on..
  42. if [ -f "install.location" ]; then
  43. source ./install.location
  44. echo "Read target-directory from file ./install.location - it is: ${INST_LOCATION}"
  45. echo "Delete the file if you want to specify a new target directory."
  46. echo
  47. else
  48. # if no argument given AND there is no location file, then give usage info.
  49. usage
  50. fi
  51. fi
  52. fi
  53. # now, we have a target location... lets go on and pull
  54. # if we are in our git directory then update all
  55. git pull
  56. cd "${SRCPATH_QWBOT}"
  57. git submodule update --init --recursive
  58. # we always make them both...
  59. cd "$SRCPATH_LIBQWCL"
  60. qmake
  61. make clean
  62. make
  63. cd "${SRCPATH_QWBOT}"
  64. qmake
  65. make clean
  66. make
  67. if [ -d "${INST_LOCATION}" ]; then
  68. #copy assets over
  69. echo "Copying qwbot binary and starting script..."
  70. cp "${BIN_QWBOT}" "${INST_LOCATION}"
  71. cp -v "${STARTER}" "${INST_LOCATION}"
  72. echo "Copying qwclient library..."
  73. mkdir -p "${INST_LOCATION}/libqwclient"
  74. cp -vd ${SRCPATH_LIBQWCL}/*.so.* "${INST_LOCATION}/libqwclient/"
  75. # change into that target directory
  76. cd ${INST_LOCATION}
  77. # first start there:
  78. if [ -f "./${BIN_QWBOT}" ]; then
  79. LD_LIBRARY_PATH=${SRCPATH_LIBQWCL} ./${BIN_QWBOT} &
  80. PID=$!
  81. echo PID $PID
  82. sleep 1
  83. kill -9 $PID > /dev/null
  84. else
  85. echo
  86. echo "It seems there have been problems compiling this thing! The binary ./${BIN_QWBOT} is missing."
  87. echo "This is awkward. Probably some dependency was missing or had a wrong version while compilation."
  88. echo "Better go have a chat to the devs at irc://quakenet.org/qwnet"
  89. echo
  90. exit
  91. fi
  92. # cfg file should have been created by the first start of the qwbot.
  93. # now, lets check the starting script. It should be executable.
  94. if [ -f "${STARTER}" ]; then
  95. chmod u+x "${STARTER}"
  96. fi
  97. cd "${INST_LOCATION}"
  98. echo
  99. echo "The installation is now ready to run. BUT..."
  100. echo
  101. echo "1. Please know, that you need maps. The bot will start downloading them often, which takes time."
  102. echo " It is advised, you get some maps already and put them in the appropriate gamedir under"
  103. echo " ${INST_LOCATION}"
  104. echo " gamedir qw example: ${INST_LOCATION}/qw/maps"
  105. echo " gamedir fortress example: ${INST_LOCATION}/fortress/maps"
  106. echo
  107. echo "2. Please edit the ${CFG_QWBOT}"
  108. echo " For an overview of configuration options, please see the wiki at:"
  109. echo " https://gogs.netdome.biz/community-messaging-project/qwbot/wiki/home"
  110. echo
  111. echo "3. Now, it's cool to run:"
  112. echo " cd "${INST_LOCATION}" && ./${STARTER}"
  113. echo
  114. echo "4. If you want to update your bot at a later time, go to ${SRCPATH_QWBOT} and run me (${0}) again."
  115. echo
  116. echo "Have fun."
  117. echo
  118. else
  119. #missing
  120. echo "For some reason I can't create or access the target directory ${INST_LOCATION} ...is it alive?"
  121. exit
  122. fi