commit 5ab7ca995262b68d51d7d754336fad6d3cd5595c
parent c71483d17b39d0e602d585375743954e5cd5a2b6
Author: Jaromil <jaromil@dyne.org>
Date: Sat, 1 Jun 2013 13:15:25 +0000
new install script for ssh based administration
Diffstat:
A | bin/gitzone-install | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 106 insertions(+), 0 deletions(-)
diff --git a/bin/gitzone-install 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