# FreeBSD Setup Script



## Sejoslaw (Oct 23, 2022)

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


----------



## drhowarddrfine (Oct 23, 2022)

Do it in sh cause that's native to FreeBSD. Bash isn't.

Of course, that doesn't matter if you are doing this to learn bash.


----------



## jardows (Oct 23, 2022)

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)


----------



## Alain De Vos (Oct 23, 2022)

If it's executed by /bin/sh or /usr/local/bin/bash is not that important here . As it is a "users script".


----------



## cy@ (Oct 24, 2022)

A better alternative might be ansible, like the following to install postfix.

```
---
# Make sure postfix pkg is installed
- pkgng:
    name: postfix
    state: present
```


----------



## cy@ (Oct 24, 2022)

That role was a minimalist example. A better example is a playbook people can cut & paste and run.

```
---
- 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.


```
---
- 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.


----------



## jardows (Oct 24, 2022)

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.


----------



## drhowarddrfine (Oct 24, 2022)

Alain De Vos What happens if the user doesn't have or use bash? He'll definitely have sh so it is kind of important.


----------

