Hi everyone! I'm diving into bash scripting and I have an ongoing project I want to share. I've created a script that transforms a minimal Arch Linux installation into a CachyOS hybrid, complete with CachyOS repositories, a suitable kernel, and specific configurations for my system. You can check out my initial version here: [GitHub link](https://github.com/Veprovina/CarchyOS/blob/main/Carchyos.sh). My idea is to eventually expand this script for other operating systems, but right now I'm focused on making it work well for my setup.
I've tested the script in a virtual machine, and while it functions, I suspect it might be overly simplistic or possibly contain errors. I'm keen to learn more about Bash scripting techniques. For example, I utilized the "cat" command from a forum post and tweaked it for my needs, but I'm unclear on its full functionality. I know that '>>' appends to a file, while '>' creates a new file or overwrites an existing one, but I wonder if there's a more elegant way to add new lines or create files. Also, I've heard that 'printf' might be better than 'echo' in some cases, but I'm not sure why.
Here's what my script currently does:
- Prints every impending change in colored output.
- Executes the CachyOS script to switch from Arch to CachyOS repositories and packages.
- Installs packages via pacman.
- Creates directories for mount points, adds drive UUIDs to fstab, and mounts them.
- Sets up a udev rule for a gamepad.
Am I on the right track, or have I strayed off course? Any guidance or references to beginner-friendly documentation or tutorials that could help deepen my understanding would be greatly appreciated! My ultimate goal is to achieve a fully automatic initial setup with just one script.
1 Answer
Hey! A couple of quick suggestions: first off, it's a good idea to avoid using 'sudo' within your script. Just running your script as a superuser should be sufficient. Also, you might want to consider adding error reporting. This will help you catch any issues that arise during execution. And don’t forget to run your script through a tool like Shellcheck – it’s really great for spotting common problems and improving your code!

Thanks for the tips! I usually just run it with sudo, so I see your point. How can I implement error reporting and what’s the best way to use Shellcheck?