Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
173 lines (143 sloc) 5.95 KB
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.files import exists
import os
from StringIO import StringIO
if not env.hosts:
env.hosts = [
] = '/bin/sh -c'
def etckeeper_check():
sudo('etckeeper pre-install')
def etckeeper_commit(message):
sudo('if etckeeper unclean; then etckeeper commit "%s"; fi' % message)
def etckeeper_done():
sudo('etckeeper post-install')
def usrlocal_check():
with cd('/usr/local'):
sudo('test -z "`git status --porcelain`"')
def usrlocal_commit(message):
with cd('/usr/local'):
sudo('if test -n "`git status --porcelain`"; then git add -A .; git commit -m "%s"; fi' % message)
def configs():
put('etckeeper/etckeeper.conf', '/etc/etckeeper/', use_sudo=True)
put('apt/99checkrestart', '/etc/apt/apt.conf.d/', use_sudo=True)
etckeeper_commit('chaosdorf-admin-toolkit configfile updates')
def deploy(version):
put("../chaosdorf-admin-toolkit_%s_all.deb" % version, '/root/', use_sudo=True)
sudo("dpkg --install /root/chaosdorf-admin-toolkit_%s_all.deb" % version)
sudo("rm /root/chaosdorf-admin-toolkit_%s_all.deb" % version)
def test():
def upgrade():
sudo("apt-get dist-upgrade --quiet")
def checkrestart():
def ldapuser(user_name, first_name, last_name):
sudo('cpu useradd -f "%s" -E "%s" -e %s' % (first_name, last_name, user_name, user_name))
sudo('ldappasswd -y /root/ldap_password -x -W -D cn=admin,dc=chaosdorf,dc=de uid=%s,ou=People,dc=chaosdorf,dc=de' % user_name)
def ldappasswd(user_name):
sudo('ldappasswd -y /root/ldap_password -x -W -D cn=admin,dc=chaosdorf,dc=de uid=%s,ou=People,dc=chaosdorf,dc=de' % user_name)
def maildir(user_name):
sudo('mkdir -p /srv/mail/%s' % user_name)
sudo('chown -R %s:%s /srv/mail/%s' % (user_name, user_name, user_name))
# by default, fabric runs the user target for each host, even though
# ldapuser and maildir only work for one. Limiting it to one host fixes this.
def user(user_name, first_name, last_name):
execute(ldapuser, user_name, first_name, last_name)
execute(maildir, user_name)
def mailforward(user_name, mail_forward):
ldif = '''dn: uid=%s,ou=People,dc=chaosdorf,dc=de
changetype: modify
replace: mailRoutingAddress
mailRoutingAddress: %s
''' % (user_name, mail_forward)
put(StringIO(ldif), 'fabfile_aliases.ldif')
sudo('ldapmodify -y /root/ldap_password -x -W -D cn=admin,dc=chaosdorf,dc=de -f fabfile_aliases.ldif')
def sshkey(user_name, key_file):
key = open(key_file).read().replace("\n", '').replace("\r", '')
ldif = '''dn: uid=%s,ou=People,dc=chaosdorf,dc=de
changetype: modify
add: sshPublicKey
sshPublicKey: %s
''' % (user_name, key)
put(StringIO(ldif), 'fabfile_keys.ldif')
sudo('ldapmodify -y /root/ldap_password -x -W -D cn=admin,dc=chaosdorf,dc=de -f fabfile_keys.ldif')
def deluser(user_name):
execute(archive_maildir, user_name)
execute(archive_home, user_name)
def archive_maildir(user_name):
with cd('/srv/mail'):
if exists(user_name):
sudo('tar czf {user}.tgz {user}'.format(user = user_name))
sudo('rm -r {user}'.format(user = user_name))
@hosts('', '')
def archive_home(user_name):
with cd('/home'):
if exists(user_name):
sudo('tar czf {user}.tgz {user}'.format(user = user_name))
sudo('rm -r {user}'.format(user = user_name))
def upgrade_mediawiki(version):
with cd('/root'):
sudo('bash /root/ > /root/mediawiki_before_upgrade_%s.sql' % version)
with cd('/srv/www'):
sudo('wget --quiet -O mediawiki.tar.gz'
% ('.'.join(version.split('.')[0:2]), version))
sudo('tar xf mediawiki.tar.gz -C /srv/www/ --strip-components=1')
sudo('rm mediawiki.tar.gz')
with cd(''):
with cd('maintenance'):
sudo('php update.php')
sudo('git add -A')
sudo('git commit -m "Upgrade auf MediaWiki %s"' % version)
def deploy_raumstatus():
put('raumstatus/raumstatus_update', '/usr/local/bin', use_sudo=True, mode=0755)
put('raumstatus/bilder/*.png', '/srv/www/de.chaosdorf/raumstatus', use_sudo=True)
etckeeper_commit('raumstatus update')
usrlocal_commit('raumstatus update')
def cgit():
if exists('/opt/cgit/src'):
with cd('/opt/cgit/src') as d:
sudo('git pull')
sudo('git submodule update --init')
sudo('apt-get install --assume-yes build-essential libssl-dev zlib1g-dev')
sudo('mkdir -p /opt/cgit/static')
sudo('git clone --recursive '
with cd('/opt/cgit/src') as d:
sudo('cp cgit /opt/cgit/cgit.cgi')
sudo('cp cgit.css cgit.png /opt/cgit/static')
# fuer embedded hosts mit readonly / (z.B. raspis im Clubraum)
def setup_readonly_host():
run('mount -o remount,rw /')
with cd('/var/lib'):
run('if ! readlink logrotate; then rm -rf logrotate; ln -s /tmp logrotate; fi')
run('mount -o remount,ro /')
def jabber_adduser(nickname):
local('echo generating temporary password:')
local('pwgen -s 23 1')
sudo('prosodyctl adduser' % nickname, user='prosody')
You can’t perform that action at this time.