Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. include .env
  2. #########################################
  3. ##### Production Scripts #####
  4. #########################################
  5. # Creates a database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  6. # Call via "make backup-mariadb db=cabbage"
  7. backup-mariadb:
  8. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  9. mkdir -p $(MYSQL_DUMPS_DIR)
  10. chmod -R 777 $(MYSQL_DUMPS_DIR)
  11. mkdir -p $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
  12. chmod -R 777 $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
  13. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false | gzip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`/`date "+%Y%m%d-%H%M-%Z"`-${db}.sql.gz
  14. # Remove unnecessary data from database after 3 months.
  15. # Call via "make purge-old-logs db=cabbage"
  16. purge-old-logs:
  17. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  18. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM generic_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  19. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM droplogs WHERE ts < NOW() - INTERVAL 3 MONTH;"
  20. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM chat_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  21. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM trade_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  22. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM private_message_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  23. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM live_feeds WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  24. curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{ \"content\": \"\", \"embeds\": [ { \"title\": \"Clean-up of ${db} database completed.\", \"color\": 1087508, \"description\": \"Public, Private, and Global messages older than 3 months have been removed from the live database.\n\nAlso deleted were Generic logs (such as dropping items), logs of items received as drops by monsters, trade logs, and the live_feeds events older than 3 months.\n\nThese records now only exist in database backups.\" } ] }" $(TERMINAL_WEBHOOK)
  25. #########################################
  26. ##### End of Production Scripts #####
  27. #########################################
  28. #########################################
  29. ##### Development Scripts #####
  30. #########################################
  31. start-linux:
  32. `pwd`/Start-Linux.sh
  33. run-server:
  34. `pwd`/Deployment_Scripts/run.sh
  35. run-client:
  36. ant -f Client_Base/build.xml runclient
  37. combined-install:
  38. `pwd`/Deployment_Scripts/combined-install.sh
  39. get-updates:
  40. `pwd`/Deployment_Scripts/get-updates.sh
  41. compile:
  42. ant -f server/build.xml compile_core
  43. ant -f server/build.xml compile_plugins
  44. ant -f Client_Base/build.xml compile
  45. ant -f PC_Launcher/build.xml compile
  46. # Sets a specified username to be in a specified group in a specified database
  47. # Call via "make rank-mariadb db=cabbage group=0 username=wolf"
  48. rank-mariadb:
  49. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  50. @[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
  51. @[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
  52. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';"
  53. # Sets a specified username to be in a specified group in a specified database
  54. # Call via "make rank-sqlite db=cabbage group=0 username=wolf"
  55. rank-sqlite:
  56. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  57. @[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
  58. @[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
  59. sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';" ".exit"
  60. # Changes a specified username to be a new username in a specified database
  61. # Call via "make namechange-mariadb db=cabbage oldname=wolf newname=wolf2"
  62. namechange-mariadb:
  63. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  64. @[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
  65. @[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
  66. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';"
  67. # Changes a specified username to be a new username in a specified database
  68. # Call via "make namechange-sqlite db=cabbage oldname=wolf newname=wolf2"
  69. namechange-sqlite:
  70. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  71. @[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
  72. @[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
  73. sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';" ".exit"
  74. # Creates a database that the user specifies the name of
  75. # Call via "make create-mariadb db=cabbage"
  76. create-mariadb:
  77. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  78. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "create database ${db};"
  79. # Imports the core.sql file to a specified database
  80. # Call via "make import-authentic-mariadb db=preservation"
  81. import-authentic-mariadb:
  82. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  83. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
  84. # Imports the core.sqlite file to a specified database
  85. # Call via "make import-authentic-sqlite db=preservation"
  86. import-authentic-sqlite:
  87. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  88. cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
  89. # Imports the addon sql files to a specified database
  90. # Call via "make import-custom-mariadb db=cabbage"
  91. import-custom-mariadb:
  92. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  93. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
  94. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_auctionhouse.sql
  95. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_bank_presets.sql
  96. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_clans.sql
  97. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_equipment_tab.sql
  98. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_harvesting.sql
  99. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_npc_kill_counting.sql
  100. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_runecraft.sql
  101. # Imports the addon sqlite files to a specified database
  102. # Call via "make import-custom-sqlite db=cabbage"
  103. import-custom-sqlite:
  104. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  105. cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
  106. cat server/database/sqlite/addons/add_auctionhouse.sqlite | sqlite3 server/inc/sqlite/${db}.db
  107. cat server/database/sqlite/addons/add_bank_presets.sqlite | sqlite3 server/inc/sqlite/${db}.db
  108. cat server/database/sqlite/addons/add_clans.sqlite | sqlite3 server/inc/sqlite/${db}.db
  109. cat server/database/sqlite/addons/add_equipment_tab.sqlite | sqlite3 server/inc/sqlite/${db}.db
  110. cat server/database/sqlite/addons/add_npc_kill_counting.sqlite | sqlite3 server/inc/sqlite/${db}.db
  111. # Imports the retro.sql file to a specified database
  112. # Call via "make import-retro-mariadb db=2001scape"
  113. import-retro-mariadb:
  114. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  115. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/retro.sql
  116. # Imports the retro.sqlite file to a specified database
  117. # Call via "make import-retro-sqlite db=2001scape"
  118. import-retro-sqlite:
  119. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  120. rm server/inc/sqlite/${db}.db
  121. cat server/database/sqlite/retro.sqlite | sqlite3 server/inc/sqlite/${db}.db
  122. # Creates a database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  123. # Call via "make backup-mariadb-local db=cabbage"
  124. backup-mariadb-local:
  125. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  126. mkdir -p $(MYSQL_DUMPS_DIR)
  127. chmod -R 777 $(MYSQL_DUMPS_DIR)
  128. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false | zip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m%d-%H%M-%Z"`-${db}.zip
  129. # Creates a database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  130. # Call via "make backup-sqlite-local db=cabbage"
  131. backup-sqlite-local:
  132. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  133. mkdir -p $(MYSQL_DUMPS_DIR)
  134. chmod -R 777 $(MYSQL_DUMPS_DIR)
  135. echo .dump | sqlite3 server/inc/sqlite/${db}.db | zip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m%d-%H%M-%Z"`-${db}.zip
  136. # Unzips a database backup zip file in the output directory specified in the .env file and then imports it into the specified database as a database restoration from backup method
  137. # Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
  138. restore-mariadb-local:
  139. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  140. @[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
  141. unzip -p $(MYSQL_DUMPS_DIR)/${name} | mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db}
  142. # Unzips a database backup zip file in the output directory specified in the .env file and then imports it into the specified database as a database restoration from backup method
  143. # Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
  144. restore-sqlite-local:
  145. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  146. @[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
  147. rm server/inc/sqlite/${db}.db
  148. echo .read | unzip -p $(MYSQL_DUMPS_DIR)/${name} | sqlite3 server/inc/sqlite/${db}.db
  149. #########################################
  150. ##### End of Development Scripts #####
  151. #########################################