FreeBSD Setup Script

Hi everyone.

I've recently started learning bash scripting and I thought it might be useful to try and automate installing most common stuff like xorg, de, wifi, etc.
Because of that I've created a relatively simple script which automates these tasks.
I'm open to any feedback and discussion what to improve / do differently / do better.

Here is the script
Link
 
I’ve been wanting to work on something like that myself. Of course simple setup without options will be easy. Where you run into complexity (and learning opportunities) is when you want to present choices. I’ve done all my scripting with sh, but if you’re wanting to learn bash specifically, the nice thing is that you can learn how to do it in sh, which will work in bash, then check out the bash extensions that may add features to the script (I’m thinking specifically about arrays)
 
A better alternative might be ansible, like the following to install postfix.
Code:
---
# Make sure postfix pkg is installed
- pkgng:
    name: postfix
    state: present
 
That role was a minimalist example. A better example is a playbook people can cut & paste and run.
Code:
---
- name: push out all postfix files
  hosts: all_hosts
  gather_facts: true
 
  tasks:
    - name: Make sure a limit is used
      import_role:
        name: common
        tasks_from: check_limit.yml

    - name: Do the pkg upgrade
      pkgng:
        name: "*"
        autoremove: no
        state: latest

You can delete the check_limit task to get an idea how well it works. All it does is make sure you put a -l flag onto the command line. The check_limit code is below.

Code:
---
- name: check for limit
  fail:
    msg: "You must run this Ansible playbook with a LIMIT"
  when: ansible_limit is not defined
  run_once: true

At $JOB we use Ansible-Tower, the Open Source of which can be found here, which provides web forms to fill the command line bits in for you.
 
I took some time to browse through your script. First, kudos on making a very readable script. I was just scanning quickly on my cell phone, and still could determine rather easily what everything was doing.

I would suggest for the hardware, build in a function to auto-detect installed hardware. There are a few different ways you could do this. Parsing dmesg or running pciconf -lv come to mind first.
 
Back
Top