database_installer.bat 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. @echo off
  2. REM ##############################################
  3. REM ## L2JDP Database Installer - (by DrLecter) ##
  4. REM ##############################################
  5. REM ## Interactive script setup - (by TanelTM) ##
  6. REM ##############################################
  7. REM Copyright (C) 2010 L2J DataPack
  8. REM This program is free software; you can redistribute it and/or modify
  9. REM it under the terms of the GNU General Public License as published by
  10. REM the Free Software Foundation; either version 3 of the License, or (at
  11. REM your option) any later version.
  12. REM
  13. REM This program is distributed in the hope that it will be useful, but
  14. REM WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. REM or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. REM for more details.
  17. REM
  18. REM You should have received a copy of the GNU General Public License along
  19. REM with this program; if not, write to the Free Software Foundation, Inc.,
  20. REM 675 Mass Ave, Cambridge, MA 02139, USA. Or contact the Official L2J
  21. REM DataPack Project at http://www.l2jdp.com, http://www.l2jdp.com/forum or
  22. REM #l2j @ irc://irc.freenode.net
  23. set config_file=vars.txt
  24. set config_version=0
  25. set workdir="%cd%"
  26. set full=0
  27. set stage=0
  28. set logging=0
  29. set upgrade_mode=0
  30. set backup=.
  31. set logdir=.
  32. set safe_mode=1
  33. set cmode=c
  34. set fresh_setup=0
  35. :loadconfig
  36. title L2JDP Installer - Reading Configuration from File...
  37. cls
  38. if not exist %config_file% goto configure
  39. ren %config_file% vars.bat
  40. call vars.bat
  41. ren vars.bat %config_file%
  42. call :colors 17
  43. if /i %config_version% == 2 goto ls_section
  44. set upgrade_mode=2
  45. echo It seems to be the first time you run this version of
  46. echo database_installer but I found a settings file already.
  47. echo I'll hopefully ask this questions just once.
  48. echo.
  49. echo Configuration upgrade options:
  50. echo.
  51. echo (1) Import and continue: I'll read your old settings and
  52. echo continue execution, but since no new settings will be
  53. echo saved, you'll see this menu again next time.
  54. echo.
  55. echo (2) Import and configure: This tool has some new available
  56. echo options, you choose the values that fit your needs
  57. echo using former settings as a base.
  58. echo.
  59. echo (3) Ignose stored settings: I'll let you configure me
  60. echo with a fresh set of default values as a base.
  61. echo.
  62. echo (4) View saved settings: See the contents of the config
  63. echo file.
  64. echo.
  65. echo (5) Quit: Did you came here by mistake?
  66. echo.
  67. set /P upgrade_mode="Type a number, press Enter (default is '%upgrade_mode%'): "
  68. if %upgrade_mode%==1 goto ls_section
  69. if %upgrade_mode%==2 goto configure
  70. if %upgrade_mode%==3 goto configure
  71. if %upgrade_mode%==4 (cls&type %config_file%&pause&goto loadconfig)
  72. if %upgrade_mode%==5 goto :eof
  73. goto loadconfig
  74. :colors
  75. if /i "%cmode%"=="n" (
  76. if not "%1"=="17" ( color F ) else ( color )
  77. ) else ( color %1 )
  78. goto :eof
  79. :configure
  80. call :colors 17
  81. title L2JDP Installer - Setup
  82. cls
  83. set config_version=2
  84. if NOT %upgrade_mode% == 2 (
  85. set fresh_setup=1
  86. set mysqlBinPath=%ProgramFiles%\MySQL\MySQL Server 5.5\bin
  87. set lsuser=root
  88. set lspass=
  89. set lsdb=l2jdb
  90. set lshost=localhost
  91. set cbuser=root
  92. set cbpass=
  93. set cbdb=l2jcb
  94. set cbhost=localhost
  95. set gsuser=root
  96. set gspass=
  97. set gsdb=l2jdb
  98. set gshost=localhost
  99. set cmode=c
  100. set backup=.
  101. set logdir=.
  102. )
  103. set mysqlPath=%mysqlBinPath%\mysql.exe
  104. echo New settings will be created for this tool to run in
  105. echo your computer, so I need to ask you some questions.
  106. echo.
  107. echo 1-MySql Binaries
  108. echo --------------------
  109. echo In order to perform my tasks, I need the path for commands
  110. echo such as 'mysql' and 'mysqldump'. Both executables are
  111. echo usually stored in the same place.
  112. echo.
  113. if "%mysqlBinPath%" == "" (
  114. set mysqlBinPath=use path
  115. echo I can't determine if the binaries are available with your
  116. echo default settings.
  117. ) else (
  118. echo I can try to find out if the current setting actually works...
  119. echo.
  120. echo %mysqlPath%
  121. )
  122. if not "%mysqlBinPath%" == "use path" call :binaryfind
  123. echo.
  124. path|find "MySQL">NUL
  125. if %errorlevel% == 0 (
  126. echo I found MySQL is in your PATH, this will be used by default.
  127. echo If you want to use something different, change 'use path' for
  128. echo something else.
  129. set mysqlBinPath=use path
  130. ) else (
  131. echo Look, I can't find "MYSQL" in your PATH environment variable.
  132. echo It would be good if you go and find out where "mysql.exe" and
  133. echo "mysqldump.exe" are.
  134. echo.
  135. echo If you have no idea about the meaning of words such as MYSQL
  136. echo or PATH, you'd better close this window, and consider googling
  137. echo and reading about it. Setup and host an L2J server requires a
  138. echo minimum of technical skills.
  139. )
  140. echo.
  141. echo Write the path to your MySQL binaries (no trailing slash needed):
  142. set /P mysqlBinPath="(default %mysqlBinPath%): "
  143. cls
  144. echo.
  145. echo 2-LoginServer settings
  146. echo --------------------
  147. echo I will connect to the MySQL server you specify, and setup a
  148. echo Loginserver database there, most people use a single MySQL
  149. echo server and database for both Login and Gameserver tables.
  150. echo.
  151. set /P lsuser="MySQL Username (default is '%lsuser%'): "
  152. set /P lspass="Password (will be shown as you type, default '%lspass%'): "
  153. set /P lsdb="Database (default is '%lsdb%'): "
  154. set /P lshost="Host (default is '%lshost%'): "
  155. if NOT "%lsuser%"=="%gsuser%" set gsuser=%lsuser%
  156. if NOT "%lspass%"=="%gspass%" set gspass=%lspass%
  157. if NOT "%lsdb%"=="%gsdb%" set gsdb=%lsdb%
  158. if NOT "%lshost%"=="%gshost%" set gshost=%lshost%
  159. echo.
  160. cls
  161. echo.
  162. echo 3-Community Board Server settings
  163. echo --------------------
  164. echo I will connect to the MySQL server you specify, and setup a
  165. echo Community Board server database there, most people use a single MySQL
  166. echo server for both Login and Gameserver which CBserver can use too,
  167. echo but CBserver requires a different database!
  168. echo.
  169. set /P cbuser="MySQL Username (default is '%cbuser%'): "
  170. set /P cbpass="Password (will be shown as you type, default '%cbpass%'): "
  171. set /P cbdb="Database (default is '%cbdb%'): "
  172. set /P cbhost="Host (default is '%cbhost%'): "
  173. echo.
  174. echo 4-GameServer settings
  175. echo --------------------
  176. set /P gsuser="User (default is '%gsuser%'): "
  177. set /P gspass="Pass (default is '%gspass%'): "
  178. set /P gsdb="Database (default is '%gsdb%'): "
  179. set /P gshost="Host (default is '%gshost%'): "
  180. echo.
  181. echo 5-Misc. settings
  182. echo --------------------
  183. set /P cmode="Color mode (c)olor or (n)on-color, default %cmode% : "
  184. set /P backup="Path for your backups (default '%backup%'): "
  185. set /P logdir="Path for your logs (default '%logdir%'): "
  186. :safe1
  187. set safemode=y
  188. set /P safemode="Debugging messages and increase verbosity a lil bit (y/n, default '%safemode%'): "
  189. if /i %safemode%==y (set safe_mode=1&goto safe2)
  190. if /i %safemode%==n (set safe_mode=0&goto safe2)
  191. goto safe1
  192. :safe2
  193. echo.
  194. if "%mysqlBinPath%" == "use path" (
  195. set mysqlBinPath=
  196. set mysqldumpPath=mysqldump
  197. set mysqlPath=mysql
  198. ) else (
  199. set mysqldumpPath=%mysqlBinPath%\mysqldump.exe
  200. set mysqlPath=%mysqlBinPath%\mysql.exe
  201. )
  202. echo @echo off > %config_file%
  203. echo set config_version=%config_version% >> %config_file%
  204. echo set cmode=%cmode%>> %config_file%
  205. echo set safe_mode=%safe_mode% >> %config_file%
  206. echo set mysqlPath=%mysqlPath%>> %config_file%
  207. echo set mysqlBinPath=%mysqlBinPath%>> %config_file%
  208. echo set mysqldumpPath=%mysqldumpPath%>> %config_file%
  209. echo set lsuser=%lsuser%>> %config_file%
  210. echo set lspass=%lspass%>> %config_file%
  211. echo set lsdb=%lsdb%>> %config_file%
  212. echo set lshost=%lshost% >> %config_file%
  213. echo set cbuser=%cbuser%>> %config_file%
  214. echo set cbpass=%cbpass%>> %config_file%
  215. echo set cbdb=%cbdb%>> %config_file%
  216. echo set cbhost=%cbhost% >> %config_file%
  217. echo set gsuser=%gsuser%>> %config_file%
  218. echo set gspass=%gspass%>> %config_file%
  219. echo set gsdb=%gsdb%>> %config_file%
  220. echo set gshost=%gshost%>> %config_file%
  221. echo set logdir=%logdir%>> %config_file%
  222. echo set backup=%backup%>> %config_file%
  223. echo.
  224. echo Script setup complete, your settings were saved in the
  225. echo '%config_file%' file. Remember: your passwords are stored
  226. echo as clear text.
  227. echo.
  228. echo press any key to continue...
  229. pause> nul
  230. goto loadconfig
  231. :ls_section
  232. cls
  233. call :colors 17
  234. set cmdline=
  235. set stage=1
  236. title L2JDP Installer - Login Server DataBase Setup
  237. echo.
  238. echo Trying to make a backup of your loginserver database.
  239. set cmdline="%mysqldumpPath%" --add-drop-table -h %lshost% -u %lsuser% --password=%lspass% %lsdb% ^> "%backup%\loginserver_backup.sql" 2^> NUL
  240. %cmdline%
  241. if %ERRORLEVEL% == 0 goto lsdbok
  242. REM if %safe_mode% == 1 goto omfg
  243. :ls_err1
  244. call :colors 47
  245. title L2JDP Installer - Login Server DataBase Setup ERROR!!!
  246. cls
  247. echo.
  248. echo Backup attempt failed! A possible reason for this to
  249. echo happen, is that your DB doesn't exist yet. I could
  250. echo try to create %lsdb% for you, or maybe you prefer to
  251. echo proceed with the CommunityServer part of this tool.
  252. echo.
  253. :ls_ask1
  254. set lsdbprompt=y
  255. echo ATTEMPT TO CREATE LOGINSERVER DATABASE:
  256. echo.
  257. echo (y) Yes
  258. echo.
  259. echo (n) No
  260. echo.
  261. echo (r) Reconfigure
  262. echo.
  263. echo (q) Quit
  264. echo.
  265. set /p lsdbprompt= Choose (default yes):
  266. if /i %lsdbprompt%==y goto lsdbcreate
  267. if /i %lsdbprompt%==n goto cb_backup
  268. if /i %lsdbprompt%==r goto configure
  269. if /i %lsdbprompt%==q goto end
  270. goto ls_ask1
  271. :omfg
  272. cls
  273. call :colors 57
  274. title L2JDP Installer - Potential PICNIC detected at stage %stage%
  275. echo.
  276. echo There was some problem while executing:
  277. echo.
  278. echo "%cmdline%"
  279. echo.
  280. echo I'd suggest you to look for correct values and try this
  281. echo script again later. But maybe you'd prefer to go on now.
  282. echo.
  283. if %stage% == 1 set label=ls_err1
  284. if %stage% == 2 set label=ls_err2
  285. if %stage% == 3 set label=cb_backup
  286. if %stage% == 4 set label=cb_err1
  287. if %stage% == 5 set label=cb_err2
  288. if %stage% == 6 set label=gs_backup
  289. if %stage% == 7 set label=gs_err1
  290. if %stage% == 8 set label=gs_err2
  291. if %stage% == 9 set label=horrible_end
  292. if %stage% == 10 set label=horrible_end
  293. :omfgask1
  294. set omfgprompt=q
  295. echo (c) Continue running the script
  296. echo.
  297. echo (r) Reconfigure
  298. echo.
  299. echo (q) Quit now
  300. echo.
  301. set /p omfgprompt= Choose (default quit):
  302. if /i %omfgprompt%==c goto %label%
  303. if /i %omfgprompt%==r goto configure
  304. if /i %omfgprompt%==q goto horrible_end
  305. goto omfgask1
  306. :lsdbcreate
  307. call :colors 17
  308. set cmdline=
  309. set stage=2
  310. title L2JDP Installer - Login Server DataBase Setup - DB Creation
  311. echo.
  312. echo Trying to create a Login Server database...
  313. set cmdline="%mysqlPath%" -h %lshost% -u %lsuser% --password=%lspass% -e "CREATE DATABASE %lsdb%" 2^> NUL
  314. %cmdline%
  315. if %ERRORLEVEL% == 0 goto logininstall
  316. if %safe_mode% == 1 goto omfg
  317. :ls_err2
  318. call :colors 47
  319. title L2JDP Installer - Login Server DataBase Setup - DB Creation ERROR!
  320. cls
  321. echo An error occured while trying to create a database for
  322. echo your login server.
  323. echo.
  324. echo Possible reasons:
  325. echo 1-You provided innacurate info , check user, password, etc.
  326. echo 2-User %lsuser% don't have enough privileges for
  327. echo database creation. Check your MySQL privileges.
  328. echo 3-Database exists already...?
  329. echo.
  330. echo Unless you're sure that the pending actions of this tool
  331. echo could work, i'd suggest you to look for correct values
  332. echo and try this script again later.
  333. echo.
  334. :ls_ask2
  335. set omfgprompt=q
  336. echo (c) Continue running
  337. echo.
  338. echo (r) Reconfigure
  339. echo.
  340. echo (q) Quit now
  341. echo.
  342. set /p omfgprompt= Choose (default quit):
  343. if /i %omfgprompt%==c goto cb_backup
  344. if /i %omfgprompt%==q goto horrible_end
  345. if /i %omfgprompt%==r goto configure
  346. goto ls_ask2
  347. :lsdbok
  348. call :colors 17
  349. title L2JDP Installer - Login Server DataBase Setup - WARNING!
  350. echo.
  351. :asklogin
  352. if %fresh_setup%==0 (
  353. set loginprompt=s
  354. set msg=default skip
  355. ) else (
  356. set loginprompt=x
  357. set msg=no default for fresh install
  358. )
  359. echo LOGINSERVER DATABASE install type:
  360. echo.
  361. echo (f) Full: I will destroy data in your `accounts` and
  362. echo and `gameserver` tables.
  363. echo.
  364. echo (s) Skip: I'll take you to the communityserver database
  365. echo installation and upgrade options.
  366. echo.
  367. echo (r) Reconfigure: You'll be able to redefine MySQL path,
  368. echo user and database information and start over with
  369. echo those fresh values.
  370. echo.
  371. echo (q) Quit
  372. echo.
  373. set /p loginprompt= Choose (%msg%):
  374. if /i %loginprompt%==f goto logininstall
  375. if /i %loginprompt%==s goto cb_backup
  376. if /i %loginprompt%==r goto configure
  377. if /i %loginprompt%==q goto end
  378. goto asklogin
  379. :logininstall
  380. set stage=3
  381. call :colors 17
  382. set cmdline=
  383. title L2JDP Installer - Login Server DataBase Setup - Full Install
  384. echo Deleting loginserver tables for new content.
  385. set cmdline="%mysqlPath%" -h %lshost% -u %lsuser% --password=%lspass% -D %lsdb% ^< login_install.sql 2^> NUL
  386. %cmdline%
  387. if not %ERRORLEVEL% == 0 goto omfg
  388. set full=1
  389. goto cb_backup
  390. :cb_backup
  391. cls
  392. call :colors 17
  393. set cmdline=
  394. rem if %full% == 1 goto communityinstall
  395. set stage=4
  396. title L2JDP Installer - Community Board Server DataBase Setup
  397. echo.
  398. echo Trying to make a backup of your cbserver database.
  399. set cmdline="%mysqldumpPath%" --add-drop-table -h %cbhost% -u %cbuser% --password=%cbpass% %cbdb% ^> "%backup%\cbserver_backup.sql" 2^> NUL
  400. %cmdline%
  401. if %ERRORLEVEL% == 0 goto cbdbok
  402. REM if %safe_mode% == 1 goto omfg
  403. :cb_err1
  404. call :colors 47
  405. title L2JDP Installer - Community Board Server DataBase Setup ERROR!
  406. cls
  407. echo.
  408. echo Backup attempt failed! A possible reason for this to
  409. echo happen, is that your DB doesn't exist yet. I could
  410. echo try to create %cbdb% for you, or maybe you prefer to
  411. echo proceed with the GameServer part of this tool.
  412. echo.
  413. :cb_ask1
  414. set cbdbprompt=y
  415. echo ATTEMPT TO CREATE COMMUNITYSERVER DATABASE:
  416. echo.
  417. echo (y) Yes
  418. echo.
  419. echo (n) No
  420. echo.
  421. echo (r) Reconfigure
  422. echo.
  423. echo (q) Quit
  424. echo.
  425. set /p cbdbprompt= Choose (default yes):
  426. if /i %cbdbprompt%==y goto cbdbcreate
  427. if /i %cbdbprompt%==n goto gs_backup
  428. if /i %cbdbprompt%==r goto configure
  429. if /i %cbdbprompt%==q goto end
  430. goto cb_ask1
  431. :cbdbcreate
  432. call :colors 17
  433. set cmdline=
  434. set stage=5
  435. title L2JDP Installer - Communty Board Server DataBase Setup - DB Creation
  436. echo.
  437. echo Trying to create a Community Board Server database...
  438. set cmdline="%mysqlPath%" -h %cbhost% -u %cbuser% --password=%cbpass% -e "CREATE DATABASE %cbdb%" 2^> NUL
  439. %cmdline%
  440. if %ERRORLEVEL% == 0 goto communityinstall
  441. if %safe_mode% == 1 goto omfg
  442. :cb_err2
  443. call :colors 47
  444. title L2JDP Installer - Community Board Server DataBase Setup - DB Creation ERROR!
  445. cls
  446. echo An error occured while trying to create a database for
  447. echo your Community Board server.
  448. echo.
  449. echo Possible reasons:
  450. echo 1-You provided innacurate info , check user, password, etc.
  451. echo 2-User %cbuser% don't have enough privileges for
  452. echo database creation. Check your MySQL privileges.
  453. echo 3-Database exists already...?
  454. echo.
  455. echo Unless you're sure that the pending actions of this tool
  456. echo could work, i'd suggest you to look for correct values
  457. echo and try this script again later.
  458. echo.
  459. :cb_ask2
  460. set omfgprompt=q
  461. echo (c) Continue running
  462. echo.
  463. echo (r) Reconfigure
  464. echo.
  465. echo (q) Quit now
  466. echo.
  467. set /p omfgprompt= Choose (default quit):
  468. if /i %omfgprompt%==c goto gs_backup
  469. if /i %omfgprompt%==q goto horrible_end
  470. if /i %omfgprompt%==r goto configure
  471. goto cb_ask2
  472. :cbdbok
  473. call :colors 17
  474. title L2JDP Installer - Community Board Server DataBase Setup - WARNING!
  475. echo.
  476. :askcommunity
  477. if %fresh_setup%==0 (
  478. set communityprompt=s
  479. set msg=default skip
  480. ) else (
  481. set communityprompt=x
  482. set msg=no default for fresh install
  483. )
  484. echo COMMUNITYSERVER DATABASE install type:
  485. echo.
  486. echo (f) Full: WARNING! I'll destroy ALL of your existing community
  487. echo data (i really mean it: mail, forum, memo.. ALL)
  488. echo.
  489. echo (u) Upgrade: I'll do my best to preserve all of your community
  490. echo data.
  491. echo.
  492. echo (s) Skip: I'll take you to the gameserver database
  493. echo installation and upgrade options.
  494. echo.
  495. echo (r) Reconfigure: You'll be able to redefine MySQL path,
  496. echo user and database information and start over with
  497. echo those fresh values.
  498. echo.
  499. echo (q) Quit
  500. echo.
  501. set /p communityprompt= Choose (%msg%):
  502. if /i %communityprompt%==f goto communityinstall
  503. if /i %communityprompt%==u goto upgradecbinstall
  504. if /i %communityprompt%==s goto gs_backup
  505. if /i %communityprompt%==r goto configure
  506. if /i %communityprompt%==q goto end
  507. goto askcommunity
  508. :communityinstall
  509. set stage=6
  510. call :colors 17
  511. set cmdline=
  512. title L2JDP Installer - Community Board Server DataBase Setup - Full Install
  513. echo Deleting communityserver tables for new content.
  514. set cmdline="%mysqlPath%" -h %cbhost% -u %cbuser% --password=%cbpass% -D %cbdb% ^< community_install.sql 2^> NUL
  515. %cmdline%
  516. if not %ERRORLEVEL% == 0 goto omfg
  517. set full=1
  518. goto upgradecbinstall
  519. :upgradecbinstall
  520. set stage=6
  521. set cmdline=
  522. if %full% == 1 (
  523. title L2JDP Installer - Community Board Server DataBase Setup - Installing...
  524. echo Installing new communityserver content.
  525. ) else (
  526. title L2JDP Installer - Community Board Server DataBase Setup - Upgrading...
  527. echo Upgrading communityserver content.
  528. )
  529. if %logging% == 0 set output=NUL
  530. set dest=cb
  531. for %%i in (..\cb_sql\*.sql) do call :dump %%i
  532. echo done...
  533. echo.
  534. goto gs_backup
  535. :gs_backup
  536. cls
  537. call :colors 17
  538. set cmdline=
  539. if %full% == 1 goto fullinstall
  540. set stage=7
  541. title L2JDP Installer - Game Server DataBase Setup
  542. cls
  543. echo.
  544. echo Making a backup of the original gameserver database.
  545. set cmdline="%mysqldumpPath%" --add-drop-table -h %gshost% -u %gsuser% --password=%gspass% %gsdb% ^> "%backup%\gameserver_backup.sql" 2^> NUL
  546. %cmdline%
  547. if %ERRORLEVEL% == 0 goto gsdbok
  548. rem if %safe_mode% == 1 goto omfg
  549. :gs_err1
  550. call :colors 47
  551. title L2JDP Installer - Game Server DataBase Setup - Backup ERROR!
  552. cls
  553. echo.
  554. echo Backup attempt failed! A possible reason for this to happen,
  555. echo is that your DB doesn't exist yet. I could try to create
  556. echo %gsdb% for you, but maybe you prefer me to continue with
  557. echo last part of the script.
  558. echo.
  559. :askgsdb
  560. set gsdbprompt=y
  561. echo ATTEMPT TO CREATE GAMESERVER DATABASE?
  562. echo.
  563. echo (y) Yes
  564. echo.
  565. echo (n) No
  566. echo.
  567. echo (r) Reconfigure
  568. echo.
  569. echo (q) Quit
  570. echo.
  571. set /p gsdbprompt= Choose (default yes):
  572. if /i %gsdbprompt%==y goto gsdbcreate
  573. if /i %gsdbprompt%==n goto horrible_end
  574. if /i %gsdbprompt%==r goto configure
  575. if /i %gsdbprompt%==q goto end
  576. goto askgsdb
  577. :gsdbcreate
  578. call :colors 17
  579. set stage=8
  580. set cmdline=
  581. title L2JDP Installer - Game Server DataBase Setup - DB Creation
  582. cls
  583. echo Trying to create Game Server database...
  584. set cmdline="%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -e "CREATE DATABASE %gsdb%" 2^> NUL
  585. %cmdline%
  586. if %ERRORLEVEL% == 0 goto fullinstall
  587. if %safe_mode% == 1 goto omfg
  588. :gs_err2
  589. call :colors 47
  590. title L2JDP Installer - Game Server DataBase Setup - DB Creation ERROR!
  591. cls
  592. echo.
  593. echo An error occured while trying to create a database for
  594. echo your game server.
  595. echo.
  596. echo Possible reasons:
  597. echo 1-You provided innacurate info, check username, pass, etc.
  598. echo 2-User %gsuser% don't have enough privileges for
  599. echo database creation.
  600. echo 3-Database exists already...?
  601. echo.
  602. echo I'd suggest you to look for correct values and try this
  603. echo script again later. But you can try to reconfigure it now.
  604. echo.
  605. :askgsdbcreate
  606. set omfgprompt=q
  607. echo (r) Restart script with fresh configuration values
  608. echo.
  609. echo (q) Quit now
  610. echo.
  611. set /p omfgprompt= Choose (default quit):
  612. if /i %omfgprompt%==r goto configure
  613. if /i %omfgprompt%==q goto horrible_end
  614. goto askgsdbcreate
  615. :gsdbok
  616. call :colors 17
  617. title L2JDP Installer - Game Server DataBase Setup - WARNING!
  618. cls
  619. echo.
  620. :asktype
  621. set installtype=u
  622. echo GAMESERVER DATABASE install:
  623. echo.
  624. echo (f) Full: WARNING! I'll destroy ALL of your existing character
  625. echo data (i really mean it: items, pets.. ALL)
  626. echo.
  627. echo (u) Upgrade: I'll do my best to preserve all of your character
  628. echo data.
  629. echo.
  630. echo (s) Skip: We'll get into the last set of questions (cummulative
  631. echo updates, custom stuff...)
  632. echo.
  633. echo (q) Quit
  634. echo.
  635. set /p installtype= Choose (default upgrade):
  636. if /i %installtype%==f goto fullinstall
  637. if /i %installtype%==u goto upgradeinstall
  638. if /i %installtype%==s goto custom
  639. if /i %installtype%==q goto end
  640. goto asktype
  641. :fullinstall
  642. call :colors 17
  643. set stage=9
  644. set cmdline=
  645. title L2JDP Installer - Game Server DataBase Setup - Full Install
  646. echo Deleting all gameserver tables for new content...
  647. set cmdline="%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^< full_install.sql 2^> NUL
  648. %cmdline%
  649. if not %ERRORLEVEL% == 0 goto omfg
  650. set full=1
  651. echo.
  652. echo Game Server tables were deleted.
  653. goto upgradeinstall
  654. :upgradeinstall
  655. set stage=9
  656. set cmdline=
  657. if %full% == 1 (
  658. title L2JDP Installer - Game Server DataBase Setup - Installing...
  659. echo Installing new gameserver content.
  660. ) else (
  661. title L2JDP Installer - Game Server DataBase Setup - Upgrading...
  662. echo Upgrading gameserver content.
  663. )
  664. if %logging% == 0 set output=NUL
  665. set dest=ls
  666. for %%i in (..\sql\login\*.sql) do call :dump %%i
  667. set dest=gs
  668. for %%i in (..\sql\server\*.sql) do call :dump %%i
  669. echo done...
  670. echo.
  671. goto custom
  672. :dump
  673. set cmdline=
  674. if /i %full% == 1 (set action=Installing) else (set action=Upgrading)
  675. echo %action% %1>>"%output%"
  676. echo %action% %~nx1
  677. if "%dest%"=="ls" set cmdline="%mysqlPath%" -h %lshost% -u %lsuser% --password=%lspass% -D %lsdb% ^< %1 2^>^>"%output%"
  678. if "%dest%"=="cb" set cmdline="%mysqlPath%" -h %cbhost% -u %cbuser% --password=%cbpass% -D %cbdb% ^< %1 2^>^>"%output%"
  679. if "%dest%"=="gs" set cmdline="%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^< %1 2^>^>"%output%"
  680. %cmdline%
  681. if %logging%==0 if NOT %ERRORLEVEL%==0 call :omfg2 %1
  682. goto :eof
  683. :omfg2
  684. cls
  685. call :colors 47
  686. title L2JDP Installer - Potential DataBase Issue at stage %stage%
  687. echo.
  688. echo Something caused an error while executing instruction :
  689. echo %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb%
  690. echo.
  691. echo with file %~nx1
  692. echo.
  693. echo What we should do now?
  694. echo.
  695. :askomfg2
  696. set ntpebcak=c
  697. echo (l) Log it: I will create a log for this file, then continue
  698. echo with the rest of the list in non-logging mode.
  699. echo.
  700. echo (c) Continue: Let's pretend that nothing happened and continue with
  701. echo the rest of the list.
  702. echo.
  703. echo (r) Reconfigure: Perhaps these errors were caused by a typo.
  704. echo you can restart from scratch and redefine paths, databases
  705. echo and user info again.
  706. echo.
  707. echo (q) Quit now
  708. echo.
  709. set /p ntpebcak= Choose (default continue):
  710. if /i %ntpebcak%==c (call :colors 17 & goto :eof)
  711. if /i %ntpebcak%==l (call :logginon %1 & goto :eof)
  712. if /i %ntpebcak%==r (call :configure & exit)
  713. if /i %ntpebcak%==q (call :horrible_end & exit)
  714. goto askomfg2
  715. :logginon
  716. cls
  717. call :colors 17
  718. title L2JDP Installer - Game Server DataBase Setup - Logging Options turned on
  719. set logging=1
  720. if %full% == 1 (
  721. set output=%logdir%\install-%~nx1.log
  722. ) else (
  723. set output=%logdir%\upgrade-%~nx1.log
  724. )
  725. echo.
  726. echo Per your request, i'll create a log file for your reading pleasure.
  727. echo.
  728. echo I'll call it %output%
  729. echo.
  730. echo If you already have such a file and would like to keep a copy.
  731. echo go now and read it or back it up, because it's not going to be rotated
  732. echo or anything, instead i'll just overwrite it.
  733. echo.
  734. echo When you're done or if you don't mind, press any key to start.
  735. pause>NUL
  736. set cmdline="%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^<..\sql\%1 2^>^>"%output%"
  737. date /t >"%output%"
  738. time /t >>"%output%"
  739. %cmdline%
  740. echo Log file created, resuming normal operations...
  741. call :colors 17
  742. set logging=0
  743. set output=NUL
  744. goto :eof
  745. :custom
  746. title L2JDP Installer - Custom Server Tables
  747. cls
  748. set cstprompt=n
  749. echo.
  750. echo L2J provides some "Custom Server Tables" for non-retail modifications
  751. echo in order to avoid override the original Server Tables.
  752. echo.
  753. set /p cstprompt=Install Custom Server Tables: (y) yes or (n) no :
  754. if /i %cstprompt%==y goto cstinstall
  755. if /i %cstprompt%==n goto mod
  756. goto newbie_helper
  757. :cstinstall
  758. cls
  759. echo.
  760. echo Installing custom content.
  761. cd ..\sql\server\custom\
  762. echo @echo off> temp.bat
  763. if exist custom_errors.txt del custom_errors.txt
  764. for %%i in (*.sql) do echo "%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^< %%i 2^>^> custom_errors.txt >> temp.bat
  765. call temp.bat> nul
  766. del temp.bat
  767. move custom_errors.txt %workdir%
  768. title L2JDP Installer - Custom Server Tables Process Complete
  769. cls
  770. echo Database structure for L2J Custom finished.
  771. echo.
  772. echo Remember that in order to get these additions actually working
  773. echo you need to edit your configuration files.
  774. echo.
  775. pause
  776. cd %workdir%
  777. :mod
  778. title L2JDP Installer - Mod Server Tables
  779. cls
  780. set cstprompt=n
  781. echo.
  782. echo L2J provides a basic infraestructure for some non-retail features
  783. echo (aka L2J mods) to get enabled with a minimum of changes.
  784. echo.
  785. echo Some of these mods would require extra tables in order to work
  786. echo and those tables could be created now if you wanted to.
  787. echo.
  788. set /p cstprompt=Install Mod Server Tables: (y) yes or (n) no :
  789. if /i %cstprompt%==y goto modinstall
  790. if /i %cstprompt%==n goto newbie_helper
  791. goto newbie_helper
  792. :modinstall
  793. cls
  794. echo.
  795. echo Installing mods content.
  796. cd ..\sql\server\mods\
  797. echo @echo off> temp.bat
  798. if exist mods_errors.txt del mods_errors.txt
  799. for %%i in (*.sql) do echo "%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^< %%i 2^>^> mods_errors.txt >> temp.bat
  800. call temp.bat> nul
  801. del temp.bat
  802. move mods_errors.txt %workdir%
  803. title L2JDP Installer - Mod Server Tables Process Complete
  804. cls
  805. echo Database structure for L2J Mods finished.
  806. echo.
  807. echo Remember that in order to get these additions actually working
  808. echo you need to edit your configuration files.
  809. echo.
  810. pause
  811. cd %workdir%
  812. goto newbie_helper
  813. :newbie_helper
  814. call :colors 17
  815. set stage=10
  816. title L2JDP Installer - Update SQL Tables
  817. cls
  818. if %full% == 1 goto end
  819. echo.
  820. echo Inside...
  821. echo sql/login/updates
  822. echo sql/server/updates
  823. echo cb_sql/updates folders
  824. echo we use to store cummulative changes needed by
  825. echo the database structures.
  826. echo.
  827. echo Usually these SQL files are created whenever some new
  828. echo feature implementation requires it.
  829. echo.
  830. echo I can try to apply these patches for you.
  831. :asknb
  832. set nbprompt=a
  833. echo.
  834. echo What we do with the .sql files in your updates folder?
  835. echo.
  836. echo (a) All LS/CS/GS Updates: I'll do the automatic process
  837. echo with LS/CS/GS updates folders.
  838. echo.
  839. echo (l) Only LS Updates : I'll do the automatic process
  840. echo only with the sql/login/updates folder.
  841. echo.
  842. echo (c) Only CB Updates : I'll do the automatic process
  843. echo only with the cb_sql/updates folder.
  844. echo.
  845. echo (g) Only GS Updates: I'll do the automagic process
  846. echo only with the sql/server/updates folder.
  847. echo.
  848. echo (s) Skip: I'll do nothing, it's up to you to find out
  849. echo which file does what, which one could be of use for
  850. echo you, etc.
  851. echo.
  852. set /p nbprompt= Choose (default auto-all):
  853. if /i %nbprompt%==a goto nblsinstall
  854. if /i %nbprompt%==l goto nblsinstall
  855. if /i %nbprompt%==c goto nbcbinstall
  856. if /i %nbprompt%==g goto nbgsinstall
  857. if /i %nbprompt%==s goto end
  858. goto asknb
  859. :nblsinstall
  860. cd ..\sql\login\updates\
  861. echo @echo off> temp.bat
  862. if exist lserrors.txt del lserrors.txt
  863. for %%i in (*.sql) do echo "%mysqlPath%" -h %lshost% -u %lsuser% --password=%lspass% -D %lsdb% ^< %%i 2^>^> lserrors.txt >> temp.bat
  864. call temp.bat> nul
  865. del temp.bat
  866. move lserrors.txt %workdir%
  867. cd %workdir%
  868. if /i %nbprompt%==l goto nbfinished
  869. :nbcbinstall
  870. cd ..\cb_sql\updates\
  871. echo @echo off> temp.bat
  872. if exist cberrors.txt del cberrors.txt
  873. for %%i in (*.sql) do echo "%mysqlPath%" -h %cbhost% -u %cbuser% --password=%cbpass% -D %cbdb% ^< %%i 2^>^> cberrors.txt >> temp.bat
  874. call temp.bat> nul
  875. del temp.bat
  876. move cberrors.txt %workdir%
  877. cd %workdir%
  878. if /i %nbprompt%==c goto nbfinished
  879. :nbgsinstall
  880. cd ..\sql\server\updates\
  881. echo @echo off> temp.bat
  882. if exist gserrors.txt del gserrors.txt
  883. for %%i in (*.sql) do echo "%mysqlPath%" -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% ^< %%i 2^>^> gserrors.txt >> temp.bat
  884. call temp.bat> nul
  885. del temp.bat
  886. move gserrors.txt %workdir%
  887. cd %workdir%
  888. :nbfinished
  889. title L2JDP Installer - Update SQL Tables Process Complete
  890. cls
  891. echo Automagic processing finished, i'm leaving an 'errors.txt'
  892. echo file for your consideration.
  893. echo.
  894. echo Remember that some of these files could have tried to add stuff that were
  895. echo part of your database structure already, so don't go out yelling about
  896. echo.
  897. echo 'Duplicate column name'
  898. echo.
  899. echo messages you may find there.
  900. echo.
  901. echo Rather you should focus in those that say
  902. echo.
  903. echo 'Table doesn't exist'
  904. echo.
  905. echo for example.
  906. echo.
  907. pause
  908. goto end
  909. :binaryfind
  910. if EXIST "%mysqlBinPath%" (echo Found) else (echo Not Found)
  911. goto :eof
  912. :horrible_end
  913. call :colors 47
  914. title L2JDP Installer - Oops!
  915. cls
  916. echo This wasn't a clean run, but don't worry.
  917. echo You can get help and support:
  918. echo.
  919. echo 1-Read the L2J Datapack project wiki :
  920. echo (http://www.l2jdp.com/trac/wiki)
  921. echo 2-Search for a similar problem in our forums
  922. echo (http://www.l2jdp.com/forum)
  923. echo.
  924. echo You can ask for support in our forums or irc channel:
  925. echo irc://irc.freenode.net channel: #l2j
  926. echo.
  927. echo I'll try to gather some versioning information that you
  928. echo may find useful when asking for support :
  929. echo.
  930. echo Datapack revision reported by 'SVN version':
  931. svnversion -n 2>NUL
  932. echo.
  933. if %ERRORLEVEL% == 9009 (
  934. echo SVN commandline tools not found!
  935. echo Please download and install "Windows installer with
  936. echo the basic win32 binaries" (or something that fits our
  937. echo binaries needs) from :
  938. echo http://goo.gl/c0uyh
  939. echo.
  940. )
  941. set dpvf="..\config\l2jdp-version.properties"
  942. echo Datapack revision reported by properties file :
  943. if NOT EXIST %dpvf% (
  944. echo Your %dpvf% file is missing!
  945. echo Use eclipse/ant to build one from your DP SVN copy.
  946. echo With it we'll be able to help you better.
  947. ) else (
  948. type %dpvf% | find "version" 2> NUL
  949. if not %ERRORLEVEL% == 0 (
  950. echo An error occured while trying to read
  951. echo your %dpvf% file!
  952. echo Make sure you keep it up to date
  953. echo and in the correct place.
  954. echo %ERRORLEVEL%
  955. ))
  956. echo.
  957. rem del %config_file%
  958. pause
  959. goto end
  960. :end
  961. call :colors 17
  962. title L2JDP Installer - Script Execution Finished
  963. cls
  964. echo.
  965. echo L2JDP database_installer version 0.2.4
  966. echo (C) 2007-2011 L2J Datapack Team
  967. echo database_installer comes with ABSOLUTELY NO WARRANTY;
  968. echo This is free software, and you are welcome to redistribute it
  969. echo under certain conditions; See the file gpl.txt for further
  970. echo details.
  971. echo.
  972. echo Thanks for using our software.
  973. echo visit http://www.l2jdp.com for more info about
  974. echo the L2J Datapack project.
  975. echo.
  976. pause
  977. color