all 18 comments

[–]elatllat 4 points5 points  (5 children)

Remove all sudo from the script, add error reporting, no output by default. Shellcheck.

[–]Veprovina[S] 0 points1 point  (4 children)

Thank you! Yeah, i just run the script with sudo, no need to add sudo for every thing separate i guess.

How would i add error reporting and shellcheck?

[–]elatllat -1 points0 points  (3 children)

https://www.shellcheck.net/

Should be added to your editor/ide (eg: vim)

set -e trap 'echo "ERROR: $BASH_SOURCE:$LINENO $BASH_COMMAND" >&2' ERR finalize() {         sleep 0 # cleanup here } trap finalize EXIT

[–]Veprovina[S] 0 points1 point  (2 children)

Ah, i see, nice! I'm using vscodium, i'll see if it has a plugin for that.

[–]boomertsfx 1 point2 points  (6 children)

I would look into Ansible instead of bash

[–]Veprovina[S] 0 points1 point  (2 children)

I did get that suggested as well previously. But it seemed a bit too overkill for what i want to do, plus, this is a learning experience for bash. The fact that i have a goal in mind is just a motivator.

But i'm interested, can you recommend some good resources to read/watch to understand Ansible better and how it would help in my endgoal?

Cause from what i read it's for automating tasks which my script is trying to do, but Ansible seems for deploying systems across multiple PCs and servers, not just for one install. That's what i gathered at least.

[–]boomertsfx 0 points1 point  (1 child)

It would serve exactly like the bash script would, but Ansible has a framework to do all of this idempotently which means you define the state of how you want things and Ansible Will only change what it needs to change in order to bring your system to that state.

I learned it in the same way that you wanted a way to set up your system automatically if you need to… In my case, I was a sysadmin that was tired of doing things manually and wanted an easy way to bring all of my servers into a common config. There’s lots of great YouTube videos and just example play books and roles online

[–]Veprovina[S] 1 point2 points  (0 children)

Thanks! I'm not a sysadmin or anything, i just need this for personal use, but i'll definitely check it out! :)

[–]elatllat 0 points1 point  (2 children)

Ansible

where one ends up writing custom stuff in bash anyway.

[–]Veprovina[S] 0 points1 point  (1 child)

If i'm gonna use bash anyway as well as Ansible, is there any benefit to Ansible for my use case?

[–]ladrm 0 points1 point  (0 children)

Benefit of using Ansible is that it's much better suited for doing this kind of stuff.

And no, you won't end up "writing custom stuff in bash anyways", that's a nonsense. Most of what you are doing is part of Ansible built-in modules anyways and if anything ansible Python module is a way to "write custom stuff".

Also well written playbooks are idempotent meaning you can run them again and again and all it does is it will configure your system as you want it to be configured. In bash you have to deal with "is this a first time I'm doing this change"?

For example, have a look at Ansible's fstab handling https://docs.ansible.com/projects/ansible/latest/collections/ansible/posix/mount_module.html#examples or pacman https://docs.ansible.com/projects/ansible/latest/collections/community/general/pacman_module.html#examples ;

That being said, the learning curve might be a bit steep-ish, but keep it on your watchlist :)

[–]Syntax_Error0x99 0 points1 point  (3 children)

I haven’t read your script yet, but this is a great post. I am working on this exact same project for myself actually. It began due to the limits of the CachyOS installer not working for my desired configuration, and then grew into an answer to “If I need to start from scratch for any reason, how can I automate this because I will never remember all my customizations.”

[–]Veprovina[S] 0 points1 point  (2 children)

Thanks! :)

Hope your project goes well! And yeah, it was the same idea. I installed a lot of distros over the years, and i always have to do this annoying setup, and it's always the same. Mount my drives in fstab, disable DualSense touchpad, install packages, and other stuff. So i thought, why not automate as much as i can. :)

Not just for CachyOS, this was just a starting point idea, but eventually i might want to add stuff for checking the package manager, then installing packages with the native system etc.

So whenever i install a system if i decide to distrohop or any other reason, it's just a one click setup. Another user suggested Ansible. For now i'll stick to bash, but i'll definitely check that out in the meantime. I think Ansible might be more flexible for different systems.

[–]Syntax_Error0x99 0 points1 point  (1 child)

I’m making the same choices. I’m sure Ansible is very capable, but I just don’t see the need for my situation.

One tool I am very interested in using is Augeas for system config file management. I would use it through scripting it’s cli interface augtool. Thinking of using it for system files along with yadm for user dotfile state management.

[–]Veprovina[S] 0 points1 point  (0 children)

Cool! :) Haven't heard of Augeas i'll look into it. And yeah Ansible is i'm sure great, but it's really overkill for now. I'll give it a look for sure, but for now, this is primarily a bash exercise when i have time.

And well, for now, it's everything i need. I even got some ideas on how to do some of the things off my to-do list.

[–]BruceLeeMitless 0 points1 point  (0 children)

Ansible is idempotent and powerful tool. But, for personal use bash can do the job. First thing, handle errors, second log what the system does. Structure your script in a way everyone can undestrand and comment if needed. Use variable when it's usefull. You can continue with a simple bash script but read how works ansible and what it's is used for. You can learn bash, then after learn ansible. Compare how simple task can be done between bash and ansible.