install.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/bin/bash
  2. #
  3. # OGP - Open Game Panel
  4. # Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  5. #
  6. # http://www.opengamepanel.org/
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. #
  22. # Parameters can be passed into the install.sh script to automate OGP updates
  23. # $1 = Operation Type (Used as opType)
  24. # $2 = OGP User (Used as ogpAgentUser)
  25. # $3 = OGP User Sudo Pass (Used as ogpUserPass)
  26. # $4 = Install Path (Used as ogpInsPath)
  27. # Parameter notifications
  28. if [ ! -z "$1" ]; then
  29. echo -n "Received operation type of $1 as a parameter."
  30. opType="$1"
  31. fi
  32. if [ ! -z "$2" ]; then
  33. echo -n "Received OGP user of $2 as a parameter."
  34. ogpAgentUser="$2"
  35. fi
  36. if [ ! -z "$3" ]; then
  37. echo -n "Received OGP sudo password of $3 as a parameter."
  38. ogpUserPass="$3"
  39. fi
  40. if [ ! -z "$4" ]; then
  41. echo -n "Received OGP agent path of $4 as a parameter."
  42. ogpInsPath="$4"
  43. fi
  44. failed()
  45. {
  46. echo "ERROR: ${1}"
  47. exit 1
  48. }
  49. if [ "X`which screen &> /dev/null;echo $?`" != "X0" ]; then
  50. failed "You need to install software called 'screen', before you can install OGP agent.";
  51. fi
  52. if [ "X`which sed &> /dev/null;echo $?`" != "X0" ]; then
  53. failed "You need to install software called 'sed', before you can install OGP agent.";
  54. fi
  55. echo
  56. clear
  57. echo "#######################################################################"
  58. echo "# OGP Agent installation and configuration"
  59. echo "# This program will:"
  60. echo "# Create ${DEFAULT_AGENT_HOME} or user defined directory"
  61. echo "# Copy ogp_agent files to ${DEFAULT_AGENT_HOME} or user defined dir"
  62. echo "# Copy the ogp_agent init script to /etc/init.d or user defined dir"
  63. echo "# Create an initial configuration file"
  64. echo "# Thank you for using OGP. http://www.opengamepanel.org/"
  65. echo "#######################################################################"
  66. echo
  67. if [ "X`which rsync &> /dev/null;echo $?`" != "X0" ]; then
  68. echo "*** WARNING **** missing rsync client. It is not required, but needed to use the rsync game installer";
  69. fi
  70. if [ "X`whoami`" != "Xroot" ]
  71. then
  72. echo
  73. echo "Detected non-root install..."
  74. username=`whoami`
  75. echo -n "Enter sudo password: ";
  76. read sudo_password;
  77. else
  78. echo "Next you need to type the username of the user that owns the agent homes.";
  79. echo "This user must own (have access to) all the game home directories that you"
  80. echo "want to run with this agent and must to be in sudoers list so it can perform"
  81. echo "administrative tasks.";echo
  82. while [ 1 ]
  83. do
  84. if [ ! -z "$ogpAgentUser" ] ; then
  85. username="$ogpAgentUser"
  86. else
  87. echo -n "Enter user name: ";
  88. read username;
  89. fi
  90. if [ -z "$ogpUserPass" ] ; then
  91. echo -n "Enter user password: ";
  92. read sudo_password;
  93. else
  94. sudo_password="$ogpUserPass"
  95. fi
  96. if [ -z "${username}" ]
  97. then
  98. echo "Username can not be empty.";echo
  99. continue;
  100. fi
  101. if [ "Xroot" == "X${username}" ]
  102. then
  103. echo "'${username}' can not be used as user for agent.";echo
  104. continue;
  105. fi
  106. ID_OF_USER=`id -u ${username} 2> /dev/null`
  107. if [ $? != 0 ]
  108. then
  109. echo "User with entered username (${username}) does not exist.";echo
  110. continue;
  111. fi
  112. break;
  113. done
  114. fi
  115. readonly AGENT_USER_HOME="`cat /etc/passwd | grep "^${username}:" | cut -d':' -f6`/OGP/"
  116. echo
  117. echo "Next the directory for the agent needs to be chosen. The default directory";
  118. echo "Should be fine in most of the cases."
  119. echo
  120. if [ -z "$ogpInsPath" ]; then
  121. echo "Where do you want to install the agent?"
  122. echo -n "[Default is ${AGENT_USER_HOME}]: "
  123. read agent_home
  124. else
  125. agent_home="$ogpInsPath"
  126. fi
  127. if [ -z "${agent_home}" ]
  128. then
  129. agent_home=$AGENT_USER_HOME
  130. fi
  131. # Try to prevent users from doing damage to their systems.
  132. case ${agent_home} in
  133. /bin*|/boot*|/dev*|/etc*|/lib*|/proc*|/root*|/sbin*|/sys*|/)
  134. failed "The agent home can not be ${agent_home}";
  135. ;;
  136. esac
  137. echo "Agent install dir is ${agent_home}"
  138. echo
  139. agent_home=${agent_home%/}
  140. if [ ! -e ${agent_home} ]
  141. then
  142. mkdir -p ${agent_home} || failed "Failed to create the directory (${agent_home}) for agent."
  143. elif [ ! -w ${agent_home} ]
  144. then
  145. failed "You do not have write permissions to the directory you assigned as agent home (${agent_home})."
  146. fi
  147. if [ "X`whoami`" == "Xroot" ];
  148. then
  149. readonly DEFAULT_INIT_DIR="/etc/init.d/"
  150. else
  151. readonly DEFAULT_INIT_DIR="${agent_home}/"
  152. fi
  153. if [ "X`uname`" != "XLinux" ]
  154. then
  155. echo
  156. echo "Detected non-Linux platform..."
  157. echo "Where do you want to put the init scripts?"
  158. echo -n "[Default ${DEFAULT_INIT_DIR}]: "
  159. read init_dir
  160. fi
  161. if [ -z "$opType" ]; then
  162. echo "Where do you want to put the init scripts?"
  163. echo -n "[Default ${DEFAULT_INIT_DIR}]:"
  164. read init_dir
  165. fi
  166. if [ -z "${init_dir}" ]
  167. then
  168. init_dir=${DEFAULT_INIT_DIR}
  169. fi
  170. init_dir=${init_dir%/}
  171. echo "Copying files..."
  172. cp -avf Crypt EHCP FastDownload File Frontier IspConfig KKrcon php-query Schedule Time ogp_agent.pl ogp_screenrc ogp_agent_run agent_conf.sh extPatterns.txt ${agent_home}/ || failed "Failed to copy agent files to ${agent_home}."
  173. # Create the directory for configs.
  174. mkdir -p ${agent_home}/Cfg || failed "Failed to create ${agent_home}/Cfg dir."
  175. echo
  176. if [ -e /etc/gentoo-release ]
  177. then
  178. echo "Copying ogp_agent.init.gentoo to $init_dir - Gentoo Specific Init"
  179. init_file_template='includes/ogp_agent.init.gentoo'
  180. elif [ -e /etc/sysconfig ] && [ ! -e /etc/debian_version ]
  181. then
  182. echo "Copying ogp_agent.init.rh to $init_dir - Redhat Style Init (also SuSE, and Mandrake)"
  183. init_file_template='includes/ogp_agent.init.rh'
  184. elif [ -e /etc/debian_version ]
  185. then
  186. echo "Copying ogp_agent.init.dbn to $init_dir - Debian Style Init"
  187. init_file_template='includes/ogp_agent.init.dbn'
  188. else
  189. echo "Copying the generic init script because I don't know what kind of Linux distro this is"
  190. init_file_template='includes/ogp_agent.init'
  191. fi
  192. init_file=${init_dir}/ogp_agent
  193. cp -f $init_file_template $init_file || failed "Failed to create init file ($init_file)."
  194. # Next we replace the OGP_AGENT_DIR with the actual dir in init file.
  195. sed -i "s|OGP_AGENT_DIR|${agent_home}|" ${init_file} || failed "Failed to modify init file ($init_file)."
  196. sed -i "s|OGP_USER|${username}|" ${init_file} || failed "Failed to modify init file ($init_file)."
  197. chmod a+x $init_file
  198. echo;
  199. echo "Changing files owner to user ${username}...";
  200. # Group of the files in agent_home can differ from the user so
  201. # lets leave them as they are. So no chown user:group here.
  202. chown --preserve-root -R ${username} ${agent_home} || failed "Failed to chmod the agent_home ${agent_home} for user ${username}."
  203. echo "Setting Permissions on files in ${agent_home}..."
  204. chmod 750 ${init_dir}/ogp_agent || failed "Failed to chmod ${init_dir}/ogp_agent to 750."
  205. chmod 750 ${agent_home}/ogp_agent.pl || failed "Failed to chmod ${agent_home}/ogp_agent.pl to 750."
  206. chmod 750 ${agent_home}/ogp_agent_run || failed "Failed to chmod ${agent_home}/ogp_agent_run to 750."
  207. echo "Install Successful!"
  208. echo "Now configuring..."
  209. echo ""
  210. # Run the configuration script
  211. chmod +x ${agent_home}/agent_conf.sh
  212. if [ -z "$opType" ]; then
  213. bash ${agent_home}/agent_conf.sh -s $sudo_password
  214. fi
  215. echo;echo
  216. echo "Installation complete!"
  217. echo "Start the agent manually to test it like this:"
  218. echo " cd ${agent_home}"
  219. echo " ./ogp_agent.pl"
  220. echo
  221. echo "If everything looks good, hit <Ctrl C> to kill the agent."
  222. echo "The agent can be started with the init scripst by using following command"
  223. echo " ${init_dir}/ogp_agent start";
  224. echo
  225. exit 0