database_installer.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. #!/bin/bash
  2. ##########################################################################
  3. ## Copyright (C) 2004-2013 L2J DataPack ##
  4. ## ##
  5. ## This file is part of L2J DataPack. ##
  6. ## ##
  7. ## L2J DataPack is free software: you can redistribute it and/or modify ##
  8. ## it under the terms of the GNU General Public License as published by ##
  9. ## the Free Software Foundation, either version 3 of the License, or ##
  10. ## (at your option) any later version. ##
  11. ## ##
  12. ## L2J DataPack is distributed in the hope that it will be useful, ##
  13. ## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
  14. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ##
  15. ## General Public License for more details. ##
  16. ## ##
  17. ## You should have received a copy of the GNU General Public License ##
  18. ## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
  19. ##########################################################################
  20. ## WARNING! WARNING! WARNING! WARNING! ##
  21. ## ##
  22. ## DON'T USE NOTEPAD TO CHANGE THIS FILE ##
  23. ## INSTEAD USE SOME DECENT TEXT EDITOR. ##
  24. ## NEWLINE CHARACTERS DIFFER BETWEEN DOS/ ##
  25. ## WINDOWS AND UNIX. ##
  26. ## ##
  27. ## USING NOTEPAD TO SAVE THIS FILE WILL ##
  28. ## LEAVE IT IN A BROKEN STATE!!! ##
  29. ############################################
  30. ## Writen by DrLecter ##
  31. ## License: GNU GPL ##
  32. ## Based on Tiago Tagliaferri's script ##
  33. ## E-mail: tiago_tagliaferri@msn.com ##
  34. ## From "L2J-DataPack" ##
  35. ## Bug reports: http://trac.l2jdp.com/ ##
  36. ############################################
  37. trap finish 2
  38. configure() {
  39. echo "#############################################"
  40. echo "# You entered script configuration area #"
  41. echo "# No change will be performed in your DB #"
  42. echo "# I will just ask you some questions about #"
  43. echo "# your hosts and DB. #"
  44. echo "#############################################"
  45. MYSQLDUMPPATH=`which -a mysqldump 2>/dev/null`
  46. MYSQLPATH=`which -a mysql 2>/dev/null`
  47. if [ $? -ne 0 ]; then
  48. echo "We were unable to find MySQL binaries on your path"
  49. while :
  50. do
  51. echo -ne "\nPlease enter MySQL binaries directory (no trailing slash): "
  52. read MYSQLBINPATH
  53. if [ -e "$MYSQLBINPATH" ] && [ -d "$MYSQLBINPATH" ] && \
  54. [ -e "$MYSQLBINPATH/mysqldump" ] && [ -e "$MYSQLBINPATH/mysql" ]; then
  55. MYSQLDUMPPATH="$MYSQLBINPATH/mysqldump"
  56. MYSQLPATH="$MYSQLBINPATH/mysql"
  57. break
  58. else
  59. echo "The data you entered is invalid. Please verify and try again."
  60. exit 1
  61. fi
  62. done
  63. fi
  64. #LS
  65. echo -ne "\nPlease enter MySQL Login Server hostname (default localhost): "
  66. read LSDBHOST
  67. if [ -z "$LSDBHOST" ]; then
  68. LSDBHOST="localhost"
  69. fi
  70. echo -ne "\nPlease enter MySQL Login Server database name (default l2jls): "
  71. read LSDB
  72. if [ -z "$LSDB" ]; then
  73. LSDB="l2jls"
  74. fi
  75. echo -ne "\nPlease enter MySQL Login Server user (default root): "
  76. read LSUSER
  77. if [ -z "$LSUSER" ]; then
  78. LSUSER="root"
  79. fi
  80. echo -ne "\nPlease enter MySQL Login Server $LSUSER's password (won't be displayed) :"
  81. stty -echo
  82. read LSPASS
  83. stty echo
  84. echo ""
  85. if [ -z "$LSPASS" ]; then
  86. echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
  87. elif [ "$LSUSER" == "$LSPASS" ]; then
  88. echo "You're not too brilliant choosing passwords huh?"
  89. fi
  90. #CB
  91. echo -ne "\nPlease enter MySQL Community Server hostname (default localhost): "
  92. read CBDBHOST
  93. if [ -z "$CBDBHOST" ]; then
  94. CBDBHOST="localhost"
  95. fi
  96. echo -ne "\nPlease enter MySQL Community Server database name (default l2jcs): "
  97. read CBDB
  98. if [ -z "$CBDB" ]; then
  99. CBDB="l2jcs"
  100. fi
  101. echo -ne "\nPlease enter MySQL Community Server user (default root): "
  102. read CBUSER
  103. if [ -z "$CBUSER" ]; then
  104. CBUSER="root"
  105. fi
  106. echo -ne "\nPlease enter MySQL Community Server $CBUSER's password (won't be displayed) :"
  107. stty -echo
  108. read CBPASS
  109. stty echo
  110. echo ""
  111. if [ -z "$CBPASS" ]; then
  112. echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
  113. elif [ "$CBUSER" == "$CBPASS" ]; then
  114. echo "You're not too brilliant choosing passwords huh?"
  115. fi
  116. #GS
  117. echo -ne "\nPlease enter MySQL Game Server hostname (default localhost): "
  118. read GSDBHOST
  119. if [ -z "$GSDBHOST" ]; then
  120. GSDBHOST="localhost"
  121. fi
  122. echo -ne "\nPlease enter MySQL Game Server database name (default l2jgs): "
  123. read GSDB
  124. if [ -z "$GSDB" ]; then
  125. GSDB="l2jgs"
  126. fi
  127. echo -ne "\nPlease enter MySQL Game Server user (default root): "
  128. read GSUSER
  129. if [ -z "$GSUSER" ]; then
  130. GSUSER="root"
  131. fi
  132. echo -ne "\nPlease enter MySQL Game Server $GSUSER's password (won't be displayed): "
  133. stty -echo
  134. read GSPASS
  135. stty echo
  136. echo ""
  137. if [ -z "$GSPASS" ]; then
  138. echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
  139. elif [ "$GSUSER" == "$GSPASS" ]; then
  140. echo "You're not too brilliant choosing passwords huh?"
  141. fi
  142. save_config $1
  143. }
  144. save_config() {
  145. if [ -n "$1" ]; then
  146. CONF="$1"
  147. else
  148. CONF="database_installer.rc"
  149. fi
  150. echo ""
  151. echo "With these data I can generate a configuration file which can be read"
  152. echo "on future updates. WARNING: this file will contain clear text passwords!"
  153. echo -ne "Shall I generate config file $CONF? (Y/n):"
  154. read SAVE
  155. if [ "$SAVE" == "y" -o "$SAVE" == "Y" -o "$SAVE" == "" ];then
  156. cat <<EOF>$CONF
  157. #Configuration settings for L2J-Datapack database installer script
  158. MYSQLDUMPPATH=$MYSQLDUMPPATH
  159. MYSQLPATH=$MYSQLPATH
  160. LSDBHOST=$LSDBHOST
  161. LSDB=$LSDB
  162. LSUSER=$LSUSER
  163. LSPASS=$LSPASS
  164. CBDBHOST=$CBDBHOST
  165. CBDB=$CBDB
  166. CBUSER=$CBUSER
  167. CBPASS=$CBPASS
  168. GSDBHOST=$GSDBHOST
  169. GSDB=$GSDB
  170. GSUSER=$GSUSER
  171. GSPASS=$GSPASS
  172. EOF
  173. chmod 600 $CONF
  174. echo "Configuration saved as $CONF"
  175. echo "Permissions changed to 600 (rw- --- ---)"
  176. elif [ "$SAVE" != "n" -a "$SAVE" != "N" ]; then
  177. save_config
  178. fi
  179. }
  180. load_config() {
  181. if [ -n "$1" ]; then
  182. CONF="$1"
  183. else
  184. CONF="database_installer.rc"
  185. fi
  186. if [ -e "$CONF" ] && [ -f "$CONF" ]; then
  187. . $CONF
  188. else
  189. echo "Settings file not found: $CONF"
  190. echo "You can specify an alternate settings filename:"
  191. echo $0 config_filename
  192. echo ""
  193. echo "If file doesn't exist it can be created"
  194. echo "If nothing is specified script will try to work with ./database_installer.rc"
  195. echo ""
  196. configure $CONF
  197. fi
  198. }
  199. ls_backup(){
  200. while :
  201. do
  202. clear
  203. echo ""
  204. echo -ne "Do you want to make a backup copy of your LSDB? (y/n): "
  205. read LSB
  206. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  207. echo "Trying to make a backup of your Login Server DataBase."
  208. $MYSQLDUMPPATH --add-drop-table -h $LSDBHOST -u $LSUSER --password=$LSPASS $LSDB > ls_backup.sql
  209. if [ $? -ne 0 ];then
  210. clear
  211. echo ""
  212. echo "There was a problem accesing your LS database, either it wasnt created or authentication data is incorrect."
  213. exit 1
  214. fi
  215. break
  216. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  217. break
  218. fi
  219. done
  220. ls_ask
  221. }
  222. ls_ask(){
  223. clear
  224. echo ""
  225. echo "LOGINSERVER DATABASE install type:"
  226. echo ""
  227. echo "(f) Full: WARNING! I'll destroy ALL of your existing login"
  228. echo " data."
  229. echo ""
  230. echo "(u) Upgrade: I'll do my best to preserve all login data."
  231. echo ""
  232. echo "(s) Skip: I'll take you to the communityserver database"
  233. echo " installation and upgrade options."
  234. echo ""
  235. echo "(q) Quit"
  236. echo ""
  237. echo -ne "LOGINSERVER DB install type: "
  238. read LSASK
  239. case "$LSASK" in
  240. "f"|"F") ls_cleanup I;;
  241. "u"|"U") ls_upgrade U;;
  242. "s"|"S") cs_backup;;
  243. "q"|"Q") finish;;
  244. *) ls_ask;;
  245. esac
  246. }
  247. ls_cleanup(){
  248. clear
  249. echo "Deleting Login Server tables for new content."
  250. $MYL < ls_cleanup.sql
  251. ls_install
  252. }
  253. ls_upgrade(){
  254. clear
  255. echo ""
  256. echo "Upgrading structure of Login Server tables."
  257. echo ""
  258. for file in $(ls ../sql/login/updates/*.sql);do
  259. $MYL --force < $file 2>> ls_error.log
  260. done
  261. ls_install
  262. }
  263. ls_install(){
  264. clear
  265. if [ "$1" == "I" ]; then
  266. echo ""
  267. echo "Installing new Login Server content."
  268. echo ""
  269. else
  270. echo ""
  271. echo "Upgrading Login Server content."
  272. echo ""
  273. fi
  274. for login in $(ls ../sql/login/*.sql);do
  275. echo "Installing loginserver table : $login"
  276. $MYL < $login
  277. done
  278. cs_ask
  279. }
  280. cs_backup(){
  281. while :
  282. do
  283. clear
  284. echo ""
  285. echo -ne "Do you want to make a backup copy of your CBDB? (y/n): "
  286. read CSB
  287. if [ "$CSB" == "Y" -o "$CSB" == "y" ]; then
  288. echo "Trying to make a backup of your Community Server DataBase."
  289. $MYSQLDUMPPATH --add-drop-table -h $CBDBHOST -u $CBUSER --password=$CBPASS $CBDB > cs_backup.sql
  290. if [ $? -ne 0 ];then
  291. clear
  292. echo ""
  293. echo "There was a problem accesing your CB database, either it wasnt created or authentication data is incorrect."
  294. exit 1
  295. fi
  296. break
  297. elif [ "$CSB" == "n" -o "$CSB" == "N" ]; then
  298. break
  299. fi
  300. done
  301. cs_ask
  302. }
  303. cs_ask(){
  304. clear
  305. echo ""
  306. echo "COMMUNITY SERVER DATABASE install type:"
  307. echo ""
  308. echo "(f) Full: WARNING! I'll destroy ALL of your existing community"
  309. echo " data (i really mean it: mail, forum, memo.. ALL)"
  310. echo ""
  311. echo "(u) Upgrade: I'll do my best to preserve all of your community"
  312. echo " data."
  313. echo ""
  314. echo "(s) Skip: I'll take you to the gameserver database"
  315. echo " installation and upgrade options."
  316. echo ""
  317. echo "(q) Quit"
  318. echo ""
  319. echo -ne "COMMUNITYSERVER DB install type: "
  320. read CSASK
  321. case "$CSASK" in
  322. "f"|"F") cs_cleanup I;;
  323. "u"|"U") cs_upgrade U;;
  324. "s"|"S") gs_backup;;
  325. "q"|"Q") finish;;
  326. *) cs_ask;;
  327. esac
  328. }
  329. cs_cleanup(){
  330. clear
  331. echo "Deleting Community Server tables for new content."
  332. $MYC < cs_cleanup.sql
  333. cs_install
  334. }
  335. cs_upgrade(){
  336. clear
  337. echo ""
  338. echo "Upgrading structure of Community Server tables."
  339. echo ""
  340. for file in $(ls ../sql/community/updates/*sql);do
  341. $MYC --force < $file 2>> cs_error.log
  342. done
  343. cs_install
  344. }
  345. cs_install(){
  346. clear
  347. if [ "$1" == "I" ]; then
  348. echo ""
  349. echo "Installing new Community Server content."
  350. echo ""
  351. else
  352. echo ""
  353. echo "Upgrading Community Server content."
  354. echo ""
  355. fi
  356. for cb in $(ls ../sql/community/*.sql);do
  357. echo "Installing Communityserver table : $cb"
  358. $MYC < $cb
  359. done
  360. gs_ask
  361. }
  362. gs_backup(){
  363. while :
  364. do
  365. clear
  366. echo ""
  367. echo -ne "Do you want to make a backup copy of your GSDB? (y/n): "
  368. read GSB
  369. if [ "$GSB" == "Y" -o "$GSB" == "y" ]; then
  370. echo "Trying to create a Game Server DataBase."
  371. $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > gs_backup.sql
  372. if [ $? -ne 0 ];then
  373. clear
  374. echo ""
  375. echo "There was a problem accesing your GS database, either it wasnt created or authentication data is incorrect."
  376. exit 1
  377. fi
  378. break
  379. elif [ "$GSB" == "n" -o "$GSB" == "N" ]; then
  380. break
  381. fi
  382. done
  383. gs_ask
  384. }
  385. gs_ask(){
  386. clear
  387. echo ""
  388. echo "GAME SERVER DATABASE install:"
  389. echo ""
  390. echo "(f) Full: WARNING! I'll destroy ALL of your existing character"
  391. echo " data (i really mean it: items, pets.. ALL)"
  392. echo ""
  393. echo "(u) Upgrade: I'll do my best to preserve all of your character"
  394. echo " data."
  395. echo ""
  396. echo "(s) Skip: We'll get into the last set of questions (cummulative"
  397. echo " updates, custom stuff...)"
  398. echo ""
  399. echo "(q) Quit"
  400. echo ""
  401. echo -ne "GAMESERVER DB install type: "
  402. read GSASK
  403. case "$GSASK" in
  404. "f"|"F") gs_cleanup I;;
  405. "u"|"U") gs_upgrade U;;
  406. "s"|"S") custom_ask;;
  407. "q"|"Q") finish;;
  408. *) gs_ask;;
  409. esac
  410. }
  411. gs_cleanup(){
  412. clear
  413. echo "Deleting all Game Server tables for new content."
  414. $MYG < gs_cleanup.sql
  415. gs_install
  416. }
  417. gs_upgrade(){
  418. clear
  419. echo ""
  420. echo "Upgrading structure of Game Server tables (this could take awhile, be patient)"
  421. echo ""
  422. for file in $(ls ../sql/game/updates/*.sql);do
  423. $MYG --force < $file 2>> gs_error.log
  424. done
  425. gs_install
  426. }
  427. gs_install(){
  428. clear
  429. if [ "$1" == "I" ]; then
  430. echo ""
  431. echo "Installing new Game Server content."
  432. echo ""
  433. else
  434. echo ""
  435. echo "Upgrading Game Server content."
  436. echo ""
  437. fi
  438. for gs in $(ls ../sql/game/*.sql);do
  439. echo "Installing GameServer table : $gs"
  440. $MYG < $gs
  441. done
  442. custom_ask
  443. }
  444. custom_ask(){
  445. clear
  446. echo ""
  447. echo "L2J provides some Custom Server Tables for non-retail modifications"
  448. echo "in order to avoid override the original Server Tables."
  449. echo ""
  450. echo "Remember that in order to get these additions actually working"
  451. echo "you need to edit your configuration files."
  452. echo ""
  453. echo -ne "Install Custom Server Tables: (y) yes or (n) no ?"
  454. read CSASK
  455. case "$CSASK" in
  456. "y"|"Y") custom_install;;
  457. "n"|"N") mod_ask;;
  458. *) custom_ask;;
  459. esac
  460. }
  461. custom_install(){
  462. clear
  463. echo ""
  464. echo "Installing Custom content."
  465. for custom in $(ls ../sql/game/custom/*.sql);do
  466. echo "Installing custom table: $custom"
  467. $MYG < $custom
  468. done
  469. clear
  470. mod_ask
  471. }
  472. mod_ask(){
  473. clear
  474. echo ""
  475. echo "L2J provides a basic infraestructure for some non-retail features"
  476. echo "(aka L2J mods) to get enabled with a minimum of changes."
  477. echo ""
  478. echo "Some of these mods would require extra tables in order to work"
  479. echo "and those tables could be created now if you wanted to."
  480. echo ""
  481. echo "Remember that in order to get these additions actually working"
  482. echo "you need to edit your configuration files."
  483. echo ""
  484. echo -ne "Install Mod Server Tables: (y) yes or (n) no ?"
  485. read MDASK
  486. case "$MDASK" in
  487. "y"|"Y") mod_install;;
  488. "n"|"N") finish;;
  489. *) mod_ask;;
  490. esac
  491. }
  492. mod_install(){
  493. clear
  494. echo ""
  495. echo "Installing Mods content."
  496. for mod in $(ls ../sql/game/mods/*.sql);do
  497. echo "Installing custom mod table : $mod"
  498. $MYG < $mod
  499. done
  500. clear
  501. finish
  502. }
  503. finish(){
  504. clear
  505. echo "L2JDP Database Installer"
  506. echo ""
  507. echo "Thanks for using our software."
  508. echo "visit http://www.l2jdp.com for more info about"
  509. echo "the L2J DataPack Project."
  510. exit 0
  511. }
  512. clear
  513. load_config $1
  514. MYL="$MYSQLPATH -h $LSDBHOST -u $LSUSER --password=$LSPASS -D $LSDB"
  515. MYG="$MYSQLPATH -h $GSDBHOST -u $GSUSER --password=$GSPASS -D $GSDB"
  516. MYC="$MYSQLPATH -h $CBDBHOST -u $CBUSER --password=$CBPASS -D $CBDB"
  517. ls_backup