cerpus / Edlib

Edlib is an application for creating, sharing, storing and using rich interactive learning resources.
https://docs.edlib.com
GNU General Public License v3.0
40 stars 7 forks source link

fix broken update-hosts script #2720

Closed emmachughes closed 4 months ago

emmachughes commented 4 months ago

Replaces the broken update-host-file.sh script with a simpler one that actually works.

The documentation asks to run a very buggy script to update the /etc/hosts. One such run on macOS:

$ ./scripts/update-host-file.sh
127.0.0.1\tapi.edlib.test\n127.0.0.1\tca.edlib.test\n127.0.0.1\tdocs.edlib.test\n127.0.0.1\tfacade.edlib.test\n127.0.0.1\tmoodle.edlib.test\n127.0.0.1\tnpm.components.edlib.test\n127.0.0.1\twww.edlib.test
Password:
sed: 1: "/### EDLIB BLOCK (autog ...": unexpected EOF (pending }'s)

In Debian, if a block is already present (the first run works, but prints garbage):

# ./update-host-file.sh
127.0.0.1\tapi.edlib.test\n127.0.0.1\tca.edlib.test\n127.0.0.1\tdocs.edlib.test\n127.0.0.1\tfacade.edlib.test\n127.0.0.1\tmoodle.edlib.test\n127.0.0.1\tnpm.components.edlib.test\n127.0.0.1\twww.edlib.test
sed: cannot rename /etc/sedQdDhKX: Device or resource busy

It seems to rely on the GNU version of sed, but e.g. macOS and Alpine don't provide this. In addition, sudo must be present, which isn't universally the case.

The new script is tested to work on macOS, Debian, and Alpine, and doesn't require sudo or GNU sed.

The hubbub branch will have its subdomains added to the list when merging.