Looking for Feedback on My Fedora Optimization Script

0
14
Asked By CuriousCoder42 On

I just created a shell script aimed at optimizing Fedora right after installation. If anyone has the time, could you take a look at it and suggest areas for improvement? Here's the script: [my script](https://github.com/somniasum/crimsonhat/blob/main/crimsonhat.sh). I appreciate any help!

3 Answers

Answered By ScriptSavvy88 On

First off, be careful with `set -euo pipefail`. Only use it if you completely understand what each flag does. In many cases, just using `set -u` is sufficient. Using `-e` might lead to issues, so try to limit its use with `|| true` where necessary. Also, `pipefail` can be unreliable with some third-party tools like curl; you might want to verify outputs manually for such cases.

Answered By TinkerTender On

When it comes to terminal colors, instead of assuming capabilities, consider using `tput` to fetch the correct escape sequences. This will ensure that your script checks if a terminal is present and has the required capabilities. It might look something like this: `RED="$(tput setaf 1 || tput setf 4)"`. Just remember to verify if the color codes are actually set before using them!

Answered By CodeCleaner94 On

I recommend simplifying your echo commands. You could create a helper function for each message type. For example, you could create `info`, `warn`, and `die` functions dedicated to printing messages with colors. This will definitely tidy up your script, making it more manageable. For example:

```bash
info() { echo -e "${0##*/}: $BLUE$1" 1>&2; }
warn() { echo -e "${0##*/}: $YELLOW$1" 1>&2; }
die() { echo -e "${0##*/}: $RED$1" 1>&2; exit 3; }
```
It's way cleaner!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.