database_installer.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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. asklogin(){
  183. clear
  184. echo "#############################################"
  185. echo "# WARNING: This section of the script CAN #"
  186. echo "# destroy your characters and accounts #"
  187. echo "# information. Read questions carefully #"
  188. echo "# before you reply. #"
  189. echo "#############################################"
  190. echo ""
  191. echo "Choose full (f) if you don't have and 'accounts' table or would"
  192. echo "prefer to erase the existing accounts information."
  193. echo "Choose skip (s) to skip loginserver DB installation and go to"
  194. echo "communityserver DB installation/upgrade."
  195. echo -ne "LOGINSERVER DB install type: (f) full, (s) skip or (q) quit? "
  196. read LOGINPROMPT
  197. case "$LOGINPROMPT" in
  198. "f"|"F") logininstall; loginupgrade; cbbackup; askcbtype;;
  199. "s"|"S") cbbackup; askcbtype;;
  200. "q"|"Q") finish;;
  201. *) asklogin;;
  202. esac
  203. }
  204. logininstall(){
  205. echo "Deleting loginserver tables for new content."
  206. $MYL < ls_cleanup.sql
  207. }
  208. loginupgrade(){
  209. clear
  210. echo "Installling new loginserver content."
  211. for login in $(ls ../sql/login/*.sql);do
  212. echo "Installing loginserver table : $login"
  213. $MYL < $login
  214. done
  215. }
  216. gsbackup(){
  217. while :
  218. do
  219. echo ""
  220. echo -ne "Do you want to make a backup copy of your GSDB? (y/n): "
  221. read LSB
  222. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  223. echo "Making a backup of the original gameserver database."
  224. $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > gs_backup.sql
  225. if [ $? -ne 0 ];then
  226. clear
  227. echo ""
  228. echo "There was a problem accesing your GS database, either it wasnt created or authentication data is incorrect."
  229. exit 1
  230. fi
  231. break
  232. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  233. break
  234. fi
  235. done
  236. }
  237. cbbackup(){
  238. while :
  239. do
  240. clear
  241. echo ""
  242. echo -ne "Do you want to make a backup copy of your CBDB? (y/n): "
  243. read LSB
  244. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  245. echo "Making a backup of the original communityserver database."
  246. $MYSQLDUMPPATH --add-drop-table -h $CBDBHOST -u $CBUSER --password=$CBPASS $CBDB > cs_backup.sql
  247. if [ $? -ne 0 ];then
  248. clear
  249. echo ""
  250. echo "There was a problem accesing your CB database, either it wasnt created or authentication data is incorrect."
  251. exit 1
  252. fi
  253. break
  254. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  255. break
  256. fi
  257. done
  258. }
  259. lsbackup(){
  260. while :
  261. do
  262. clear
  263. echo ""
  264. echo -ne "Do you want to make a backup copy of your LSDB? (y/n): "
  265. read LSB
  266. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  267. echo "Making a backup of the original loginserver database."
  268. $MYSQLDUMPPATH --add-drop-table -h $LSDBHOST -u $LSUSER --password=$LSPASS $LSDB > ls_backup.sql
  269. if [ $? -ne 0 ];then
  270. clear
  271. echo ""
  272. echo "There was a problem accesing your LS database, either it wasnt created or authentication data is incorrect."
  273. exit 1
  274. fi
  275. break
  276. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  277. break
  278. fi
  279. done
  280. }
  281. asktype(){
  282. echo ""
  283. echo ""
  284. echo "WARNING: A full install (f) will destroy all existing character data."
  285. echo -ne "GAMESERVER DB install type: (f) full install, (u) upgrade, (s) skip or (q) quit? "
  286. read INSTALLTYPE
  287. case "$INSTALLTYPE" in
  288. "f"|"F") fullinstall; upgradeinstall I; custom;;
  289. "u"|"U") upgradeinstall U; custom;;
  290. "s"|"S") custom;;
  291. "q"|"Q") finish;;
  292. *) asktype;;
  293. esac
  294. }
  295. askcbtype(){
  296. clear
  297. echo ""
  298. echo ""
  299. echo "WARNING: A full install (f) will destroy all existing community data."
  300. echo -ne "COMMUNITYSERVER DB install type: (f) full install, (u) upgrade, (s) skip or (q) quit? "
  301. read INSTALLTYPE
  302. case "$INSTALLTYPE" in
  303. "f"|"F") fullcbinstall; upgradecbinstall I; gsbackup; asktype;;
  304. "u"|"U") upgradecbinstall U; gsbackup; asktype;;
  305. "s"|"S") gsbackup; asktype;;
  306. "q"|"Q") finish;;
  307. *) asktype;;
  308. esac
  309. }
  310. fullcbinstall(){
  311. echo "Deleting all communityserver tables for new content."
  312. $MYC < cs_cleanup.sql
  313. }
  314. upgradecbinstall(){
  315. clear
  316. if [ "$1" == "I" ]; then
  317. echo "Installling new communityserver content."
  318. else
  319. echo "Upgrading communityserver content"
  320. fi
  321. if [ "$1" == "I" ]; then
  322. for cb in $(ls ../sql/community/*.sql);do
  323. echo "Installing Community Board table : $cb"
  324. $MYC < $cb
  325. done
  326. fi
  327. newbie_helper_cb
  328. }
  329. fullinstall(){
  330. clear
  331. echo "Deleting all gameserver tables for new content."
  332. $MYG < gs_cleanup.sql
  333. }
  334. upgradeinstall(){
  335. clear
  336. if [ "$1" == "I" ]; then
  337. echo "Installling new gameserver content."
  338. else
  339. echo "Upgrading gameserver content"
  340. fi
  341. for gs in $(ls ../sql/game/*.sql);do
  342. echo "Installing GameServer table : $gs"
  343. $MYG < $gs
  344. done
  345. newbie_helper
  346. }
  347. custom(){
  348. echo ""
  349. echo ""
  350. echo -ne "Install custom gameserver DB tables: (y) yes or (n) no or (q) quit?"
  351. read ASKCS
  352. case "$ASKCS" in
  353. "y"|"Y") cstinstall;;
  354. "n"|"N") finish;;
  355. "q"|"Q") finish;;
  356. *) custom;;
  357. esac
  358. finish
  359. }
  360. cstinstall(){
  361. while :
  362. do
  363. clear
  364. echo ""
  365. echo -ne "Do you want to make another backup of GSDB before applying custom contents? (y/N): "
  366. read LSB
  367. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  368. echo "Making a backup of the default gameserver tables."
  369. $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > custom_backup.sql 2> /dev/null
  370. if [ $? -ne 0 ];then
  371. echo ""
  372. echo "There was a problem accesing your GS database, server down?."
  373. exit 1
  374. fi
  375. break
  376. elif [ "$LSB" == "n" -o "$LSB" == "N" -o "$LSB" == "" ]; then
  377. break
  378. fi
  379. done
  380. clear
  381. echo "Installing custom content."
  382. for custom in $(ls ../sql/game/custom/*.sql);do
  383. echo "Installing custom table: $custom"
  384. $MYG < $custom
  385. done
  386. # L2J mods that needed extra tables to work properly, should be
  387. # listed here. To do so copy & paste the following 6 lines and
  388. # change them properly:
  389. # MOD: Wedding.
  390. echo -ne "Install "Wedding Mod" tables? (y/N): "
  391. read modprompt
  392. if [ "$modprompt" == "y" -o "$modprompt" == "Y" ]; then
  393. for mod in $(ls ../sql/game/mods/*.sql);do
  394. echo "Installing custom mod table : $mod"
  395. $MYG < $mod
  396. done
  397. fi
  398. finish
  399. }
  400. finish(){
  401. clear
  402. echo "Script execution finished."
  403. echo ""
  404. echo "L2JDP database_installer version 0.2.2"
  405. echo "(C) 2007-2011 L2J Datapack Team"
  406. echo "database_installer comes with ABSOLUTELY NO WARRANTY;"
  407. echo "This is free software, and you are welcome to redistribute it"
  408. echo "under certain conditions; See the file gpl.txt for further"
  409. echo "details."
  410. echo ""
  411. echo "Thanks for using our software."
  412. echo "visit http://www.l2jdp.com for more info about"
  413. echo "the L2J Datapack project."
  414. exit 0
  415. }
  416. newbie_helper(){
  417. while :
  418. do
  419. echo ""
  420. echo -ne "If you're not that skilled applying changes within 'updates' folder, i can try to do it for you (y). If you wish to do it on your own, choose (n). Should i parse updates files? (Y/n)"
  421. read NOB
  422. if [ "$NOB" == "Y" -o "$NOB" == "y" -o "$NOB" == "" ]; then
  423. clear
  424. echo ""
  425. echo "There we go, it may take some time..."
  426. echo "Installing Gameserver Updates"
  427. for file in $(ls ../sql/game/updates/*.sql);do
  428. $MYG --force < $file 2>> gserror.log
  429. done
  430. echo "Installing Loginserver Updates"
  431. for file in $(ls ../sql/login/updates/*.sql);do
  432. $MYL --force < $file 2>> lserror.log
  433. done
  434. break
  435. elif [ "$NOB" == "n" -o "$NOB" == "N" ]; then
  436. break
  437. fi
  438. done
  439. }
  440. newbie_helper_cb(){
  441. while :
  442. do
  443. echo ""
  444. echo -ne "If you're not that skilled applying changes within 'updates' folder, i can try to do it for you (y). If you wish to do it on your own, choose (n). Should i parse updates files? (Y/n)"
  445. read NOB
  446. if [ "$NOB" == "Y" -o "$NOB" == "y" -o "$NOB" == "" ]; then
  447. clear
  448. echo ""
  449. echo "There we go, it may take some time..."
  450. echo "updates parser results. Last run: "`date` >cb_database_installer.log
  451. for file in $(ls ../sql/community/updates/*sql);do
  452. echo $file|cut -d/ -f4 >> cb_database_installer.log
  453. $MYC --force < $file 2>> cb_database_installer.log
  454. if [ $? -eq 0 ];then
  455. echo "no errors">> cb_database_installer.log
  456. fi
  457. done
  458. clear
  459. echo ""
  460. echo "Log available at $(pwd)/cb_database_installer.log"
  461. echo ""
  462. break
  463. elif [ "$NOB" == "n" -o "$NOB" == "N" ]; then
  464. break
  465. fi
  466. done
  467. }
  468. clear
  469. load_config $1
  470. MYL="$MYSQLPATH -h $LSDBHOST -u $LSUSER --password=$LSPASS -D $LSDB"
  471. MYG="$MYSQLPATH -h $GSDBHOST -u $GSUSER --password=$GSPASS -D $GSDB"
  472. MYC="$MYSQLPATH -h $CBDBHOST -u $CBUSER --password=$CBPASS -D $CBDB"
  473. lsbackup
  474. asklogin