begin integration of zfs quota
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Oct 2011 18:44:58 +0000 (20:44 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 7 Oct 2011 18:44:58 +0000 (20:44 +0200)
README
create-user.sh
env.sh
extrausers/group
extrausers/passwd
test.sh

diff --git a/README b/README
index b704218..447a0c8 100644 (file)
--- a/README
+++ b/README
@@ -22,3 +22,21 @@ remove-user.sh
 test.sh
        - excercise rsync server to test basic operation and deduplication
 
+
+Installation on Debian:
+
+$ ./bin/debian-install.sh
+
+Disk quota calculation depends on custom POSIX ids created using libnss-extrausers
+so ensure that /etc/nsswitch.conf has extrausers enabled:
+
+$ egrep '^(passwd|group):' /etc/nsswitch.conf 
+passwd:         compat extrausers
+group:          compat extrausers
+
+Install default test user and first slice:
+
+$ sudo cp -v extrausers/* /var/lib/extrausers/
+`extrausers/group' -> `/var/lib/extrausers/group'
+`extrausers/passwd' -> `/var/lib/extrausers/passwd'
+
index 85913a6..244d6f9 100755 (executable)
@@ -1,16 +1,44 @@
 #!/bin/sh -xe
 
-login=$1
+. ./env.sh
+
+email=$1
 password=$2
-host=$3
+quota=$3
+host=$4
 
-if [ -z "$login" -o -z "$password" ]; then
-       echo "Usage: $0 login password [host]"
+if [ -z "$email" -o -z "$password" ]; then
+       echo "Usage: $0 email password [quota] [host]"
        exit 1
 fi
 
-mkdir -p users/$login/blob
-secrets="users/$login/secrets"
+test -z "$quota" && quota=200k
+
+if passwd=`grep ":$email:" /var/lib/extrausers/passwd` ; then
+       echo "## $passwd"
+       uid=`echo $passwd | cut -d: -f3`
+else
+       uid=`tail -1 /var/lib/extrausers/passwd | cut -d: -f3`
+       echo $uid
+       uid=`expr $uid + 1`
+       echo "u$uid:$password:$uid:$PORT:$email:$SLICE/$uid:/bin/false" \
+               >> /var/lib/extrausers/passwd
+fi
+
+ZSLICE=`echo $SLICE | sed 's!^/!!'`
+if [ ! -e $SLICE/$uid ] ; then
+       mkdir $SLICE/$uid
+       chown $uid:$PORT $SLICE/$uid
+       zfs set userquota@u$uid=$quota $ZSLICE
+fi
+
+secrets="$SLICE/$uid/.secrets"
 test ! -z "$host" && login="$login+$host"
 grep "^$login:" $secrets || echo "$login:$password" >> $secrets
-cat $secrets
+md5mail=`echo -n $email | md5sum | cut -d" " -f1`
+md5passwd=`echo -n $password | md5sum | cut -d" " -f1`
+grep "^$md5mail:" $secrets || echo "$md5mail:$md5passwd" >> $secrets
+
+id u$uid
+zfs get userquota@u$uid $ZSLICE
+zfs get userused@u$uid $ZSLICE
diff --git a/env.sh b/env.sh
index 96dbbb0..069707a 100644 (file)
--- a/env.sh
+++ b/env.sh
@@ -1,2 +1,3 @@
 export SLICE=/test/s1
 export IP=10.13.37.102
+export PORT=6501
index 322a1f1..dc4067d 100644 (file)
@@ -1 +1 @@
-g2000:x:2000:
+s1:/test/s1:6501:
index e5b2ae8..527ca75 100644 (file)
@@ -1 +1,2 @@
-u2000:x:2000:2000::/tmp/:/bin/fase
+u2000:secret:2000:6501:test@example.com:/test/s1/2000:/bin/false
+u2001:secret:2001:6501:test2@example.com:/test/s1/2001:/bin/false
diff --git a/test.sh b/test.sh
index be55b54..d10c635 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -15,13 +15,13 @@ pull() {
 }
 
 
-./remove-user.sh test
+#./remove-user.sh u2000
 
-./create-user.sh test secret
-./create-user.sh test secret localhost
+#./create-user.sh u2000 secret
+#./create-user.sh u2000 secret localhost
 
-./remove-user.sh test2
-./create-user.sh test2 secret
+#./remove-user.sh u2001
+#./create-user.sh u2001 secret
 
 dir=/tmp/test
 rm -Rf "$dir"