summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2013-06-01 13:15:25 (GMT)
committer tg(x) <*@tg-x.net>2013-06-05 16:55:27 (GMT)
commit5ab7ca995262b68d51d7d754336fad6d3cd5595c (patch)
tree32da49196950fcb3ed720b26d938dd71c5494ad1
parentc71483d17b39d0e602d585375743954e5cd5a2b6 (diff)
new install script for ssh based administration
-rwxr-xr-xbin/gitzone-install106
1 files changed, 106 insertions, 0 deletions
diff --git a/bin/gitzone-install b/bin/gitzone-install
new file mode 100755
index 0000000..fccef75
--- /dev/null
+++ b/bin/gitzone-install
@@ -0,0 +1,106 @@
+#!/bin/sh
+#
+# gitzone - git-based zone file management tool for BIND
+#
+# Copyright (C) 2013 Dyne.org Foundation
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# quick script to install a new gitzone user / zones repository
+
+# first arg: username
+# secondo (optional) arg: ssh public key
+
+if [ -z $1 ]; then
+ echo "usage: gitzone-install username [ id_rsa.pub ]";
+ return 0; fi
+
+uid="`id -u`"
+if ! [ "$uid" = "0" ]; then
+ echo "this script needs to be run as root."
+ return 1; fi
+
+user="$1"
+
+# check user argument
+grep "^$user" /etc/passwd > /dev/null
+if ! [ $? = 0 ]; then echo "error: user not found: $user"; return 1; fi
+if ! [ -r /home/$user ]; then echo "error: user home not found: /home/$user"; return 1; fi
+if [ -r /home/$user/zones/$user/.git ]; then
+ echo "error: gitzone already installed for user $user";
+else # create gitzone directory in user home
+
+mkdir -p /home/$user/zones/$user
+cd /home/$user/zones/$user
+git init .
+git config receive.denyCurrentBranch ignore
+name="`cat /etc/passwd | grep '^$user' | cut -d: -f5 | sed 's/,//g'`"
+git config user.name "$user"
+git config user.email "$user@`hostname -f`"
+ln -s /usr/libexec/gitzone/*receive* .git/hooks/
+cd -
+chown -R $user:bind /home/$user/zones
+chmod -R o-rwx /home/$user/zones
+
+# add user to bind group
+usermod -aG bind $user
+
+# add gitzone cache dir
+mkdir -p /var/cache/bind/$user
+chown $user:bind /var/cache/bind/$user
+
+touch /etc/bind/named.conf.local
+grep "${user}.conf" /etc/bind/named.conf.local > /dev/null
+if ! [ $? = 0 ]; then
+ cat <<EOF >> /etc/bind/named.conf.local
+include "/etc/bind/repos/${user}.conf"
+EOF
+fi
+
+# success
+echo "Gitzone installed for user $user"
+echo "git repository url (via ssh)"
+echo "$user@`hostname -f`:zones/$user"
+
+fi # gitzone created
+
+cat <<EOF
+Don't forget to add configurations to bind!
+
+In /etc/bind/repos create ${user}.conf and put inside:
+
+zone "domain.com" {
+ type master;
+ notify yes;
+ file "/var/cache/bind/$user/domain.com";
+ allow-transfer { transfer; };
+};
+
+Then restart the bind9 daemon.
+
+2) in /etc/bind/named.conf.local add a line:
+include "/etc/bind/repos/${user}.conf";
+EOF
+
+
+key="$2" # add ssh key
+if [ -z "$key" ]; then return 0; fi
+if ! [ -r $key ]; then echo "warning: key not found $key"; return 1; fi
+mkdir -p /home/$user/.ssh
+touch /home/$user/.ssh/authorized_keys
+cat $key >> /home/$user/.ssh/authorized_keys
+chmod -R go-rwx /home/$user/.ssh
+chown -R $user:$user /home/$user/.ssh
+echo "ssh public key $key added for $user"
+return 0