Scripting Server Customization & Setup With Bash

in #technology7 years ago (edited)

Scripting-Server-Customization-And-Setup-With-BASH.png

As you well know by now, I am a big nerd. Not the broken glasses and suspender-wearing kind but the learn as much about computers as I can kind. The more I learn, the more I find myself moving away from large desktop environments and window managers to the terminal. The terminal is fast, efficient, and does not hog system resources.

It is to a point now that if I can do it in the terminal then I do it in the terminal. Of course, some tasks are not well suited for a terminal. Just because I can read a webpage via the terminal does not mean it's the best tool for the job. The majority of websites use so much CSS and javascript that it becomes a nightmare to navigate through.

That being said, most of my workflow can be more efficient in the terminal via a headless server. No need for a super expensive laptop, all I need is one that can connect to the server of my choice. After a bit of tweaking the environment is exactly as I like it to be. Every aspect down to the color scheme and keyboard layout.

However, over time this simple tweaking has become a healthy chunk of my time to both set up and update. New servers need all the goods, and even with all the dotfiles in place at my Github account I still need to take time setting everything up. Installing packages and symlinking configuration files takes more time the more I use the terminal.

New Witness Server

My witness (and every witness) server has crossed the twenty-seven gibibytes of RAM (yes, gibibyte is the correct term for digital storage capacity). This is causing me to purchase a new monthly server package for my witness. If I do not, my server will start missing blocks once the RAM usage is at its maximum.

So I upped it to the sixty-four gibibyte package from @privex to stay ahead of the curve since my current package either needs to be renewed or shut down. This new server holds a Xenon E3 processor with four cores and eight threads, two 2TB hard drives, 64GB of RAM, and 20TB of bandwidth. I'm pretty stoked that I am able to afford a server this beastly and it's all thanks to you, Steemit!

In all honesty, this server would be so far past overkill for anything I do outside of witnessing for the Steem blockchain, but it is still cool to have control of a machine with so much RAM. I remember back when I first got into building computers and would have done (almost) anything for 1GB of RAM. Boy, have times changed!

However, this new server leads to the problem we mentioned earlier. I now am tasked with the job of setting the customizations to what works best for me. It may seem like OCD that I need to have a specific color scheme in Vim or an exact keybinding for tmux. But this all leads to better productivity in the long run and allows me to remember one set up instead of several.

automation-with-bash-script.jpg

Automation Through Bash Scripting

We covered Bash in a mini-series here a few months back, and since I only ever use Linux, I can use these types of scripts on all my machines. As you can see on my Github page, I already have dotfiles for my desktop and laptop (which will merge soon), but I don't have a repository for my server configuration.

This is because I have only recently gotten into heavily customizing my terminal experience to improve my productivity. I guess we can say that forcing myself to learn Vim started off the journey in its current form since that got me into editing the .vimrc file. Add in the move to i3wm for my desktop computer, and the ball is now rolling in full force.

This bash script is still in the works, so there are only a few lines I am able to share with you, but I think it will get your gears turning. Having the mindset to automate as much of my computing life as possible saves me a lot of time. With this time saved, I am able to blog, browse Steemit, run the Creators' 2Guild, and have a life.

Parts of my script

if [[ ! -d ~/.config/nvim/colors/ ]]; then
   mkdir ~/.config/nvim/colors/
fi

Here I tell the script that if the directory ~/.config/nvim/colors/ does not exist then create the directory by running mkdir ~/.config/nvim/colors/. Then I do it again for the .bashrc. file.

if [[ ! -f ~/.bashrc ]]; then
   touch ~/.bashrc
fi

The reason why I have the script create these files and directories (and more as I flesh this out) is to make sure the needed information is there for the symlinks I automate at the end of the bash script. After this I have the script add two lines to the end of the .bashrc file.

echo "alias vim='nvim'" >> .bashrc
echo "alias tmux='tmux -2'" >> .bashrc
source ~/.bashrc

These lines may be replaced with a symlink to a completed .bashrc file as I tweak the script because as I add more to the server's .bashrc it could make the script a bit messy. The next section I have so far is to install git and pull down a Vim, plugin manager.

sudo apt install git

git clone https://github.com/VundleVim/Vundle.vim.git ~/.config/nvim/bundle/Vundle.vim

I plan to have the script check the distribution of Linux before installing git so that I do not have to edit this file between servers running Ubuntu and Arch. Then we have the symlinks:

ln -sf ~/dotfiles/vim/colors/molokai.vim ~/.config/nvim/colors/molokai.vim
ln -sf ~/dotfiles/vimrc.main ~/.config/nvim/init.vim
ln -sf ~/dotfiles/tmuxConfig.main ~/.tmux.conf

A symlink tells the computer to use the first file in each line and make the second file link back to the first. This is handy when customizing the configuration files for many programs. Instead of having to edit them every time by hand we can have a master copy to edit and tweak over time.

Thanks For Reading!


Looking to take your Steem based creations to the next level?
Join us over at the Creators' Guild Discord group! We are here to encourage, support and increase the creation of quality content.

Like what you see?!
You can vote me as witness!
If you have any questions about the future of Steem
or my witness please feel free to message jrswab#3134 on Discord.

vote-jrswab-for-steem-Witnesses—Steemit.gif

Click here to vote with SteemConnect!

Or you can do the following via Steemit:
Go to https://steemit.com/~witnesses
Scroll down to the bottom.
Type "jrswab" into the box.
Click "Vote" once.
Refresh & check.

All images came from royalty and attribution free sources unless specified.

Sort:  

I'm a fellow nerd and can still VI in my sleep...

I should hang out with you more, as I want to learn how to programmatically access the Steemit blockchain. Any tips for me? ;)

😄😇😄

@creatr

I want to learn how to programmatically access the Steemit blockchain

I am about to start messing around with that soon as a way to intergrate my content onto my own website so I'll let you know as soon as I do.

And yes, let's hang out :D

Thanks!

I was starting to use SteemSQL, but @archange began charging more than I was willing to pay... :(

In any case, I need to learn the magic behind direct blockchain access. :D

I am going to be messing around with javascript and nodejs for my sites' access to the steem blockchain. Just need to find the time haha

"Just need to find the time haha..."

Yeah, me too...

Maybe we can egg each other on. ;)

You can do it! I believe in you! (like that? haha)

Yeah, like that... or maybe, "Hey, I got that API function working before you did, neener neener...." ;)

As you said that as you started learning and advanced from desktop I started imagining some 3D windows holograms Augmented Reality and what not :D. I understand you completely. In company Im working we have now new notebooks with Windows 10. It's all "shiny and nice" but I have linux in virtual box and Im spending 95% of my time in CLI (rest is in portable thunderbird). I have all my settings keys etc on that linux and when I get new (mandatory) notebook I just copy virtual box image and Im ready to go. You started building your scripts nicely. I would recommend python it can do more than bash and it's not at all hard to learn.

I know Python a bit and have wrote with it in the past but it never crossed my mind to have it execute shell commands. Thanks for the tip!

I know how you feel. Having to take my hand off the keyboard to go move the mouse pointer around the screen and click incessantly seems so annoying and slow. :)

Coin Marketplace

STEEM 0.18
TRX 0.15
JST 0.028
BTC 63099.80
ETH 2455.59
USDT 1.00
SBD 2.58