totara / totara-docker-dev

A docker setup to create a development environment for Totara Learn
MIT License
49 stars 32 forks source link

Add script for adding docker-dev hosts to /etc/hosts #160

Closed markmetcalfe closed 3 years ago

markmetcalfe commented 3 years ago

Currently, it is a bit of a hassle having to create entries in /etc/hosts for all your different sites if you have multiple site sub-directories set up.

This offers a single command that scans all the different sites you have available and the different PHP containers there are, and then generates permutations of them and inserts them into your /etc/hosts file easily. It also updates existing entries, so you can run it when you need to update them too.

markmetcalfe commented 3 years ago

When testing it the script also created hosts for hidden folders:

Your /etc/hosts file has been updated
Hosts have been added for the following sites: 13 Users jobtest original1..DS_Store pg2mysql review t14

I think we should exclude hidden folders, like original1..DS_Store ;)

I've updated it to use the find command, so it will be a bit better at filtering out hidden directories. Although note that the only GNU/Linux compatible way of determining if a file/directory is hidden is if it is prefixed with . - so if it were .DS_Store it would be excluded, but I don't know of a POSIX compatible way of checking it for both max and linux (so even if macOS thinks original1..DS_Store is hidden, linux would think it is visible)

sed: 1: "/etc/hosts": extra characters at the end of h command

Not sure where the error in the first line comes from but worth checking.

This is a specific issue with how macOS implements the sed command - I think I've fixed it but I can't test it myself - could you try it again? (Fix is based upon this: https://stackoverflow.com/questions/16745988/sed-command-with-i-option-in-place-editing-works-fine-on-ubuntu-but-not-mac)