database_installer.sh 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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://l2jdp.com/trac ##
  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 l2jdb): "
  54. read LSDB
  55. if [ -z "$LSDB" ]; then
  56. LSDB="l2jdb"
  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. #GS
  74. echo -ne "\nPlease enter MySQL Game Server hostname (default $LSDBHOST): "
  75. read GSDBHOST
  76. if [ -z "$GSDBHOST" ]; then
  77. GSDBHOST="$LSDBHOST"
  78. fi
  79. echo -ne "\nPlease enter MySQL Game Server database name (default $LSDB): "
  80. read GSDB
  81. if [ -z "$GSDB" ]; then
  82. GSDB="$LSDB"
  83. fi
  84. echo -ne "\nPlease enter MySQL Game Server user (default $LSUSER): "
  85. read GSUSER
  86. if [ -z "$GSUSER" ]; then
  87. GSUSER="$LSUSER"
  88. fi
  89. echo -ne "\nPlease enter MySQL Game Server $GSUSER's password (won't be displayed): "
  90. stty -echo
  91. read GSPASS
  92. stty echo
  93. echo ""
  94. if [ -z "$GSPASS" ]; then
  95. echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
  96. elif [ "$GSUSER" == "$GSPASS" ]; then
  97. echo "You're not too brilliant choosing passwords huh?"
  98. fi
  99. save_config $1
  100. }
  101. save_config() {
  102. if [ -n "$1" ]; then
  103. CONF="$1"
  104. else
  105. CONF="database_installer.rc"
  106. fi
  107. echo ""
  108. echo "With these data I can generate a configuration file which can be read"
  109. echo "on future updates. WARNING: this file will contain clear text passwords!"
  110. echo -ne "Shall I generate config file $CONF? (Y/n):"
  111. read SAVE
  112. if [ "$SAVE" == "y" -o "$SAVE" == "Y" -o "$SAVE" == "" ];then
  113. cat <<EOF>$CONF
  114. #Configuration settings for L2J-Datapack database installer script
  115. MYSQLDUMPPATH=$MYSQLDUMPPATH
  116. MYSQLPATH=$MYSQLPATH
  117. LSDBHOST=$LSDBHOST
  118. LSDB=$LSDB
  119. LSUSER=$LSUSER
  120. LSPASS=$LSPASS
  121. GSDBHOST=$GSDBHOST
  122. GSDB=$GSDB
  123. GSUSER=$GSUSER
  124. GSPASS=$GSPASS
  125. EOF
  126. chmod 600 $CONF
  127. echo "Configuration saved as $CONF"
  128. echo "Permissions changed to 600 (rw- --- ---)"
  129. elif [ "$SAVE" != "n" -a "$SAVE" != "N" ]; then
  130. save_config
  131. fi
  132. }
  133. load_config() {
  134. if [ -n "$1" ]; then
  135. CONF="$1"
  136. else
  137. CONF="database_installer.rc"
  138. fi
  139. if [ -e "$CONF" ] && [ -f "$CONF" ]; then
  140. . $CONF
  141. else
  142. echo "Settings file not found: $CONF"
  143. echo "You can specify an alternate settings filename:"
  144. echo $0 config_filename
  145. echo ""
  146. echo "If file doesn't exist it can be created"
  147. echo "If nothing is specified script will try to work with ./database_installer.rc"
  148. echo ""
  149. configure $CONF
  150. fi
  151. }
  152. asklogin(){
  153. echo "#############################################"
  154. echo "# WARNING: This section of the script CAN #"
  155. echo "# destroy your characters and accounts #"
  156. echo "# information. Read questions carefully #"
  157. echo "# before you reply. #"
  158. echo "#############################################"
  159. echo ""
  160. echo "Choose full (f) if you don't have and 'accounts' table or would"
  161. echo "prefer to erase the existing accounts information."
  162. echo "Choose skip (s) to skip loginserver DB installation and go to"
  163. echo "gameserver DB installation/upgrade."
  164. echo -ne "LOGINSERVER DB install type: (f) full, (s) skip or (q) quit? "
  165. read LOGINPROMPT
  166. case "$LOGINPROMPT" in
  167. "f"|"F") logininstall; loginupgrade; gsbackup; asktype;;
  168. "s"|"S") gsbackup; asktype;;
  169. "q"|"Q") finish;;
  170. *) asklogin;;
  171. esac
  172. }
  173. logininstall(){
  174. echo "Deleting loginserver tables for new content."
  175. $MYL < login_install.sql &> /dev/null
  176. }
  177. loginupgrade(){
  178. echo "Installling new loginserver content."
  179. $MYL < ../sql/accounts.sql &> /dev/null
  180. $MYL < ../sql/account_data.sql &> /dev/null
  181. $MYL < ../sql/gameservers.sql &> /dev/null
  182. }
  183. gsbackup(){
  184. while :
  185. do
  186. echo ""
  187. echo -ne "Do you want to make a backup copy of your GSDB? (y/n): "
  188. read LSB
  189. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  190. echo "Making a backup of the original gameserver database."
  191. $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > gameserver_backup.sql
  192. if [ $? -ne 0 ];then
  193. echo ""
  194. echo "There was a problem accesing your GS database, either it wasnt created or authentication data is incorrect."
  195. exit 1
  196. fi
  197. break
  198. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  199. break
  200. fi
  201. done
  202. }
  203. lsbackup(){
  204. while :
  205. do
  206. echo ""
  207. echo -ne "Do you want to make a backup copy of your LSDB? (y/n): "
  208. read LSB
  209. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  210. echo "Making a backup of the original loginserver database."
  211. $MYSQLDUMPPATH --add-drop-table -h $LSDBHOST -u $LSUSER --password=$LSPASS $LSDB > loginserver_backup.sql
  212. if [ $? -ne 0 ];then
  213. echo ""
  214. echo "There was a problem accesing your LS database, either it wasnt created or authentication data is incorrect."
  215. exit 1
  216. fi
  217. break
  218. elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
  219. break
  220. fi
  221. done
  222. }
  223. asktype(){
  224. echo ""
  225. echo ""
  226. echo "WARNING: A full install (f) will destroy all existing character data."
  227. echo -ne "GAMESERVER DB install type: (f) full install, (u) upgrade, (s) skip or (q) quit? "
  228. read INSTALLTYPE
  229. case "$INSTALLTYPE" in
  230. "f"|"F") fullinstall; upgradeinstall I; custom;;
  231. "u"|"U") upgradeinstall U; custom;;
  232. "s"|"S") custom;;
  233. "q"|"Q") finish;;
  234. *) asktype;;
  235. esac
  236. }
  237. fullinstall(){
  238. echo "Deleting all gameserver tables for new content."
  239. $MYG < full_install.sql &> /dev/null
  240. }
  241. upgradeinstall(){
  242. if [ "$1" == "I" ]; then
  243. echo "Installling new gameserver content."
  244. else
  245. echo "Upgrading gameserver content"
  246. fi
  247. if [ "$1" == "I" ]; then
  248. $MYG < ../sql/access_levels.sql &> /dev/null
  249. $MYG < ../sql/admin_command_access_rights.sql &> /dev/null
  250. $MYG < ../sql/auction.sql &> /dev/null
  251. $MYG < ../sql/castle.sql &> /dev/null
  252. $MYG < ../sql/clanhall.sql &> /dev/null
  253. $MYG < ../sql/fort.sql &> /dev/null
  254. $MYG < ../sql/forums.sql &> /dev/null
  255. $MYG < ../sql/grandboss_data.sql &> /dev/null
  256. $MYG < ../sql/npc_buffer.sql &> /dev/null
  257. $MYG < ../sql/seven_signs_festival.sql &> /dev/null
  258. $MYG < ../sql/seven_signs_status.sql &> /dev/null
  259. fi
  260. $MYG < ../sql/armor.sql &> /dev/null
  261. $MYG < ../sql/armorsets.sql &> /dev/null
  262. $MYG < ../sql/auction_bid.sql &> /dev/null
  263. $MYG < ../sql/auction_watch.sql &> /dev/null
  264. $MYG < ../sql/auto_announcements.sql &> /dev/null
  265. $MYG < ../sql/auto_chat.sql &> /dev/null
  266. $MYG < ../sql/auto_chat_text.sql &> /dev/null
  267. $MYG < ../sql/castle_door.sql &> /dev/null
  268. $MYG < ../sql/castle_doorupgrade.sql &> /dev/null
  269. $MYG < ../sql/castle_functions.sql &> /dev/null
  270. $MYG < ../sql/castle_manor_procure.sql &> /dev/null
  271. $MYG < ../sql/castle_manor_production.sql &> /dev/null
  272. $MYG < ../sql/castle_siege_guards.sql &> /dev/null
  273. $MYG < ../sql/char_templates.sql &> /dev/null
  274. $MYG < ../sql/char_creation_items.sql &> /dev/null
  275. $MYG < ../sql/character_friends.sql &> /dev/null
  276. $MYG < ../sql/character_hennas.sql &> /dev/null
  277. $MYG < ../sql/character_macroses.sql &> /dev/null
  278. $MYG < ../sql/character_quests.sql &> /dev/null
  279. $MYG < ../sql/character_raid_points.sql &> /dev/null
  280. $MYG < ../sql/character_recipebook.sql &> /dev/null
  281. $MYG < ../sql/character_recommends.sql &> /dev/null
  282. $MYG < ../sql/character_shortcuts.sql &> /dev/null
  283. $MYG < ../sql/character_skills.sql &> /dev/null
  284. $MYG < ../sql/character_skills_save.sql &> /dev/null
  285. $MYG < ../sql/character_subclasses.sql &> /dev/null
  286. $MYG < ../sql/characters.sql &> /dev/null
  287. $MYG < ../sql/clan_data.sql &> /dev/null
  288. $MYG < ../sql/clan_privs.sql &> /dev/null
  289. $MYG < ../sql/clan_skills.sql &> /dev/null
  290. $MYG < ../sql/clan_subpledges.sql &> /dev/null
  291. $MYG < ../sql/clan_wars.sql &> /dev/null
  292. $MYG < ../sql/clanhall_functions.sql &> /dev/null
  293. $MYG < ../sql/class_list.sql &> /dev/null
  294. $MYG < ../sql/cursed_weapons.sql &> /dev/null
  295. $MYG < ../sql/dimensional_rift.sql &> /dev/null
  296. $MYG < ../sql/droplist.sql &> /dev/null
  297. $MYG < ../sql/enchant_skill_trees.sql &> /dev/null
  298. $MYG < ../sql/etcitem.sql &> /dev/null
  299. $MYG < ../sql/fish.sql &> /dev/null
  300. $MYG < ../sql/fishing_skill_trees.sql &> /dev/null
  301. $MYG < ../sql/fort_doorupgrade.sql &> /dev/null
  302. $MYG < ../sql/fort_functions.sql &> /dev/null
  303. $MYG < ../sql/fort_siege_guards.sql &> /dev/null
  304. $MYG < ../sql/fort_spawnlist.sql &> /dev/null
  305. $MYG < ../sql/fort_staticobjects.sql &> /dev/null
  306. $MYG < ../sql/fortsiege_clans.sql &> /dev/null
  307. $MYG < ../sql/four_sepulchers_spawnlist.sql &> /dev/null
  308. $MYG < ../sql/games.sql &> /dev/null
  309. $MYG < ../sql/global_tasks.sql &> /dev/null
  310. $MYG < ../sql/grandboss_list.sql &> /dev/null
  311. $MYG < ../sql/helper_buff_list.sql &> /dev/null
  312. $MYG < ../sql/henna.sql &> /dev/null
  313. $MYG < ../sql/henna_trees.sql &> /dev/null
  314. $MYG < ../sql/heroes.sql &> /dev/null
  315. $MYG < ../sql/item_attributes.sql &> /dev/null
  316. $MYG < ../sql/items.sql &> /dev/null
  317. $MYG < ../sql/itemsonground.sql &> /dev/null
  318. $MYG < ../sql/locations.sql &> /dev/null
  319. $MYG < ../sql/lvlupgain.sql &> /dev/null
  320. $MYG < ../sql/mapregion.sql &> /dev/null
  321. $MYG < ../sql/merchant_areas_list.sql &> /dev/null
  322. $MYG < ../sql/merchant_buylists.sql &> /dev/null
  323. $MYG < ../sql/merchant_lease.sql &> /dev/null
  324. $MYG < ../sql/merchant_shopids.sql &> /dev/null
  325. $MYG < ../sql/merchants.sql &> /dev/null
  326. $MYG < ../sql/minions.sql &> /dev/null
  327. $MYG < ../sql/npc.sql &> /dev/null
  328. $MYG < ../sql/npcskills.sql &> /dev/null
  329. $MYG < ../sql/olympiad_nobles.sql&> /dev/null
  330. $MYG < ../sql/olympiad_nobles_eom.sql&> /dev/null
  331. $MYG < ../sql/pets.sql &> /dev/null
  332. $MYG < ../sql/pets_skills.sql &> /dev/null
  333. $MYG < ../sql/pets_stats.sql &> /dev/null
  334. $MYG < ../sql/pledge_skill_trees.sql &> /dev/null
  335. $MYG < ../sql/posts.sql &> /dev/null
  336. $MYG < ../sql/quest_global_data.sql &> /dev/null
  337. $MYG < ../sql/raidboss_spawnlist.sql &> /dev/null
  338. $MYG < ../sql/random_spawn.sql &> /dev/null
  339. $MYG < ../sql/random_spawn_loc.sql &> /dev/null
  340. $MYG < ../sql/seven_signs.sql &> /dev/null
  341. $MYG < ../sql/siege_clans.sql &> /dev/null
  342. $MYG < ../sql/skill_learn.sql &> /dev/null
  343. $MYG < ../sql/skill_spellbooks.sql &> /dev/null
  344. $MYG < ../sql/skill_trees.sql &> /dev/null
  345. $MYG < ../sql/spawnlist.sql &> /dev/null
  346. $MYG < ../sql/teleport.sql &> /dev/null
  347. $MYG < ../sql/topic.sql &> /dev/null
  348. $MYG < ../sql/transform_skill_trees.sql &> /dev/null
  349. $MYG < ../sql/walker_routes.sql &> /dev/null
  350. $MYG < ../sql/weapon.sql &> /dev/null
  351. $MYG < ../sql/zone_vertices.sql &> /dev/null
  352. newbie_helper
  353. }
  354. custom(){
  355. echo ""
  356. echo ""
  357. echo -ne "Install custom gameserver DB tables: (y) yes or (n) no or (q) quit?"
  358. read ASKCS
  359. case "$ASKCS" in
  360. "y"|"Y") cstinstall;;
  361. "n"|"N") finish;;
  362. "q"|"Q") finish;;
  363. *) custom;;
  364. esac
  365. finish
  366. }
  367. cstinstall(){
  368. while :
  369. do
  370. echo ""
  371. echo -ne "Do you want to make another backup of GSDB before applying custom contents? (y/N): "
  372. read LSB
  373. if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
  374. echo "Making a backup of the default gameserver tables."
  375. $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > custom_backup.sql 2> /dev/null
  376. if [ $? -ne 0 ];then
  377. echo ""
  378. echo "There was a problem accesing your GS database, server down?."
  379. exit 1
  380. fi
  381. break
  382. elif [ "$LSB" == "n" -o "$LSB" == "N" -o "$LSB" == "" ]; then
  383. break
  384. fi
  385. done
  386. echo "Installing custom content."
  387. for custom in $(ls ../sql/custom/*.sql);do
  388. $MYG < $custom &> /dev/null
  389. done
  390. # L2J mods that needed extra tables to work properly, should be
  391. # listed here. To do so copy & paste the following 6 lines and
  392. # change them properly:
  393. # MOD: Wedding.
  394. echo -ne "Install "Wedding Mod" tables? (y/N): "
  395. read modprompt
  396. if [ "$modprompt" == "Y" -o "$LSB" == "y" ]; then
  397. $MYG < ../sql/mods/mods_wedding.sql &> /dev/null
  398. fi
  399. finish
  400. }
  401. finish(){
  402. echo ""
  403. echo "Script execution finished."
  404. exit 0
  405. }
  406. newbie_helper(){
  407. while :
  408. do
  409. echo ""
  410. 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)"
  411. read NOB
  412. if [ "$NOB" == "Y" -o "$NOB" == "y" -o "$NOB" == "" ]; then
  413. echo ""
  414. echo "There we go, it may take some time..."
  415. echo "updates parser results. Last run: "`date` >database_installer.log
  416. for file in $(ls ../sql/updates/*sql);do
  417. echo $file|cut -d/ -f4 >> database_installer.log
  418. $MYG < $file 2>> database_installer.log
  419. if [ $? -eq 0 ];then
  420. echo "no errors">> database_installer.log
  421. fi
  422. done
  423. echo ""
  424. echo "Log available at $(pwd)/database_installer.log"
  425. echo ""
  426. break
  427. elif [ "$NOB" == "n" -o "$NOB" == "N" ]; then
  428. break
  429. fi
  430. done
  431. }
  432. clear
  433. load_config $1
  434. MYL="$MYSQLPATH -h $LSDBHOST -u $LSUSER --password=$LSPASS -D $LSDB"
  435. MYG="$MYSQLPATH -h $GSDBHOST -u $GSUSER --password=$GSPASS -D $GSDB"
  436. lsbackup
  437. asklogin