database_installer.sh 13 KB

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