commit 6c410d76105b2e14ad1e184129392a3d798d357f
Author: Cem Keylan <cem@ckyln.com>
Date: Wed, 15 Jan 2020 20:02:17 +0300
inital commit
Diffstat:
6 files changed, 88 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2020 Cem Keylan
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,25 @@
+# merge-hosts
+
+VERSION = 0.01.0
+
+PREFIX=/usr/local
+BINDIR=${PREFIX}/bin
+
+
+install:
+ install -Dm755 merge-hosts ${DESTDIR}${BINDIR}/merge-hosts
+ install -Dm644 hostsdir/* -t ${DESTDIR}/etc/hosts.d/
+
+uninstall:
+ rm -f ${DESTDIR}${BINDIR}/merge-hosts
+ @echo You need to manually remove the ${DESTDIR}/etc/hosts.d directory
+
+dist:
+ mkdir -p merge-hosts-${VERSION}
+ cp -r LICENSE README Makefile hostsdir merge-hosts \
+ merge-hosts-${VERSION}
+ tar -cf merge-hosts-${VERSION}.tar merge-hosts-${VERSION}
+ gzip merge-hosts-${VERSION}.tar
+ rm -rf merge-hosts-${VERSION}
+
+.PHONY: install uninstall dist
diff --git a/README b/README
@@ -0,0 +1,18 @@
+merge-hosts
+===========
+
+A simple shell script to generate an /etc/hosts file.
+Simpler version of hosts-gen[1].
+
+You can use this script to manage a list of files on the
+/etc/hosts.d folder. Sometimes you need to keep host entries
+seperately for specific purposes.
+
+After editing a file on /etc/hosts.d, you can simply run
+
+ merge-hosts
+
+and they will be merged.
+
+
+[1]: http://r-36.net/scm/hosts-gen/
diff --git a/hostsdir/00-header b/hostsdir/00-header
@@ -0,0 +1,4 @@
+
+#
+# /etc/hosts: static lookup table for host names
+#
diff --git a/hostsdir/01-local b/hostsdir/01-local
@@ -0,0 +1,6 @@
+
+#<ip-address> <hostname.domain.org> <hostname>
+127.0.0.1 localhost.localdomain localhost
+::1 localhost.localdomain localhost ip6-localhost
+
+# EOF
diff --git a/merge-hosts b/merge-hosts
@@ -0,0 +1,14 @@
+#!/usr/bin/env sh
+
+hostdir="/etc/hosts.d"
+hostfile="/etc/hosts"
+
+[ $(id -u ) -ne 0 ] && printf "Please run as root.\n" && exit 1
+[ -e "$hostfile" ] && cp "$hostfile" "$hostfile.bak"
+
+:> "${hostfile}"
+for file in "$hostdir/"* ; do
+ cat "$file" >> "$hostfile"
+done
+
+printf "Created $hostfile.\n"