 Hey, what's up everybody? My name is John Hammond and welcome back to another YouTube video and tutorial We're checking out some more stuff in our repository that we just created. I called mine tutorials You can obviously name yours whatever you'd like But it is pretty much just a repository right now that has nothing really in it But we want to start to fill it with some stuff So right now it just has a simple read me that is a simple markdown file But let's say we want to actually start to put some code in here Let's do that Well, let's say we're at least gonna start to put like a generic a template Code like some maybe how about a bash script for one thing a bash script that we can set up to At least have multiple versions of this bash script So that's why we're gonna start with a template or a blueprint But something will help set up other services or other software for us in the future Because I've got a couple ideas of some some software and some services that I'd like to be able to set up And I'd like to be able to automate that process and all the configuration installation that we actually have to do So let's start with the bare bone basics. Let's actually just get a template set up for us But in our repository, let's go ahead and make that. Let's make directory bash Templates and we want to call it bash template. I don't know. I don't know we want to call it Let's just call it template Scripts template script. Okay, so in template script. We'll have another read me So in sublime text, I'll just say template script This code is a simple bash script Let's get some let's get some links in here in our markdown file just to make it like good practice Bash if I google bash. Okay, cool. We do get the first result to be some good stuff Let's make that denoted in code and then let's get a bit of a list down here for it This is just simple markdown syntax for it. This code is a simple bash script that is Used to be a general purpose. Oh I'll zoom in on this by the way, sorry starting point and springboard Springboard is springboard one word or two words whatever for future scripts to help automate the process of installing or configuring Any form of software or services The main script you run is Let's call it setup.sh I want to make that a link as well to our setup.sh script So now let's create that setup.sh scripts. Oh, I just did save as I didn't want to do that. Did I do that? Yeah LS RM setup.sh Now we'll just get a new one setup.sh Cool, and I have a header that starts for me just because I have the file headers package installable sublimetex I think that's file header. Yeah, yeah, yeah So if you did install package if you have that's the package control set up in sublime text You can just do file header and that would be the package you would want to install to set that all up for us So, okay, sure here we are here. We are in bash in our new script and Let's for one thing get some comments going let's get a little bit more information. So what we're doing template scripts And I'll try and make this model after that markdown scripts in In fact, I'll take the same code the same information from our repository And just throw it in there. Whoa, can I word wrap that? Wrap Word wrap? Oh God I ruined it. I ruined everything Yeah, there's got to be a way to Doesn't look any better. I liked it better what I had before Oh gosh turn off word wrap. All right, fine Let's actually move on to the software portion of it Let's let's create some variables that define what this is that we're actually trying to put together This is all very general purpose keep in mind So all this stuff is going to be able to be changed later So if for whatever reason we're trying to configure or set up a little bit of software We're gonna have variables that you as the user or you as a person installing probably are going to be able to want to change For lingo and for jargon Purpose jargon purpose if that's a thing Like for semantics wise and for the for context, I'm gonna call these external variables Things that you may change Things that the user may change That the user may change. I'll just keep this all on one line and let's call that service Actually, that's probably gonna be an internal variable, right? Because internal variables are gonna be things if we're if we're rolling with that mindset of external variables or things the user may change Internal variables are gonna be things that the user probably shouldn't change Because that's gonna be what you set up. So right now. This is just gonna be a template, right? and We're probably gonna have dependencies and stuff that we need to be able to work with and install right now I'm gonna make that a empty string and just for Readability I think in our script will have some colors and we can set that up with different different variables I'm not actually enable those colors since we're in bash and so we're like the Linux console I'm actually gonna use the t-put command if you've never heard of that can man t-put really a little about that When we can use it to actually sit on colors so I can use t-puts set Foreground one and that will make it red if then I think if I echo Hello now my you see the string that I echo out is in that color and it's been reset because of my prompt But we should be able to use that just fine if I use the back ticks can use t-put set af One will give us red. What is the other one? Okay, two is green What else is there and then oh? Three three is yellow. Okay, and then these syntax actually turn off color So I'm gonna say NC for no color. I'm just gonna make that SGR zero. That's a syntax to turn off color. Cool So the external variables things that we don't want to change I guess We don't have anything for right now We don't sense if things that are be specific to configuring the service Now let's actually get down to more function stuff. Let's actually make it do, you know things, right? So we're gonna want a main function obviously and that will be the start that will be where it tells us for one thing let's have it display out our colors for us and Let's have it display the name of the program first and Then green setting up the service or whatever it is that we're actually setting up for us And then we'll turn off color. It's a little NC and then we'll exit Successfully if after we're done doing stuff and since we're doing stuff Just for a template purposes, let's actually have a function that does stuff And now rather than using the dollar sign zero to the name of the program. Let's actually make that The funk name that is a special variable in bash that actually refers to The function that you're currently calling so it's kind of cool. I just saw that doing stuff I Saw that on another video that a metal X a thousand who is an awesome YouTuber if you don't actually know him check out youtube.com forward slash Metal X a thousand. He's a really great Linux Linux guy So let's that's pretty much obviously the core of what it does But since it's gonna be able to do stuff over and over again do other things etc etc later on in the main function But what happens if something goes wrong, right? We want to be able to make sure at least be able to see it and stop our script if something happens that we Don't want to go wrong, right? Let's put our do stuff back in there So let's have a function like panic if something goes wrong and what we'll do is we'll echo Let's call this. Let's still put the function name Because now we're panicking and we'll say just something like fatal error Aborting and let's actually put that in red. Oh red turn off color and Now exit So our do stuff function we'll have multiple of these that's actually just kind of document we have so far We'll have multiple do stuff functions that do different things and then panic When something goes wrong We can use this in the script With bashes or syntax These are two vertical pipes, so we'll know if one command fails or not easy enough, right? Another thing that we're actually actually going to want to be able to do is actually install the dependencies So if for whatever reason we actually do have dependencies, let's actually set those up Just a baseline function that will actually install those Install dependencies and we'll just type that same echo statement Installing dependencies and that's just a simple app get call Oh, actually normally we since we'd be running like a pseudo app get install. Oh We're probably gonna have to create a script that will verify or a functional verify if we're running the script as root, right? Yeah, yeah, yeah, we'll definitely have to create that so otherwise since we're not gonna call with pseudo We didn't we can remove that let's update for one thing and then following that We'll use the bash syntax and after that app to get pass in why so they automatically accept Yes, and then we'll send in our dependencies and then we can we can actually use our panic our Panic function, which is created there And we're using the dependencies variable that we created up top at the very beginning of our script I'm sorry. I probably should have had this all full screen this entire time. I'm sorry Okay, so now we can install dependencies as part of our script and In the main function, right and What else is there? Oh, I'm sorry that that Verify root function we can set up for us just a little bit of documentation for one thing. Okay Function and verify root and that's just a simple if statement, right? Because we just want to test if the user is actually calling this as root. So if Bash syntax here, I'm gonna use the string of UID because we know in the terminal We can echo out UID and that should be zero if we are root. So if I pseudo echo UID Get on my password Should be Is that right? So you're a bash echo UID Should be zero. Yeah should be zero if it's not equal to zero Then we will do I'm sorry fi to end our if statement we can echo With the current name of the program and then red You must be root to run the script No color and I'll exit with a negative return code. So Cool Let's remove that extra space actually There you go. Make sure the user is running this as root So we can put that at the top of our main function Verify root and we'll just say that before actually do we want that to be a function? Because we don't know if we actually want If we're being general purpose here if we're trying to be Something we can replicate this earlier. We don't know if we actually want to be able to call this or not Sometimes the script probably won't have to run as root, right? Let's leave it. Let's leave it Yeah, let's leave it as a function and then still display later on now. We can install dependencies and do stuff That's pretty much all we need I think oh Of course, we actually have to do have to call the main function, right? So main and If we have kind of a pre declaration of all the functions just so we know what's going on We can just pass in all the variables that we already have. Oh, I'm sorry Also in our verify root since our we're interpreting the user ID variable as a string We shouldn't verify that this zero is also a string. So Call the main function passing in all past arguments so every function Has a pre declaration quote-unquote of all the functions Okay, let's see what happens when I try and run this. Can I run this? Let's make this executable So does H. Oh gotta be root awesome Cool. So now it's just updating and installing any dependencies which we shouldn't have Then we were able to see it to the very top Cool are doing stuff was doing stuff and it actually gives our function name right there and it says okay setting up the template Which would be Whatever our service is and install dependencies would be installing dependencies with our function name there Sweet so it looks like our template works pretty well Other than those weird comments at the top there whatever But that's pretty much all that we wanted to be able to do for now Because this gives us a good baseline to be able to work with any of their functions or any of their service or script that We're trying to set up for us. So okay, cool I got some good ideas. I think for services. We can try and automate and build for us. We'll be looking at Calree a little honeypot and I think I might do it with some other services like FTP or anything you might try to build and create configure on it in a Network that you're building. So sure. Hopefully we're good. Hopefully we're in a good spot. I hope you guys enjoyed it But before we go, let's actually add our changes and we'll put it in our global read me that we have Some new code Tutorial code this repository is home to Hopefully all of the code and Software that I produce for YouTube let's grab a YouTube link Okay, I probably don't even need YouTube I should learn to type guys. I'm sorry I Seriously should learn to type. Hopefully all the code and software that I produce for YouTube for use During any tutorial videos demonstrating How to set up automate automate Anything we deem necessary Contains the following folders and let's have our configured our template scripts, right? I'll make that a link and I'll make that bold Link to it there That's it for now I'll just take the same Journal per starting point of spring where future scripts help out the process any form of software services cool. I think we're good So now Think that's all I need. All right Let's get at the new read me and let's get at the entire template script folders now We can get commit added script added a template script for future Services software as our commit message Get pushed add this to the repository Log in to my username. We should be good now if we fire up Firefox Should be able to get to bit bucket org Let's go to my repository there Have to log in for one thing Hey, cool cool cool cool and the template script all add a new line in that This is just me being a perfectionist. Sorry. I tend to do this when I have a code in a repository Okay, cool, so now our template script is now accessible from our repository I will also bold that header and Now our setup script is available inside a repository and it should do everything that we've already told it to do Cool looks like we're ready to move on guys I know it took us a while, but we set up now a successful template script we can use later on and Any other service or thing that we actually try to build and create for us trying to automate the setup for So in the next couple of tutorials, let's do just that Let's try and automate the configuration installation of some services or some software. We actually want to set up like Calry Awesome. Thanks again guys. Hope you enjoyed this a little bit of bash programming a little bit of work with our repository and Other cool stuff. See you soon