Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Slightly off-topic, but in many posts mentioning Bash, the overall consensus seems to be that when a script gets too big you should switch to using a more full-featured programming language instead. Which is fine, I get the reasoning.

But imagine you need to deploy a server but for whatever reason you can't use Puppet, Ansible, or other configuration management tools. You need to write a deployment script using a "real" programming language.

How would you tackle the problem using Go, for example? Does anyone have examples of deployment or install scripts written in Go, Rust, or whatever else?

Thinking out loud I assume you would need a zypper (assuming openSUSE) package with Repository and Package structs and their methods, a secrets package to handle getting secrets from your secrets manager and setting them, and I'm drawing a blank on everything else.

As a system admin I picked up Go a few months ago to slowly reduce my Bash usage, but I still find myself using Bash whenever I have to write a install script because of how easy and fast it's to write compared to other languages.



I have no idea how I would tackle the problem with Go or Rust. But Python with pyinfra comes to mind as a sane enough solution. Since we decided to move from Puppet to pyinfra at work, I don't see myself writing any sysadmin scripts in bash again anytime soon.

Although Bash is still king for small utilities, I have found myself writing such scripts in Janet[1] recreationally. Bringing the functional paradigm to shell scripts really is a lot of fun, if you belong to that conviction. Although the lack of portability and the fact that you need to "know Bash" to even use the Janet `sh` library kind of guarantees that it will always just be for fun.

1. https://janet.guide/scripting/


Pyinfra's documentation is definitely on my list of things to read.


You can use a tool like gorun (https://wiki.ubuntu.com/gorun) to run Go source code as if it were a shell script, by putting gorun in the shebang line.

Of course the disadvantage is that you need to Go have the toolchain installed everywhere you want to use the Go script, so it's definitely not as portable as using a regular shell script.


I think bash scripts are perfectly fine for things like install scripts. The general advice isn't about the script getting too big, more so if its getting too complicated and you are already trying to use bash as a programming language.

Things like dealing with arrays, loops, calling APIs and parsing responses, etc. You certainly can do it all in bash, but at some point it becomes pretty unmaintainable.


Go is definitely a decent solution but I'm surprised why you aren't using Python. Most Linux and BSD distros have access to a default install of Python. Even if the version is a bit old, if all you're doing is hydrating templated configuration and doing bookkeeping for eventually running a binary with some parameters, older versions of the standard library will do just fine.


Not gonna lie, I have a certain prejudice against Python because of the whole packaging issue, something I definitely need to work on. I did ship Python code before, I just don't really like using it.

I do have the pyinfra documentation saved so I remember to take a look at it. I love Go for many reasons, but the distribution of binaries is probably at the top.


I tried migrating my Linux setup script to Python, but the sudo thing is quite hard to solve.

Either I have to grant the whole Python process sudo privileges and manually change the ownership of all touched files, or I have to spawn a sudo rm process to remove the files owned by root (instead of using Python's standard library).

Neither of these makes the script simpler or easier to maintain.


> Either I have to grant the whole Python process sudo privileges and manually change the ownership of all touched files, or I have to spawn a sudo rm process to remove the files owned by root (instead of using Python's standard library).

You could have a separate python script you call via sudo.

Or you could automate the equivalent within python. Old discussion:

https://www.reddit.com/r/Python/s/tIYUq1Zgd3

Code (plus Python 3 & functionality updates; linked from the discussion, but knowing HN, some people will just wabt to skip straight to it):

https://gist.github.com/barneygale/8ff070659178135b10b5e202a...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: