def setup_webserver(): '''Run setup tasks to set up a nicely configured webserver. Features: * owncloud service * fdroid repository * certificates via letsencrypt * and more The task is defined in file fabsetup_custom/fabfile_addtitions/__init__.py and could be customized by Your own needs. More info: README.md ''' run('sudo apt-get update') install_packages(packages_webserver) execute(custom.latex) execute(setup.solarized) execute(setup.vim) execute(setup.tmux) checkup_git_repo_legacy(url='[email protected]:letsencrypt/letsencrypt.git') execute(setup.service.fdroid) execute(setup.service.owncloud) # circumvent circular import, cf. http://stackoverflow.com/a/18486863 from fabfile import dfh, check_reboot dfh() check_reboot()
def solarized(): '''Set solarized colors in urxvt, tmux, and vim. More Infos: * Getting solarized colors right with urxvt, st, tmux and vim: https://bbs.archlinux.org/viewtopic.php?id=164108 * Creating ~/.Xresources: https://wiki.archlinux.org/index.php/Rxvt-unicode#Creating_.7E.2F.Xresources * Select a good font on Ubuntu: https://michaelheap.com/getting-solarized-working-on-ubuntu/ * tmux and 256 colors: http://unix.stackexchange.com/a/118903 ''' install_packages(['rxvt-unicode', 'tmux', 'vim']) install_file_legacy('~/.Xresources') if env.host_string == 'localhost': run('xrdb ~/.Xresources') # install and call term_colors run('mkdir -p ~/bin') install_file_legacy('~/bin/term_colors') run('chmod 755 ~/bin/term_colors') run('~/bin/term_colors')
def install_build_dependencies(): base_dir = '~/repos' repos = [ # depot_tools ".. includes gclient, gcl, git-cl, repo, and others." { 'url': 'https://chromium.googlesource.com/chromium/tools/' 'depot_tools.git', }, ] checkup_git_repos_legacy(repos, base_dir) install_packages([ 'autoconf', 'automake', 'clang', 'cmake', # cmake+ 'git', 'make', # GNU make 'libtool', 'shtool', 'tcl', 'pkgconf', #'pkg-config', # pkg-config on ubuntu 12.04 'python', ])
def irssi(): '''Set up irc client irssi. More infos: * https://wiki.archlinux.org/index.php/Irssi ''' install_packages(['irssi']) install_file_legacy('~/.irssi/config') run(os.path.expanduser('chmod 600 ~/.irssi/config'))
def i3(): '''Install and customize the tiling window manager i3.''' install_package('i3') install_file_legacy(path='~/.i3/config', username=env.user, repos_dir='repos') # setup: hide the mouse if not in use # in ~/.i3/config: 'exec /home/<USERNAME>/repos/hhpc/hhpc -i 10 &' install_packages(['make', 'pkg-config', 'gcc', 'libc6-dev', 'libx11-dev']) checkup_git_repo_legacy(url='https://github.com/aktau/hhpc.git') run('cd ~/repos/hhpc && make')
def latex(): '''Install a lot of packages to compile latex documents. A latex installation may be "completed" by the execution of the task 'setup.users_bin_dir'. ''' install_packages([ 'texlive', # 'texlive-doc-de', # Gibt es nur auf ubuntu 14.04? 'texlive-fonts-extra', 'texlive-generic-extra', 'texlive-lang-german', 'texlive-latex-extra', 'pandoc', ])
def vnc_raspi_osmc(): '''Install and configure dispmanx_vnc server on osmc (raspberry pi). More Infos: * https://github.com/patrikolausson/dispmanx_vnc * https://discourse.osmc.tv/t/howto-install-a-vnc-server-on-the-raspberry-pi/1517 * tightvnc: * http://raspberry.tips/raspberrypi-einsteiger/raspberry-pi-einsteiger-guide-vnc-einrichten-teil-4/ * http://jankarres.de/2012/08/raspberry-pi-vnc-server-installieren/ ''' print(blue('Install dependencies')) install_packages([ 'git', 'build-essential', 'rbp-userland-dev-osmc', 'libvncserver-dev', 'libconfig++-dev', ]) print( blue('Build vnc server for raspberry pi using dispmanx ' '(dispmanx_vnc)')) checkup_git_repo_legacy( url='https://github.com/patrikolausson/dispmanx_vnc.git') run('mkdir -p ~/repos') run('cd ~/repos/dispmanx_vnc && make') print(blue('set up dispmanx_vnc as a service')) with warn_only(): run('sudo systemctl stop dispmanx_vncserver.service') username = env.user builddir = flo('/home/{username}/repos/dispmanx_vnc') run(flo('sudo cp {builddir}/dispmanx_vncserver /usr/bin')) run('sudo chmod +x /usr/bin/dispmanx_vncserver') fabfile_data_dir = FABFILE_DATA_DIR put('{fabfile_data_dir}/files/etc/dispmanx_vncserver.conf', '/tmp/') run('sudo mv /tmp/dispmanx_vncserver.conf /etc/dispmanx_vncserver.conf') put( '{fabfile_data_dir}/files/etc/systemd/system/dispmanx_vncserver.service', '/tmp/') run('sudo mv /tmp/dispmanx_vncserver.service ' '/etc/systemd/system/dispmanx_vncserver.service') run('sudo systemctl start dispmanx_vncserver.service') run('sudo systemctl enable dispmanx_vncserver.service') run('sudo systemctl daemon-reload')
def pyenv(): '''Install or update the pyenv python environment. Checkout or update the pyenv repo at ~/.pyenv and enable the pyenv. Pyenv wird also als Github-Repo "installiert" unter ~/.pyenv More info: * https://github.com/yyuu/pyenv * https://github.com/yyuu/pyenv/wiki/Common-build-problems#requirements Tutorial: * http://amaral-lab.org/resources/guides/pyenv-tutorial ''' install_packages([ 'make', 'build-essential', 'libssl-dev', 'zlib1g-dev', 'libbz2-dev', 'libreadline-dev', 'libsqlite3-dev', 'wget', 'curl', 'llvm', 'libncurses5-dev', 'libncursesw5-dev', ]) if exists('~/.pyenv'): run('cd ~/.pyenv && git pull') run('~/.pyenv/bin/pyenv update') else: run('curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/' 'master/bin/pyenv-installer | bash') # add pyenv to $PATH and set up pyenv init bash_snippet = '~/.bashrc_pyenv' install_file_legacy(path=bash_snippet) prefix = flo('if [ -f {bash_snippet} ]; ') enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi') if env.host == 'localhost': # FIXME: next function currently only works for localhost uncomment_or_update_or_append_line(filename='~/.bashrc', prefix=prefix, new_line=enabler) else: print(cyan('\nappend to ~/.bashrc:\n\n ') + enabler)
def samba(): '''Install smb server samba and create a share (common read-write-access). More infos: * https://wiki.ubuntuusers.de/Samba%20Server/ ''' username = env.user install_packages(['samba']) run(flo('sudo smbpasswd -a {username}')) path = '$HOME/shared' sharename = 'shared' comment = '"smb share; everyone has full access (read/write)"' acl = flo('Everyone:F,{username}:F guest_ok=y') with warn_only(): run(flo('mkdir {path}')) run(flo('sudo net usershare add {sharename} {path} {comment} {acl}')) run(flo('sudo net usershare info {sharename}'))
def vnc_raspi_osmc(): '''Install and configure dispmanx_vnc server on osmc (raspberry pi). More Infos: * https://github.com/patrikolausson/dispmanx_vnc * https://discourse.osmc.tv/t/howto-install-a-vnc-server-on-the-raspberry-pi/1517 * tightvnc: * http://raspberry.tips/raspberrypi-einsteiger/raspberry-pi-einsteiger-guide-vnc-einrichten-teil-4/ * http://jankarres.de/2012/08/raspberry-pi-vnc-server-installieren/ ''' print(blue('Install dependencies')) install_packages([ 'git', 'build-essential', 'rbp-userland-dev-osmc', 'libvncserver-dev', 'libconfig++-dev', ]) print(blue('Build vnc server for raspberry pi using dispmanx ' '(dispmanx_vnc)')) checkup_git_repo_legacy( url='https://github.com/patrikolausson/dispmanx_vnc.git') run('mkdir -p ~/repos') run('cd ~/repos/dispmanx_vnc && make') print(blue('set up dispmanx_vnc as a service')) with warn_only(): run('sudo systemctl stop dispmanx_vncserver.service') username = env.user builddir = flo('/home/{username}/repos/dispmanx_vnc') run(flo('sudo cp {builddir}/dispmanx_vncserver /usr/bin')) run('sudo chmod +x /usr/bin/dispmanx_vncserver') fabfile_data_dir = FABFILE_DATA_DIR put('{fabfile_data_dir}/files/etc/dispmanx_vncserver.conf', '/tmp/') run('sudo mv /tmp/dispmanx_vncserver.conf /etc/dispmanx_vncserver.conf') put('{fabfile_data_dir}/files/etc/systemd/system/dispmanx_vncserver.service', '/tmp/') run('sudo mv /tmp/dispmanx_vncserver.service ' '/etc/systemd/system/dispmanx_vncserver.service') run('sudo systemctl start dispmanx_vncserver.service') run('sudo systemctl enable dispmanx_vncserver.service') run('sudo systemctl daemon-reload')
def virtualbox_host(): '''Install a VirtualBox host system. More Infos: * overview: https://wiki.ubuntuusers.de/VirtualBox/ * installation: https://wiki.ubuntuusers.de/VirtualBox/Installation/ ''' if query_yes_no(question='Uninstall virtualbox-dkms?', default='yes'): run('sudo apt-get remove virtualbox-dkms') install_packages([ 'virtualbox', 'virtualbox-qt', 'virtualbox-dkms', 'virtualbox-guest-dkms', 'virtualbox-guest-additions-iso', ]) users = [env.user] for username in users: run(flo('sudo adduser {username} vboxusers'))
def users_bin_dir(): '''Put custom commands at '~/bin/' For the conversion of diagrams into the pdf format: * dia2pdf, ep2svg, svg2pdf * alldia2pdf, allep2svg, alldia2pdf ''' # circumvent circular import, cf. http://stackoverflow.com/a/18486863 from fabfile.setup import pencil2 pencil2() # used by ~/bin/ep2svg install_packages([ 'dia', 'inkscape', # used by ~/bin/svg2pdf 'xsltproc', # used by ~/bin/ep2svg ]) commands = [ 'alldia2pdf', 'allep2svg', 'allepgz2ep', 'allsvg2pdf', 'dia2pdf', 'ep2svg', 'epgz2ep', 'greypdf', 'svg2pdf' ] for command in commands: install_user_command_legacy(command)
def setup_desktop(): '''Run setup tasks to set up a nicely configured desktop pc. This is highly biased on my personal preference. The task is defined in file fabsetup_custom/fabfile_addtitions/__init__.py and could be customized by Your own needs. More info: README.md ''' run('sudo apt-get update') install_packages(packages_desktop) execute(custom.latex) execute(setup.ripping_of_cds) execute(setup.regex_repl) execute(setup.i3) execute(setup.solarized) execute(setup.vim) execute(setup.tmux) execute(setup.pyenv) # circumvent circular import, cf. http://stackoverflow.com/a/18486863 from fabfile import dfh, check_reboot dfh() check_reboot()
def owncloud(): '''Set up owncloud. Package 'owncloud' pulls package 'mysql' which asks for a password. ''' hostname = re.sub(r'^[^@]+@', '', env.host) # without username if any sitename = query_input( question='\nEnter site-name of Your Owncloud web service', default=flo('owncloud.{hostname}'), color=cyan) username = env.user fabfile_data_dir = FABFILE_DATA_DIR print(magenta(' install owncloud')) repository = ''.join([ 'http://download.opensuse.org/repositories/', 'isv:/ownCloud:/community/Debian_7.0/', ]) with hide('output'): sudo(flo('wget -O - {repository}Release.key | apt-key add -')) filename = '/etc/apt/sources.list.d/owncloud.list' sudo(flo("echo 'deb {repository} /' > {filename}")) sudo('apt-get update') install_packages([ 'owncloud', 'php5-fpm', 'php-apc', 'memcached', 'php5-memcache', ]) # This server uses nginx. owncloud pulls apache2 => Disable apache2 print(magenta(' disable apache')) with hide('output'): sudo('service apache2 stop') sudo('update-rc.d apache2 disable') print(magenta(' nginx setup for owncloud')) filename = 'owncloud_site_config.template' path = flo('{fabfile_data_dir}/files/etc/nginx/sites-available/{filename}') from_str = filled_out_template(path, username=username, sitename=sitename, hostname=hostname) with tempfile.NamedTemporaryFile(prefix=filename) as tmp_file: with open(tmp_file.name, 'w') as fp: fp.write(from_str) put(tmp_file.name, flo('/tmp/{filename}')) to = flo('/etc/nginx/sites-available/{sitename}') sudo(flo('mv /tmp/{filename} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo( flo(' '.join([ 'ln -snf ../sites-available/{sitename}', '/etc/nginx/sites-enabled/{sitename}', ]))) # php5 fpm fast-cgi config template = 'www.conf' to = flo('/etc/php5/fpm/pool.d/{template}') from_ = flo('{fabfile_data_dir}/files{to}') put(from_, '/tmp/') sudo(flo('mv /tmp/{template} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) template = 'php.ini' to = flo('/etc/php5/fpm/{template}') from_ = flo('{fabfile_data_dir}/files{to}') put(from_, '/tmp/') sudo(flo('mv /tmp/{template} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo('service php5-fpm restart') sudo('service nginx reload')
def fdroid(): '''Set up an F-Droid App Repo. More infos: * https://f-droid.org/wiki/page/Setup_an_FDroid_App_Repo * https://f-droid.org/wiki/page/Installing_the_Server_and_Repo_Tools ''' hostname = re.sub(r'^[^@]+@', '', env.host) # without username if any sitename = query_input( question='\nEnter site-name of Your F-Droid web service', default=flo('fdroid.{hostname}')) username = env.user fabfile_data_dir = FABFILE_DATA_DIR print(magenta(' install fdroidserver')) res = run( 'dpkg --get-selections | ' 'grep -q "^fdroidserver[[:space:]]*install$" >/dev/null', warn_only=True) package_installed = res.return_code == 0 question = 'package fdroidserver already installed, update? ' \ '(needs some time)' if package_installed and not query_yes_no(question, default='no'): print('skip update') else: with hide('output'): sudo('yes "" | add-apt-repository ppa:guardianproject/ppa') sudo('apt-get update') # why 'android-libhost-dev' (avoid "Failed to get apk information" # on 'fdroid update --create-metadata'): # https://f-droid.org/forums/topic/failed-to-get-apk-information-2/#post-15777 install_packages(['fdroidserver', 'android-libhost-dev']) sudo('yes "" | add-apt-repository --remove ' 'ppa:guardianproject/ppa') sudo('apt-get update') site_dir = flo('/home/{username}/sites/{sitename}') apks_dir = flo('{site_dir}/apks') fdroid_dir = flo('{site_dir}/fdroid') repo_dir = flo('{site_dir}/fdroid/repo') print(magenta(' init f-droid repo')) question = ' '.join( ['already initialized, initialize again?', '(creates a new repo key)']) if exists(repo_dir) and not query_yes_no(question, default='no'): print('skip initialization') else: with warn_only(): run(flo('rm -rf {fdroid_dir}')) run(flo('mkdir -p {repo_dir}')) run(flo('cd {fdroid_dir} && fdroid init')) run(flo('cd {site_dir} && tree')) print(magenta(' update apk files of the fdroid repo')) run(flo('mkdir -p {apks_dir}')) run(flo('rm -rf {repo_dir}/*.apk')) run(flo("find {apks_dir} -type f | rename 's/ /_/g'")) run(flo("find {apks_dir} -type f | rename 's/[^[:ascii:]]//g'")) run(flo('chmod 644 {apks_dir}/*.apk')) run(flo('cp -v {apks_dir}/*.apk {repo_dir}'), warn_only=True) run(flo('cd {fdroid_dir} && fdroid update --create-metadata')) print(magenta(' setup nginx for F-Droid')) run(flo('echo -e "User-agent: *\\nDisallow: /" > {fdroid_dir}/robots.txt')) filename = 'fdroid_site_config.template' path = flo('{fabfile_data_dir}/files/etc/nginx/sites-available/{filename}') from_str = filled_out_template(path, username=username, sitename=sitename, hostname=hostname) with tempfile.NamedTemporaryFile(prefix=filename) as tmp_file: with open(tmp_file.name, 'w') as fp: fp.write(from_str) put(tmp_file.name, flo('/tmp/{filename}')) to = flo('/etc/nginx/sites-available/{sitename}') sudo(flo('mv /tmp/{filename} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo( flo(' '.join([ 'ln -snf ../sites-available/{sitename}', '/etc/nginx/sites-enabled/{sitename}', ]))) sudo('service nginx reload')
def owncloud(): '''Set up owncloud. Package 'owncloud' pulls package 'mysql' which asks for a password. ''' hostname = re.sub(r'^[^@]+@', '', env.host) # without username if any sitename = query_input( question='\nEnter site-name of Your Owncloud web service', default=flo('owncloud.{hostname}'), color=cyan) username = env.user fabfile_data_dir = FABFILE_DATA_DIR print(magenta(' install owncloud')) repository = ''.join([ 'http://download.opensuse.org/repositories/', 'isv:/ownCloud:/community/Debian_7.0/', ]) with hide('output'): sudo(flo('wget -O - {repository}Release.key | apt-key add -')) filename = '/etc/apt/sources.list.d/owncloud.list' sudo(flo("echo 'deb {repository} /' > {filename}")) sudo('apt-get update') install_packages([ 'owncloud', 'php5-fpm', 'php-apc', 'memcached', 'php5-memcache', ]) # This server uses nginx. owncloud pulls apache2 => Disable apache2 print(magenta(' disable apache')) with hide('output'): sudo('service apache2 stop') sudo('update-rc.d apache2 disable') print(magenta(' nginx setup for owncloud')) filename = 'owncloud_site_config.template' path = flo('{fabfile_data_dir}/files/etc/nginx/sites-available/{filename}') from_str = filled_out_template(path, username=username, sitename=sitename, hostname=hostname) with tempfile.NamedTemporaryFile(prefix=filename) as tmp_file: with open(tmp_file.name, 'w') as fp: fp.write(from_str) put(tmp_file.name, flo('/tmp/{filename}')) to = flo('/etc/nginx/sites-available/{sitename}') sudo(flo('mv /tmp/{filename} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo(flo(' '.join([ 'ln -snf ../sites-available/{sitename}', '/etc/nginx/sites-enabled/{sitename}', ]))) # php5 fpm fast-cgi config template = 'www.conf' to = flo('/etc/php5/fpm/pool.d/{template}') from_ = flo('{fabfile_data_dir}/files{to}') put(from_, '/tmp/') sudo(flo('mv /tmp/{template} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) template = 'php.ini' to = flo('/etc/php5/fpm/{template}') from_ = flo('{fabfile_data_dir}/files{to}') put(from_, '/tmp/') sudo(flo('mv /tmp/{template} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo('service php5-fpm restart') sudo('service nginx reload')
def fdroid(): '''Set up an F-Droid App Repo. More infos: * https://f-droid.org/wiki/page/Setup_an_FDroid_App_Repo * https://f-droid.org/wiki/page/Installing_the_Server_and_Repo_Tools ''' hostname = re.sub(r'^[^@]+@', '', env.host) # without username if any sitename = query_input( question='\nEnter site-name of Your F-Droid web service', default=flo('fdroid.{hostname}')) username = env.user fabfile_data_dir = FABFILE_DATA_DIR print(magenta(' install fdroidserver')) res = run('dpkg --get-selections | ' 'grep -q "^fdroidserver[[:space:]]*install$" >/dev/null', warn_only=True) package_installed = res.return_code == 0 question = 'package fdroidserver already installed, update? ' \ '(needs some time)' if package_installed and not query_yes_no(question, default='no'): print('skip update') else: with hide('output'): sudo('yes "" | add-apt-repository ppa:guardianproject/ppa') sudo('apt-get update') # why 'android-libhost-dev' (avoid "Failed to get apk information" # on 'fdroid update --create-metadata'): # https://f-droid.org/forums/topic/failed-to-get-apk-information-2/#post-15777 install_packages(['fdroidserver', 'android-libhost-dev']) sudo('yes "" | add-apt-repository --remove ' 'ppa:guardianproject/ppa') sudo('apt-get update') site_dir = flo('/home/{username}/sites/{sitename}') apks_dir = flo('{site_dir}/apks') fdroid_dir = flo('{site_dir}/fdroid') repo_dir = flo('{site_dir}/fdroid/repo') print(magenta(' init f-droid repo')) question = ' '.join(['already initialized, initialize again?', '(creates a new repo key)']) if exists(repo_dir) and not query_yes_no(question, default='no'): print('skip initialization') else: with warn_only(): run(flo('rm -rf {fdroid_dir}')) run(flo('mkdir -p {repo_dir}')) run(flo('cd {fdroid_dir} && fdroid init')) run(flo('cd {site_dir} && tree')) print(magenta(' update apk files of the fdroid repo')) run(flo('mkdir -p {apks_dir}')) run(flo('rm -rf {repo_dir}/*.apk')) run(flo("find {apks_dir} -type f | rename 's/ /_/g'")) run(flo("find {apks_dir} -type f | rename 's/[^[:ascii:]]//g'")) run(flo('chmod 644 {apks_dir}/*.apk')) run(flo('cp -v {apks_dir}/*.apk {repo_dir}'), warn_only=True) run(flo('cd {fdroid_dir} && fdroid update --create-metadata')) print(magenta(' setup nginx for F-Droid')) run(flo('echo -e "User-agent: *\\nDisallow: /" > {fdroid_dir}/robots.txt')) filename = 'fdroid_site_config.template' path = flo('{fabfile_data_dir}/files/etc/nginx/sites-available/{filename}') from_str = filled_out_template(path, username=username, sitename=sitename, hostname=hostname) with tempfile.NamedTemporaryFile(prefix=filename) as tmp_file: with open(tmp_file.name, 'w') as fp: fp.write(from_str) put(tmp_file.name, flo('/tmp/{filename}')) to = flo('/etc/nginx/sites-available/{sitename}') sudo(flo('mv /tmp/{filename} {to}')) sudo(flo('chown root.root {to}')) sudo(flo('chmod 644 {to}')) sudo(flo(' '.join([ 'ln -snf ../sites-available/{sitename}', '/etc/nginx/sites-enabled/{sitename}', ]))) sudo('service nginx reload')