Automate Your Initial OS Setup

栏目: IT技术 · 发布时间: 4年前

内容简介:There was a time in my life when a huge part of my time was spent reinstalling my Linux OS. Wonder why?Well, the first time you install Linux, they warn you to never runWhat they don’t tell you is that you have another million ways to effectively do the sa

There was a time in my life when a huge part of my time was spent reinstalling my Linux OS. Wonder why?

Well, the first time you install Linux, they warn you to never run rm- rf / as this would delete your entire system. Fair enough, that’s simple to follow.

What they don’t tell you is that you have another million ways to effectively do the same thing with commands which seem harmless at first glance.

However, there were some benefit form my misfortunes.

What irritated me the most was installing all the software I use from scratch every single time. I often forgot to install one or two programs I use and had to do it on the fly once I actually needed them which was very disturbing.

Hence, I came up with the idea to create a script which would automate this process via a single command. Every time I reinstall my OS, I simply run the script, go get myself a coffee and once I’m back, I have my OS all setup with what I need.

If you’re in a situation where you often have to do this yourself, read on.

Also, be aware that this guide is specific to installing Linux and Mac OS. You could probably apply the same concept in Windows, but I only speak bash , not bat .

Bash to the rescue

Now, there are tools out there specifically designed to achieve this. For example, you have Puppet .

Additionally, you could create docker images which have your setup bundled in an image. You could also use Arch Linux , which has a package manager enabling you to automate this more reliably, so I’ve been told.

But, I’m a simple man. I like simple tools. Hence, I’ve encapsulated this entire convoluted process in a single bash script.

You can find my entire OS setup script here . Nowadays, I have two different versions – one for Ubuntu and one for Mac.

But, to get started yourself, here’s what you have to do:

  1. Reinstall your OS
  2. Create a new empty script & add it to some kind of a repo (e.g. in Github)
  3. Every time you install a new program or enable some setting, add a line for that in the script
  4. Over time, when your needs or setup changes, keep your script up to date

That’s really the gist of it.

The important thing is to keep your script up to date, otherwise, you might abandon it altogether and stick to the old cumbersome ways of installing stuff manually.

What follows is a set of tips & tricks to have in mind

Automate your settings as well

Apart from enumerating all the software you need in sudo apt-get install lines, you can also add any additional settings not related to software install that you might need.

For example, I need Bulgarian Phonetic installed on my Ubuntu, which is not there by default, hence I’ve figured out how to do it from the terminal and added it to my script.

I no longer have to google “add keyboard mapping ubuntu” every time I reinstall the OS.

The good part is that most of these settings, especially in Linux, are totally scriptable. They often have GUI ways to do it (e.g. Go to Settings -> Keyboard -> …, etc) but I always search for the terminal one-liners in order to add it to the script.

When the settings aren’t scriptable…

There might be times when there isn’t an alternative to setting something up via the GUI. Or at least, Google isn’t helpful enough to show you how to do it in sensible time.

For these cases, I still suggest to “automate” them, but not via a script, but via written instructions in your README.md which you have to manually follow.

This is a bit cumbersome, but still better than trying to rediscover how to setup something every time you reinstall the OS.

Here’s an example from my Mac setup :

Automate Your Initial OS Setup

I’ve found this to be more common for Mac, since most answers in stackoverflow regarding how to setup something are via a GUI interface, which sucks.

I’m pretty sure there is a way to achieve all these settings via the terminal, but I’ve decided not to invest too much time in finding them out. However, if you happen to know how to do it, then feel free to open a pull request, it would be much appreciated.

Store a repo of common configurations

In addition to automating the settings and software you need, if you rely on software likevim, tmux or anything else which has some convoluted configuration, I suggest creating a separate repo for storing your configurations.

Getting it “installed” can be part of your OS setup script. This is exactly what I’ve done with my dotfiles repo.

In it, I keep my latest vim configuration, along with some auxiliary configs for tmux and various plugins.

Due to this, after I run my setup script, not only do I have all my necessary software installed, but I also have my vim setup with my favorite plugins and configuration the way I like it.

Conclusion

Tired of installing the same software all the time? Tired of setting up vim every time you get a new laptop or reinstall your OS?

Well, now you have your solution – automate the process.

Here’s how in a nutshell:

  1. Create a script
  2. Add your installations + settings + common configurations
  3. Repeat step 2 infinitely

Once you do this, you will escape the insidious process of setting up everything from scratch all the time.


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

ANTLR 4权威指南

ANTLR 4权威指南

Terence Parr / 张博 / 机械工业出版社 / 2017-5-1 / 69元

ANTLR是一款强大的语法分析器生成工具,可用于读取、处理、执行和翻译结构化的文本或二进制文件。它被广泛应用于学术领域和工业生产实践,是众多语言、工具和框架的基石。Twitter搜索使用ANTLR进行语法分析,每天处理超过20亿次查询;Hadoop生态系统中的Hive、Pig、数据仓库和分析系统所使用的语言都用到了ANTLR;Lex Machina将ANTLR用于分析法律文本;Oracle公司在S......一起来看看 《ANTLR 4权威指南》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

随机密码生成器
随机密码生成器

多种字符组合密码