Attempting to automate commit using a .bat

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Attempting to automate commit using a .bat

Post by Crosine » Wed Jul 22, 2015 11:04 pm

Good evening everyone. So I have been working the past few days building a .bat to completely automate my server and so far I have completed it to about 80%. At this point in time I have run into wall trying to figure out how to create a .bat script that will commit to master from my current project to my git hub account using the steps in this guide starting at the Commit section viewtopic.php?f=11&t=2568. So I have 2 questions if anyone could be kind enough to answer for me.

1. When you do a fresh clone from https://DarkstarProject/darkstar, is this always the most current updated repository?

2. Does anyone possibly have and example .bat that would commit my server build to my github URL? In addition to this, I would like to be able to execute the .bat from a folder seperate than the darkstar install server if that is possible as I keep all my .bat files in a seperate backup folder for execution.

Thank you in advance as the second question is driving me crazy to try and code :shock:

User avatar
demolish
Developer
Posts: 262
Joined: Thu Jul 26, 2012 7:12 am

Re: Attempting to automate commit using a .bat

Post by demolish » Thu Jul 23, 2015 5:32 pm

1) yes, but you don't need to clone every time, just pull
2) should just be able to stick the git commandline command crap in the bat and run

for 2, you'll need to find the commandline crap for: commit all changes with message, pull, push to remote
with remote being your fork
oh and make sure git is in your PATH variable crap (i don't linux so w/e)
<Giblet[NewBrain]> kj with this first step would be fine on my shit
Click here for a guide on scripting missions.

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Re: Attempting to automate commit using a .bat

Post by Crosine » Fri Jul 24, 2015 1:04 pm

Thanks for the reply Demolish. I was able to figure it out with the help from a few online guides and a LOT of patience. As far as making sure the push path is correct I have it saved to auto push to my directory only. Mainly since I am still an uber novice at scripting it will probably be a good while yet before I start working on unfinished quests etc. to actually be helpful to the project and start submitting scripts for fixes. :oops: I just want to thank everyone here again for all your hard work and for the help with some of the problems I have run into. Will post again with any help or future issues. In the meantime stay awesome everyone. 8-)

Delaide
Posts: 478
Joined: Sat Jun 14, 2014 8:58 am

Re: Attempting to automate commit using a .bat

Post by Delaide » Fri Jul 24, 2015 9:33 pm

Question, is it possible for you to post what you have, editing out certain details? Then someone else who reads this post can find an answer, instead of just repeating the same questions.

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Re: Attempting to automate commit using a .bat

Post by Crosine » Sat Jul 25, 2015 4:39 pm

Of course I will. :D You guys have done so much to help me out so far its only fair that I share the discoveries I make along the way. I will make a separate post following this with a tutorial on how I got things to work. Just so you have fair warning I am sure there are much cleaner solutions than what I came up with but it works. I have tested this method for the last 24 hours and it cycles perfectly. Let me throw a quick guide together and I will post soon.

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Re: Attempting to automate commit using a .bat

Post by Crosine » Sat Jul 25, 2015 6:22 pm

Alrighty, here is the process I use to automate a complete backup, update, recompile and commit. Bare with me as I have never written a guide for anything of this nature as I consider myself still a novice when it comes to this kind of thing. I will try to do my best and make it as uncomplicated as possible. :)

I use 7 folders to produce the results from this .bat. A character backup folder, a settings backup folder, a darkstar clone backup folder, a server backup folder, an auto pull folder, an auto commit folder and of course the actual darkstar folder used to install and run your server. Anyone who wishes to use this will have some minor editing to do but I entered in the instructions of what goes where after the "=" in the top of the script section. That being said there are a few things to remember as you navigate your way through here:

- at the end of this guide are links to setup remote paths as well as generating keys to allow this process to execute properly without entering in username, password, or passphrase

- you only need to change the values after the "=" sign and the code will do the rest. ie: SET CHARACTER BACKUP FOLDER=(C:\Users\YOU\EDIT\THIS\PATH\TO\YOUR\FOLDER)

- deleting any of these line commands could potentially break your process, so try to leave the code intact minus the editing you must do

- you need to have a folder corresponding to the various paths to run this, otherwise it will not cycle through the whole process, the folders are as follows; Character Backup Folder, Darkstar Install Folder, Settings Backup Folder, Server Backup Folder, Darkstar Clone Backup Folder, Auto Pull Folder, and Auto Commit Folder

- copy and paste from "Start Copy" down to "End Copy" in this post into notepad

- once your values have been edited you must save the file as a .bat, then its just a one click and walk away till its finished (start to finish is approximately 10 minutes or less for the whole process)

- at the end of this code I will also be including another code for auto pulling and auto committing and auto pulling that should be saved as .sh files

- when setting up your final commit DO NOT USE HTTPS://GIT@GITHUB.COM:DARKSTARPROJECT/DARKSTAR AS YOUR COMMIT ADDRESS (I would assume it is password protected but none the less when you push your commit it MUST BE YOUR REPOSITORY)

@ECHO "START COPY"

SET SERVER PASSWORD=SERVER PASSWORD
SET CHARACTER BACKUP FOLDER=PATH TO CHARACTER BACKUPS FOLDER
SET DARKSTAR INSTALL FOLDER=PATH TO SERVER INSTALL FOLDER
SET SETTINGS BACKUP FOLDER=PATH TO SETTINGS BACKUPS FOLDER
SET SERVER BACKUP FOLDER=PATH TO SERVER BACKUP FOLDER
SET DARKSTAR CLONE BACKUP FOLDER=PATH TO DARKSTAR CLONE BACKUP FOLDER
SET AUTO PULL FOLDER=PATH TO AUTO PULL FOLDER
SET AUTO COMMIT FOLDER=PATH TO AUTO COMMIT FOLDER

@ECHO "Character And Settings Backup"

c:
cd C:\Program Files\MySQL\MySQL Server 5.6\bin
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb auction_house > "%CHARACTER BACKUP FOLDER%\auction_house.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb accounts > "%CHARACTER BACKUP FOLDER%\accounts.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb accounts_banned > "%CHARACTER BACKUP FOLDER%\accounts_banned.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_effects > "%CHARACTER BACKUP FOLDER%\char_effects.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_equip > "%CHARACTER BACKUP FOLDER%\char_equip.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_exp > "%CHARACTER BACKUP FOLDER%\char_exp.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_inventory > "%CHARACTER BACKUP FOLDER%\char_inventory.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_jobs > "%CHARACTER BACKUP FOLDER%\char_jobs.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_look > "%CHARACTER BACKUP FOLDER%\char_look.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_pet > "%CHARACTER BACKUP FOLDER%\char_pet.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_pet_name > "%CHARACTER BACKUP FOLDER%\char_pet_name.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_points > "%CHARACTER BACKUP FOLDER%\char_points.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_profile > "%CHARACTER BACKUP FOLDER%\char_profile.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_skills > "%CHARACTER BACKUP FOLDER%\char_skills.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_stats > "%CHARACTER BACKUP FOLDER%\char_stats.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_storage > "%CHARACTER BACKUP FOLDER%\char_storage.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_vars > "%CHARACTER BACKUP FOLDER%\char_vars.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb char_weapon_skill_points > "%CHARACTER BACKUP FOLDER%\char_weapon_skill_points.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb chars > "%CHARACTER BACKUP FOLDER%\chars.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb conquest_system > "%CHARACTER BACKUP FOLDER%\conquest_system.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb delivery_box > "%CHARACTER BACKUP FOLDER%\delivery_box.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb linkshells > "%CHARACTER BACKUP FOLDER%\linkshells.sql"
mysqldump.exe -e -uroot -p%SERVER PASSWORD% dspdb > "%CHARACTER BACKUP FOLDER%\dspdb.sql"
C:
CD "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\lan_config.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\login_darkstar.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\map_darkstar.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\packet_darkstar_tcp.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\packet_darkstar_udp.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\search_server.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\server_message.conf" "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\conf\server_message_fr.conf" "%SETTINGS BACKUP FOLDER%"
C:
CD "%DARKSTAR INSTALL FOLDER%\darkstar\scripts\globals"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%\darkstar\scripts\globals\settings.lua" "%SETTINGS BACKUP FOLDER%"

@ECHO "Shadowlyre Server Backup"

C:
cd "%DARKSTAR INSTALL FOLDER%"
xcopy /s/q/y "%DARKSTAR INSTALL FOLDER%" "%SERVER BACKUP FOLDER%"

@ECHO "Darkstar Database Update"

C:
cd "%DARKSTAR CLONE BACKUP FOLDER%"
call "%AUTO PULL FOLDER%\Darkstar_Pull_Request.sh"

@ECHO "Shadowlyre Server Update"

C:
cd "%DARKSTAR INSTALL FOLDER%"
call "%AUTO PULL FOLDER%\Server_Pull_Request.sh"

@ECHO "Shadowlyre Server Rebuild"

"C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "%DARKSTAR INSTALL FOLDER%\darkstar\win32\darkstar.sln" /p:Configuration=DEBUG

@ECHO "Character And Settings Restore"

C:
CD "%CHARACTER BACKUP FOLDER%"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\auction_house.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\accounts.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\accounts_banned.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_effects.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_equip.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_exp.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_inventory.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_jobs.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_look.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_pet.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_pet_name.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_points.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_profile.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_skills.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_stats.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_storage.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_vars.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\char_weapon_skill_points.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\chars.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\conquest_system.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\delivery_box.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\linkshells.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
xcopy /s/q/y "%CHARACTER BACKUP FOLDER%\dspdb.sql" "%DARKSTAR INSTALL FOLDER%\darkstar\sql"
C:
CD "%SETTINGS BACKUP FOLDER%"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\lan_config.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\login_darkstar.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\map_darkstar.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\packet_darkstar_tcp.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\packet_darkstar_udp.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\search_server.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\server_message.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\server_message_fr.conf" "%DARKSTAR INSTALL FOLDER%\darkstar\conf"
xcopy /s/q/y "%SETTINGS BACKUP FOLDER%\settings.lua" "%DARKSTAR INSTALL FOLDER%\darkstar\scripts\globals"

@ECHO "Shadowlyre Server Commit"

C:
cd "%AUTO COMMIT FOLDER%"
call "%AUTO COMMIT FOLDER%\Server_Commit.sh"

@ECHO "END COPY"



The following codes needs to be saved as a .sh file in your auto pull folder so your call knows where it is to run the commands to auto pull. Please note that you need to create 2 separate .sh files in this section. One to point to your server install and one to point to your clone backup. These should be named to mirror the respective .sh files in sections "Darkstar Database Update" and "Server Update".

----------
.SH FILE 1
----------

SET DARKSTAR INSTALL FOLDER=PATH TO SERVER INSTALL FOLDER

cd "%DARKSTAR INSTALL FOLDER%\darkstar"
git init
git status
git remote add upstream "http://github.com/DarkstarProject/darkstar.git"
git pull remote upstream master

----------
.SH FILE 2
----------

SET DARKSTAR CLONE BACKUP FOLDER=PATH TO DARKSTAR CLONE BACKUP FOLDER

cd "%DARKSTAR CLONE BACKUP FOLDER%\darkstar"
git init
git status
git remote add upstream "http://github.com/DarkstarProject/darkstar.git"
git pull remote upstream master



The following code needs to be saved as a .sh file in your auto commit folder so your call knows where it is to run the commands to auto commit:

SET DARKSTAR INSTALL FOLDER=PATH TO SERVER INSTALL FOLDER

cd "%DARKSTAR INSTALL FOLDER%"
git init
git status
git add -A
git commit -am 'Auto Commit'
git remote add origin "git@github.com:<YOURUSERNAME:YOUR REPOSITORY>.git"
git push origin master

Now before you run the whole process you will need to follow the steps in these guides to get everything setup properly:

viewtopic.php?f=11&t=2568

https://help.github.com/articles/generating-ssh-keys/

If anyone has any questions hit me up and I will do my best to assist.
Last edited by Crosine on Sun Jul 26, 2015 11:12 pm, edited 6 times in total.

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Attempting to automate commit using a .bat

Post by kjLotus » Sat Jul 25, 2015 7:34 pm

why would you remove your darkstar folder and then check it out again? why don't you just pull?

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Re: Attempting to automate commit using a .bat

Post by Crosine » Sun Jul 26, 2015 10:46 am

If someone more knowledgeable with programming wants to change that portion to pull they can do so. This is the first actual programming script of any kind I have ever written and as I only update once a week or so I like to keep an unaltered original from darkstar saved, just in case something goes wrong and I need it (I am as newb as they get and kinda OCD about keeping backups of everything lol). That being said, I haven't quite figured out the whole pull process to just use that instead but if/when I do I will be sure to edit this to include it. This is just the process I prefer to use at the present time, anyone who uses this script is more than welcome to make changes to fit their setup. :D If you know the cmd line to change this to pull instead of copy over the fresh repository I would be glad to alter that in its place after testing it. Thanks again for your hard work everyone and stay awesome. 8-)

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: Attempting to automate commit using a .bat

Post by kjLotus » Sun Jul 26, 2015 1:25 pm

you do "git pull" instead of removing the directory and cloning new one

Crosine
Posts: 49
Joined: Wed Sep 10, 2014 9:32 pm

Re: Attempting to automate commit using a .bat

Post by Crosine » Sun Jul 26, 2015 2:51 pm

I wrote a separate cmd line .sh to test out the pull request. I will put it inside the overall script to test it out and verify that it still functions before I edit the post. If someone could just help me to verify real quick, when you perform a pull request:

1. It needs to be the origin master branch you are pulling from correct?

2. This can be done to your already existing darkstar server install and it will only update the changes made to the origin master branch?

Thanks in advance and eagerly await your replies. Stay awesome 8-)

Post Reply