hosts-gen (434B)
1 #!/bin/sh 2 # See the LICENSE file for copyright and license details. 3 4 etcdir="/etc/hosts.d" 5 hostsfile="/etc/hosts" 6 7 hostfiles="$(ls -1 "${etcdir}" | grep '^[0-9]*-.*')" 8 9 [ $(id -u ) -ne 0 ] && printf "Please run as root.\n" && exit 1 10 11 [ -e "$hostsfile" ] && cp "$hostsfile" "$hostsfile.bkp" 12 13 truncate -s 0 "${hostsfile}" 14 for f in $hostfiles; 15 do 16 cat "${etcdir}/${f}" >> "${hostsfile}" 17 done 18 19 printf "%s file created.\n" "${hostsfile}" 20