Exemple #1
0
def set_up_vim_addon_xmledit():
    print_msg('\nenable *.html files for vim addon xmledit:')
    ftplugin_dir = '~/.janus/xmledit/ftplugin'
    if exists(ftplugin_dir):
        # enable html file support (cf. http://stackoverflow.com/a/28603924):
        run(flo('cp -n {ftplugin_dir}/html.vim {ftplugin_dir}/html.vim.orig'))
        run(flo('ln -snf xml.vim {ftplugin_dir}/html.vim'))
Exemple #2
0
def revealjs_template():
    '''Create or update the template presentation demo using task `revealjs`.
    '''
    from config import basedir, github_user, github_repo

    run(flo('rm -f {basedir}/index.html'))
    run(flo('rm -f {basedir}/slides.md'))
    run(flo('rm -f {basedir}/README.md'))
    run(flo('rm -rf {basedir}/img/'))

    title = 'reveal.js template'
    subtitle = '[reveal.js][3] presentation written ' \
               'in [markdown][4] set up with [fabric][5] & [fabsetup][6]'
    description = '''\
This presentation shows how to create a reveal.js presentation which will be
set up with the fabric task `setup.revealjs` of fabsetup.

Also, you can use this presentation source as a reveal.js template:
* Checkout this repo
* Then set the title in the `index.html` and edit the
  `slides.md`.'''

    execute(revealjs, basedir, title, subtitle, description, github_user,
            github_repo)

    # (README.md was removed, but not the github remote repo)
    print_msg('\n## Re-add github repo infos into README.md')
    basename = os.path.basename(basedir)
    _insert_repo_infos_into_readme(basedir,
                                   github_user=_lazy('github_user'),
                                   github_repo=_lazy('github_repo',
                                                     default=basename))

    print_msg('\n## Assure symbolic link not tracked by git exists\n')
    run(flo('ln -snf ../reveal.js  {basedir}/reveal.js/reveal.js'))
Exemple #3
0
def revealjs_template():
    '''Create or update the template presentation demo using task `revealjs`.
    '''
    from config import basedir, github_user, github_repo

    run(flo('rm -f {basedir}/index.html'))
    run(flo('rm -f {basedir}/slides.md'))
    run(flo('rm -f {basedir}/README.md'))
    run(flo('rm -rf {basedir}/img/'))

    title = 'reveal.js template'
    subtitle = '[reveal.js][3] presentation written ' \
               'in [markdown][4] set up with [fabric][5] & [fabsetup][6]'
    description = '''\
This presentation shows how to create a reveal.js presentation which will be
set up with the fabric task `setup.revealjs` of fabsetup.

Also, you can use this presentation source as a reveal.js template:
* Checkout this repo
* Then set the title in the `index.html` and edit the
  `slides.md`.'''

    execute(revealjs, basedir, title, subtitle, description,
            github_user, github_repo)

    # (README.md was removed, but not the github remote repo)
    print_msg('\n## Re-add github repo infos into README.md')
    basename = os.path.basename(basedir)
    _insert_repo_infos_into_readme(basedir, github_user=_lazy('github_user'),
                                   github_repo=_lazy('github_repo',
                                                     default=basename))

    print_msg('\n## Assure symbolic link not tracked by git exists\n')
    run(flo('ln -snf ../reveal.js  {basedir}/reveal.js/reveal.js'))
Exemple #4
0
def set_up_vim_addon_xmledit():
    print_msg('\nenable *.html files for vim addon xmledit:')
    ftplugin_dir = '~/.janus/xmledit/ftplugin'
    if exists(ftplugin_dir):
        # enable html file support (cf. http://stackoverflow.com/a/28603924):
        run(flo('cp -n {ftplugin_dir}/html.vim {ftplugin_dir}/html.vim.orig'))
        run(flo('ln -snf xml.vim {ftplugin_dir}/html.vim'))
Exemple #5
0
def pencil2():
    '''Install or update latest Pencil version 2, a GUI prototyping tool.

    Tip: For svg exports displayed proper in other programs (eg. inkscape,
    okular, reveal.js presentations) only use the 'Common Shapes' and
    'Desktop - Sketchy GUI' elements.

    More info:
        github repo (forked version 2): https://github.com/prikhi/pencil
    '''
    repo_name = 'pencil2'
    repo_dir = flo('~/repos/{repo_name}')

    print_msg('## fetch latest pencil\n')
    checkup_git_repo_legacy(url='https://github.com/prikhi/pencil.git',
                            name=repo_name)

    print_msg('\n## build properties\n')
    update_or_append_line(flo('{repo_dir}/build/properties.sh'),
                          prefix='export MAX_VERSION=',
                          new_line="export MAX_VERSION='100.*'")
    run(flo('cat {repo_dir}/build/properties.sh'))

    run(flo('cd {repo_dir}/build && ./build.sh  linux'),
        msg='\n## build pencil\n')
    install_user_command_legacy('pencil2', pencil2_repodir=repo_dir)
    print_msg('\nNow You can start pencil version 2 with this command:\n\n'
              '    pencil2')
Exemple #6
0
def tweak_css(repo_dir):
    '''Comment out some css settings.'''
    print_msg("* don't capitalize titles (no uppercase headings)")
    files = [
        'beige.css', 'black.css', 'blood.css', 'league.css', 'moon.css',
        'night.css', 'serif.css', 'simple.css', 'sky.css', 'solarized.css',
        'white.css',
    ]
    line = '  text-transform: uppercase;'
    for file_ in files:
        update_or_append_line(filename=flo('{repo_dir}/css/theme/{file_}'),
                              prefix=line, new_line=flo('/*{line}*/'))

    print_msg('* images without border')
    data = [
        {'file': 'beige.css',     'line': '  border: 4px solid #333;'},
        {'file': 'black.css',     'line': '  border: 4px solid #fff;'},
        {'file': 'blood.css',     'line': '  border: 4px solid #eee;'},
        {'file': 'league.css',    'line': '  border: 4px solid #eee;'},
        {'file': 'moon.css',      'line': '  border: 4px solid #93a1a1;'},
        {'file': 'night.css',     'line': '  border: 4px solid #eee;'},
        {'file': 'serif.css',     'line': '  border: 4px solid #000;'},
        {'file': 'simple.css',    'line': '  border: 4px solid #000;'},
        {'file': 'sky.css',       'line': '  border: 4px solid #333;'},
        {'file': 'solarized.css', 'line': '  border: 4px solid #657b83;'},
        {'file': 'white.css',     'line': '  border: 4px solid #222;'},
    ]
    for item in data:
        file_ = item['file']
        lines = [item['line'], ]
        lines.extend(['  box-shadow: 0 0 10px rgba(0, 0, 0, 0.15); }',
                      '  box-shadow: 0 0 20px rgba(0, 0, 0, 0.55); }'])
        for line in lines:
            update_or_append_line(filename=flo('{repo_dir}/css/theme/{file_}'),
                                  prefix=line, new_line=flo('/*{line}*/'))
Exemple #7
0
def powerline_for_bash(bindings_dir):
    bash_snippet = '~/.bashrc_powerline_bash'
    install_file_legacy(path=bash_snippet, bindings_dir=bindings_dir)
    prefix = flo('if [ -f {bash_snippet} ]; ')
    enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi')
    uncomment_or_update_or_append_line(filename='~/.bashrc', prefix=prefix,
                                       new_line=enabler, comment='#')
Exemple #8
0
def lms():
    '''Install and start a Logitech Media Server (lms).

    More infos:
     * http://wiki.slimdevices.com/index.php/Logitech_Media_Server
     * http://wiki.slimdevices.com/index.php/DebianPackage
     * http://www.mysqueezebox.com/download
     * XSqueeze on Kodi:
       * http://kodi.wiki/view/Add-on:XSqueeze
       * http://forum.kodi.tv/showthread.php?tid=122199
    '''
    # cf. http://wiki.slimdevices.com/index.php/DebianPackage#installing_7.9.0
    cmds = '''\
url="http://www.mysqueezebox.com/update/?version=7.9.0&revision=1&geturl=1&os=deb"
latest_lms=$(wget -q -O - "$url")
mkdir -p ~/.logitech_media_server_sources
cd ~/.logitech_media_server_sources
wget $latest_lms
lms_deb=${latest_lms##*/}
sudo dpkg -i $lms_deb
'''
    run(cmds)
    run('sudo usermod -aG audio  squeezeboxserver')
    with warn_only():
        run('sudo addgroup lms')
    run('sudo usermod -aG lms  squeezeboxserver')
    username = env.user
    run(flo('sudo usermod -aG audio  {username}'))
    print('\n    Set correct folder permissions manually, eg:')
    print('    > ' + cyan(flo('chown -R {username}.lms  <path/to/your/media>')))
    hostname = env.host
    print(flo('\n    lms frontend available at http://{hostname}:9000'))
Exemple #9
0
def server_customizations():
    '''Customize the server (user, authorized_keys, ...).'''

    username = env.user
    env.user = '******'

    # create user
    all_users = run('cut -d: -f1 /etc/passwd').split()
    if username not in all_users:

        host = env.host

        run(flo('adduser {username}'))

        # add user to the sudo group, cf. http://askubuntu.com/a/7484
        #run('sudo adduser {username} sudo'.format(**locals()))
        # http://jeromejaglale.com/doc/unix/ubuntu_sudo_without_password
        append('/etc/sudoers', flo('{username} ALL=(ALL) NOPASSWD: ALL'),
               use_sudo=True)

        # set up password-less login
        local(flo('ssh-copy-id -i ~/.ssh/id_rsa.pub  {username}@{host}'))

        env.user = username

        # Disable service apache2 httpd, cf. http://askubuntu.com/a/355102
        sudo('update-rc.d apache2 disable')
    else:
        print(magenta(flo(' nothing to do, user {username} already exists')))
        env.user = username
Exemple #10
0
def lms():
    '''Install and start a Logitech Media Server (lms).

    More infos:
     * http://wiki.slimdevices.com/index.php/Logitech_Media_Server
     * http://wiki.slimdevices.com/index.php/DebianPackage
     * http://www.mysqueezebox.com/download
     * XSqueeze on Kodi:
       * http://kodi.wiki/view/Add-on:XSqueeze
       * http://forum.kodi.tv/showthread.php?tid=122199
    '''
    # cf. http://wiki.slimdevices.com/index.php/DebianPackage#installing_7.9.0
    cmds = '''\
url="http://www.mysqueezebox.com/update/?version=7.9.0&revision=1&geturl=1&os=deb"
latest_lms=$(wget -q -O - "$url")
mkdir -p ~/.logitech_media_server_sources
cd ~/.logitech_media_server_sources
wget $latest_lms
lms_deb=${latest_lms##*/}
sudo dpkg -i $lms_deb
'''
    run(cmds)
    run('sudo usermod -aG audio  squeezeboxserver')
    with warn_only():
        run('sudo addgroup lms')
    run('sudo usermod -aG lms  squeezeboxserver')
    username = env.user
    run(flo('sudo usermod -aG audio  {username}'))
    print('\n    Set correct folder permissions manually, eg:')
    print('    > ' +
          cyan(flo('chown -R {username}.lms  <path/to/your/media>')))
    hostname = env.host
    print(flo('\n    lms frontend available at http://{hostname}:9000'))
Exemple #11
0
def symbolic_links(repo_dir):
    print_msg('Create symbolic links in order to be able to start presi '
              'with npm (from the subdir reveal.js as starting point)')
    repo_name = os.path.basename(repo_dir)
    run(flo('ln -snf ../{repo_name}  {repo_dir}/{repo_name}'))
    run(flo('ln -snf ../img  {repo_dir}/img'))
    run(flo('ln -snf ../index.html  {repo_dir}/index.html'))
    run(flo('ln -snf ../slides.md  {repo_dir}/slides.md'))
Exemple #12
0
def server_prepare_root_bin_dir():
    '''Install custom commands for user root at '/root/bin/'.'''
    commands = ['run_backup']
    for command in commands:
        install_file_legacy(flo('/root/bin/{command}'), sudo=True)
        sudo(flo('chmod 755 /root/bin/{command}'))
        if command == 'run_backup':
            sudo('ln -snf /root/bin/run_backup /etc/cron.daily/run_backup')
Exemple #13
0
def symbolic_links(repo_dir):
    print_msg('Create symbolic links in order to be able to start presi '
              'with npm (from the subdir reveal.js as starting point)')
    repo_name = os.path.basename(repo_dir)
    run(flo('ln -snf ../{repo_name}  {repo_dir}/{repo_name}'))
    run(flo('ln -snf ../img  {repo_dir}/img'))
    run(flo('ln -snf ../index.html  {repo_dir}/index.html'))
    run(flo('ln -snf ../slides.md  {repo_dir}/slides.md'))
Exemple #14
0
def set_up_powerline_daemon(scripts_dir):
    bash_snippet = '~/.bashrc_powerline_daemon'
    install_file_legacy(path=bash_snippet, scripts_dir=scripts_dir)
    prefix = flo('if [ -f {bash_snippet} ]; ')
    enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi')
    update_or_append_line(filename='~/.bashrc',
                          prefix=prefix,
                          new_line=enabler)
Exemple #15
0
def setup_npm(revealjs_dir):
    if query_yes_no('\nSet up npm for serving presentation?', default='no'):
        run(flo('cd {revealjs_dir}  &&  ' 'npm install'))
        print_msg(
            flo('\nServe presentation locally '
                '(monitors source files for changes):\n\n'
                '    cd {revealjs_dir}  &&  npm start\n\n'
                'View presentation in a browser:\n\n'
                '    http://localhost:8000'))
Exemple #16
0
def init_git_repo(basedir):
    basedir_abs = os.path.expanduser(basedir)
    if os.path.isdir(flo('{basedir_abs}/.git')):
        print('git repo already initialized (skip)')
    else:
        fabric.operations.local(flo('cd {basedir} && git init'))
        fabric.operations.local(flo('cd {basedir} && git add .'))
        fabric.operations.local(
            flo('cd {basedir} && git commit -am "Initial commit"'))
Exemple #17
0
def download(inst_dir):
    url_script = 'https://www.cs.auckland.ac.nz/~pgut001/dumpasn1.c'
    url_config = 'https://www.cs.auckland.ac.nz/~pgut001/dumpasn1.cfg'
    url_example = 'https://github.com/openssl/openssl/blob/master/test/' \
                  'recipes/ocsp-response.der?raw=true'
    run(flo('mkdir -p {inst_dir}'))
    run(flo('cd {inst_dir}  &&  wget --backups=1  {url_script}'))
    run(flo('cd {inst_dir}  &&  wget -O dumpasn1.cfg  {url_config}'))
    run(flo('cd {inst_dir}  &&  wget -O example.der  {url_example}'))
Exemple #18
0
def powerline_for_bash(bindings_dir):
    bash_snippet = '~/.bashrc_powerline_bash'
    install_file_legacy(path=bash_snippet, bindings_dir=bindings_dir)
    prefix = flo('if [ -f {bash_snippet} ]; ')
    enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi')
    uncomment_or_update_or_append_line(filename='~/.bashrc',
                                       prefix=prefix,
                                       new_line=enabler,
                                       comment='#')
Exemple #19
0
def export_repo(parent_dir, repo_url, repo_name=None):
    if repo_name:
        repo_dir = flo('{parent_dir}/{repo_name}')
        if exists(repo_dir):
            run(flo('rm -rf {repo_dir}'),
                msg='delete existing repo dir')
    repo_name = checkup_git_repo_legacy(repo_url, name=repo_name,
                                        base_dir=parent_dir)
    run(flo('cd {parent_dir}/{repo_name} && rm -rf .git/'),
        msg='delete .git dir (the hole presentation becomes a git repository)')
Exemple #20
0
def setup_npm(revealjs_dir):
    if query_yes_no('\nSet up npm for serving presentation?',
                    default='no'):
        run(flo('cd {revealjs_dir}  &&  '
                'npm install'))
        print_msg(flo('\nServe presentation locally '
                      '(monitors source files for changes):\n\n'
                      '    cd {revealjs_dir}  &&  npm start\n\n'
                      'View presentation in a browser:\n\n'
                      '    http://localhost:8000'))
Exemple #21
0
def export_repo(parent_dir, repo_url, repo_name=None):
    if repo_name:
        repo_dir = flo('{parent_dir}/{repo_name}')
        if exists(repo_dir):
            run(flo('rm -rf {repo_dir}'), msg='delete existing repo dir')
    repo_name = checkup_git_repo_legacy(repo_url,
                                        name=repo_name,
                                        base_dir=parent_dir)
    run(flo('cd {parent_dir}/{repo_name} && rm -rf .git/'),
        msg='delete .git dir (the hole presentation becomes a git repository)')
Exemple #22
0
def restore_tracenv_from_backup_tarball(site_dir, bin_dir):
    # FIXME stop trac if it is running already
    filename_tarball = query_input('tarball path?')
    run(flo('mkdir -p {site_dir}/tmp'))
    run(flo('tar xf {filename_tarball}  --directory={site_dir}/tmp'))
    # save tracenv if it exists
    run(flo('mv {site_dir}/tracenv  {site_dir}/tracenv.before_$(date +%F).bak'
            ' || true'))
    run(flo('mv {site_dir}/tmp/tracenv_hotcopy  {site_dir}/tracenv'))
    run(flo('rmdir {site_dir}/tmp'))
Exemple #23
0
def init_git_repo(basedir):
    basedir_abs = os.path.expanduser(basedir)
    if os.path.isdir(flo('{basedir_abs}/.git')):
        print_msg('git repo already initialized (skip)')
    else:
        if not exists('{basedir_abs}/.gitignore'):
            install_file_legacy(path=flo('{basedir_abs}/.gitignore'),
                         from_path='~/repos/my_presi/.gitignore')
        run(flo('cd {basedir} && git init'))
        run(flo('cd {basedir} && git add .'))
        run(flo('cd {basedir} && git commit -am "Initial commit"'))
Exemple #24
0
def care_for_build_dir():
    build_dir = run('readlink -f ~/ct', capture=True)
    build_dir_yellow = yellow(build_dir)
    question_f = flo("delete file '{build_dir_yellow}'?")
    question_d = flo("delete build dir '{build_dir_yellow}'?")
    if os.path.isfile(build_dir) and query_yes_no(question_f, default='yes'):
        run(flo('rm -rf {build_dir}'))
    elif os.path.exists(build_dir) and query_yes_no(question_d, default='yes'):
        run(flo('rm -rf {build_dir}'))
    run(flo('mkdir -p {build_dir}'))
    return build_dir
Exemple #25
0
def enable_nvm():
    '''add to ~/.bashrc:  Export of $NVM env variable and load nvm command.'''
    bash_snippet = '~/.bashrc_nvm'
    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':
        uncomment_or_update_or_append_line(filename='~/.bashrc', prefix=prefix,
                                           new_line=enabler)
    else:
        print(cyan('\nappend to ~/.bashrc:\n\n    ') + enabler)
Exemple #26
0
def init_git_repo(basedir):
    basedir_abs = os.path.expanduser(basedir)
    if os.path.isdir(flo('{basedir_abs}/.git')):
        print_msg('git repo already initialized (skip)')
    else:
        if not exists('{basedir_abs}/.gitignore'):
            install_file_legacy(path=flo('{basedir_abs}/.gitignore'),
                                from_path='~/repos/my_presi/.gitignore')
        run(flo('cd {basedir} && git init'))
        run(flo('cd {basedir} && git add .'))
        run(flo('cd {basedir} && git commit -am "Initial commit"'))
Exemple #27
0
def care_for_build_dir():
    build_dir = run('readlink -f ~/ct', capture=True)
    build_dir_yellow = yellow(build_dir)
    question_f = flo("delete file '{build_dir_yellow}'?")
    question_d = flo("delete build dir '{build_dir_yellow}'?")
    if os.path.isfile(build_dir) and query_yes_no(question_f, default='yes'):
        run(flo('rm -rf {build_dir}'))
    elif os.path.exists(build_dir) and query_yes_no(question_d, default='yes'):
        run(flo('rm -rf {build_dir}'))
    run(flo('mkdir -p {build_dir}'))
    return build_dir
Exemple #28
0
def selfoss_password(sitename):
    password = query_input('selfoss password:'******'curl -d password="******" -d form_submit="send" '
                  '--insecure https://{sitename}/password 2>/dev/null | '
                  'grep "Generated Password"'),
              capture=True)
    match = re.search(r'value="([^"]+)"', res)
    pw_hash = match.group(1)
    print(flo('{pw_hash}'))
    update_or_append_line(flo('~/sites/{sitename}/selfoss/config.ini'),
                          prefix='password='******'password={pw_hash}'))
Exemple #29
0
def install_selfoss(sitename, site_dir, username):
    save_settings_and_data(site_dir)
    run(flo("sudo  rsync -a --delete --force --exclude='.git'  ~/repos/selfoss "
            ' {site_dir}'), msg='\n### install files')
    restored = restore_settings_and_data(site_dir)
    install_spout_fulltextrssGoogleBot(sitename)
    print_msg('\n### set write permissions for group www-data')
    for dirname in ['data/cache', 'data/favicons', 'data/logs',
                    'data/thumbnails', 'data/sqlite', 'public']:
        run(flo('sudo chown --recursive  www-data.www-data  '
                '{site_dir}/selfoss/{dirname}'))
    return restored
Exemple #30
0
def install(srcdir, inst_base, version, instdir):
    run(flo('rm -rf {instdir}'),
        msg='remove files from previous installations (if any)')

    run(flo('cd {srcdir}  &&  make install'), msg='install/copy files')

    run(flo('cd {inst_base}  &&  ln -snf  {version}  active'),
        msg='activate installed openssl')

    print_msg('link openssl commands')
    run(flo('cd ~/bin  &&  ln -snf {inst_base}/active/bin/openssl  openssl'))
    run(flo('cd ~/bin  &&  ln -snf {inst_base}/active/bin/c_rehash  c_rehash'))
Exemple #31
0
def compile(srcdir, instdir, confdir):
    instdir = expanduser(instdir)
    confdir = expanduser(confdir)

    run(
        flo('cd {srcdir}  &&  ./config  '
            'no-shared  '  # only create static libraries (no shared libs)
            'no-dso  '  # no support for loading dynamic shared objects
            '--prefix={instdir}  '
            '--openssldir={confdir}'))
    run(flo('cd {srcdir}  &&  make clean'))
    run(flo('cd {srcdir}  &&  make'))
Exemple #32
0
def enable_nvm():
    '''add to ~/.bashrc:  Export of $NVM env variable and load nvm command.'''
    bash_snippet = '~/.bashrc_nvm'
    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':
        uncomment_or_update_or_append_line(filename='~/.bashrc',
                                           prefix=prefix,
                                           new_line=enabler)
    else:
        print(cyan('\nappend to ~/.bashrc:\n\n    ') + enabler)
Exemple #33
0
def create_files(
        # '/home/theno/.fabsetup-addon-repos/fabsetup-theno-termdown'
        addon_dir,
        username,   # 'theno'
        addonname,  # 'termdown'
        taskname,   # 'termdown'
        author,
        author_email,
        headline='',
        description='',
        touched_files=''):
    filenames = [
        '.gitignore',
        'fabfile-dev.py',
        'fabfile.py',
        'LICENSE',
        'MANIFEST.in',
        'README.md',
        'requirements.txt',
        'setup.py',
        'fabsetup_USER_TASK/fabutils.py',
        'fabsetup_USER_TASK/__init__.py',
        'fabsetup_USER_TASK/_version.py',
    ]
    for filename in filenames:
        install_file_legacy(
            path=flo('~/.fabsetup-addon-repos/fabsetup-USER-ADDON/{filename}'),
            username=username,
            addonname=addonname,
            taskname=taskname,
            headline=headline,
            description=description,
            touched_files=touched_files,
            author=author,
            author_email=author_email,
            USER=username,
            ADDON=addonname,
            TASK=taskname,
        )

    # avoid substitution of USERNAME in path
    install_file_legacy(
        path='~/.fabsetup-addon-repos/fabsetup-{USER}-{ADDON}/'
             'fabsetup_{USER}_{TASK}/files/home/USERNAME/bin/'
             'termdown.template'.format(USER=username,
                                        ADDON=addonname,
                                        TASK=taskname),
        from_path='~/.fabsetup-addon-repos/fabsetup-USER-ADDON/'
                  'fabsetup_USER_TASK/files/home/USERNAME/bin/'
                  'termdown.template')

    print('')
    fabric.operations.local(flo('tree {addon_dir}'))
Exemple #34
0
def install_plugin_toc_progress(plugin_dir):
    export_repo(plugin_dir,
                'https://github.com/e-gor/Reveal.js-TOC-Progress.git',
                repo_name='toc-progress_all')
    run(flo('mv {plugin_dir}/toc-progress_all/plugin/toc-progress  '
            '{plugin_dir}/toc-progress'))
    run(flo('rm -rf {plugin_dir}/toc-progress_all'))
    print_msg('correct css path (because reveal.js is placed in a subdir)')
    update_or_append_line(flo('{plugin_dir}/toc-progress/toc-progress.js'),
                          prefix='\tlink.href="plugin/'
                                 'toc-progress/toc-progress.css"',
                          new_line='\tlink.href="reveal.js/plugin/'
                                   'toc-progress/toc-progress.css"')
Exemple #35
0
def install_plugin_title_footer(plugin_dir):
    export_repo(plugin_dir,
                'https://github.com/e-gor/Reveal.js-Title-Footer.git',
                repo_name='title-footer_all')
    run(flo('mv {plugin_dir}/title-footer_all/plugin/title-footer  '
            '{plugin_dir}/title-footer'))
    run(flo('rm -rf {plugin_dir}/title-footer_all'))
    print_msg('correct css path (because reveal.js is placed in a subdir)')
    update_or_append_line(flo('{plugin_dir}/title-footer/title-footer.js'),
                          prefix='\tlink.href="plugin/'
                                 'title-footer/title-footer.css";',
                          new_line='\tlink.href="reveal.js/plugin/'
                                   'title-footer/title-footer.css";')
Exemple #36
0
def install_plugin_toc_progress(plugin_dir):
    export_repo(plugin_dir,
                'https://github.com/e-gor/Reveal.js-TOC-Progress.git',
                repo_name='toc-progress_all')
    run(
        flo('mv {plugin_dir}/toc-progress_all/plugin/toc-progress  '
            '{plugin_dir}/toc-progress'))
    run(flo('rm -rf {plugin_dir}/toc-progress_all'))
    print_msg('correct css path (because reveal.js is placed in a subdir)')
    update_or_append_line(flo('{plugin_dir}/toc-progress/toc-progress.js'),
                          prefix='\tlink.href="plugin/'
                          'toc-progress/toc-progress.css"',
                          new_line='\tlink.href="reveal.js/plugin/'
                          'toc-progress/toc-progress.css"')
Exemple #37
0
def openssl(version='master', ignore_test_fail=False):
    '''
    Install or update OpenSSL from source (statically linked, no shared libs).

    Args:
        version (str): Git tag or branch to install from. Default: 'master'
        ignore_test_fail: Continue with installation if `make test` fails.
                          Default: False

    Example:
        > fab setup.openssl:version=OpenSSL_1_1_0-stable

    Created files and dirs:

        > tree ~/repos
        └── openssl          <--- checked out git repository with openssl source

        > tree ~/bin
        │
        ├── c_rehash -> openssl-inst/active/bin/c_rehash  \__ command links
        ├── openssl  -> openssl-inst/active/bin/openssl   /
        │
        └── openssl-inst
            ├── active -> OpenSSL_1_1_0-stable     <--- here 1.1.0 is "active"
            ├── master                             <--- installed via:
            │   ├── bin                                 `fab setup.openssl`
            │   ├── include
            │   ├── lib
            │   ├── openssldir   <--- openssl configs and default cert/key store
            │   └── share
            └── OpenSSL_1_1_0-stable              <---.
                ├── bin               installed via: -´
                ├── include     `fab setup.openssl:version=OpenSSL_1_1_0-stable`
                ├── lib
                ├── openssldir   <--- openssl configs and default cert/key store
                └── share
    '''
    src_base = '~/repos'
    srcdir = flo('{src_base}/openssl')

    inst_base = '~/bin/openssl-inst'
    instdir = flo('{inst_base}/{version}')

    # dir for openssl config files, and default certificate and key store
    confdir = flo('{instdir}/openssldir')

    download(src_base, version, srcdir)
    compile(srcdir, instdir, confdir)
    test(srcdir, ignore_test_fail)
    install(srcdir, inst_base, version, instdir)
Exemple #38
0
def git_ssh_or_die(username, key_dir='~/.ssh'):
    ''' Check if a ssh-key is created and imported in github.  Else, exit with
    return value 1 (die).
    '''
    key_dir_expanded = os.path.expanduser(key_dir)
    # ssh pub key dictionary
    pub_keys = []

    # check if ~/.ssh exists, if not die
    if not os.path.isdir(key_dir_expanded):
        print(red(flo('Could not open folder `{key_dir}`.  If you do not have '
                      'a public ssh key, create one and place it in '
                      '`~/.ssh/arbitrarykeyname.pub`.  Name your public key '
                      '`.pub` at the end and run this command again')))
        sys.exit(0)

    # loop through files in ~/.ssh and search for ssh public keys
    for name in os.listdir(key_dir_expanded):
        filename = os.path.join(key_dir_expanded, name)
        if re.search("\.pub$", filename):
            # filename ends with .pub
            try:
                with open(filename, 'r') as fh:
                    for line in fh.readlines():
                        # ssh public key if *.pub is not empty
                        pub_keys.append(line.split()[1])
            except (IOError, OSError):
                print(red(flo(
                    'Could not read {filename}. Still moving on ...')))

    if len(pub_keys) < 1:
        print(red('You do not have a ssh public key.  '
                  'Please create one first and import it into your github '
                  'account.  Then restart this command.'))
        sys.exit(2)

    # get github pub keys from user
    github_pub_keys = os.popen(flo(
        'curl -s https://github.com/{username}.keys')).read()
    if github_pub_keys:
        for line in github_pub_keys.splitlines():
            line = line.split()
            pub_keys.append(line[1])

    # check if matching keys are found
    if len(pub_keys) == len(set(pub_keys)):
        print(red('Could not find your public key at github.  '
                  'Please import your public key into github '
                  'and rerun this command.'))
        sys.exit(3)
Exemple #39
0
def build_ct(build_dir, branch=None):
    base_dir = '~/repos'
    abs_path = run(flo('readlink -f {base_dir}'), capture=True)

    vars_str = ' '.join([
        flo('PATH="{abs_path}/depot_tools:$PATH"'),  # add depot_tools to PATH
        'CXX=clang++',
        'CC=clang',
    ])

    url = 'https://github.com/google/certificate-transparency.git'
    if branch:
        url = flo('{url}@{branch}')

    cmds = [
        (flo("\n### create gclient config file '{build_dir}/.gclient'\n"),
         flo('gclient config --name="certificate-transparency" {url}')),
        ('\n### retrieve and build dependencies\n', 'gclient sync'),
        ('\n### build CT software & self-test\n',
         'make -C certificate-transparency check'),
    ]
    for msg, cmd in cmds:
        print_msg(msg)
        cmd_yellow = yellow(cmd)
        if query_yes_no(question=flo("run cmd '{cmd_yellow}' ?")):
            run(flo('cd {build_dir} && {vars_str}  {cmd}'))

    print_msg('\n### installed ct commands\n')
    run(
        flo('tree -L 2 {build_dir}/certificate-transparency/cpp/ '
            '-I "*test|*.cc|*.h|*.in|*.a|*.o|*.log|*test.py|*.trs|stamp-h1|'
            'tsan_suppressions" --prune'))
Exemple #40
0
def install_plugin_title_footer(plugin_dir):
    export_repo(plugin_dir,
                'https://github.com/e-gor/Reveal.js-Title-Footer.git',
                repo_name='title-footer_all')
    run(
        flo('mv {plugin_dir}/title-footer_all/plugin/title-footer  '
            '{plugin_dir}/title-footer'))
    run(flo('rm -rf {plugin_dir}/title-footer_all'))
    print_msg('correct css path (because reveal.js is placed in a subdir)')
    update_or_append_line(flo('{plugin_dir}/title-footer/title-footer.js'),
                          prefix='\tlink.href="plugin/'
                          'title-footer/title-footer.css";',
                          new_line='\tlink.href="reveal.js/plugin/'
                          'title-footer/title-footer.css";')
Exemple #41
0
def install_special_glyphs():
    '''
    More infos:
      https://powerline.readthedocs.io/en/latest/installation/linux.html#fonts-installation
      https://wiki.archlinux.org/index.php/Font_configuration
      $XDG_CONFIG_HOME: http://superuser.com/a/365918
    '''
    from_dir = '~/repos/powerline/font'

    run('mkdir -p ~/.local/share/fonts')
    run(flo('cp {from_dir}/PowerlineSymbols.otf  ~/.local/share/fonts'))

    to_dir = '~/.config/fontconfig/conf.d/'
    run(flo('mkdir -p {to_dir}'))
    run(flo('cp {from_dir}/10-powerline-symbols.conf  {to_dir}'))
Exemple #42
0
def compile(inst_dir):
    installed = flo('{inst_dir}/dumpasn1.c.1')
    latest = flo('{inst_dir}/dumpasn1.c')
    if isfile(expanduser(installed)):
        # wget has downloaded the latest version and moved the existing
        # (installed) version to dumpasn1.c.1
        if filecmp.cmp(expanduser(latest), expanduser(installed)):
            print_msg('no new version of dumpasn1.c (skip)')
        else:
            print_msg('new version of dumpasn1.c  ->  compile it')
            _compile(inst_dir)
        run(flo('rm {installed}'))
    else:
        print_msg('compile dumpasn1.c')
        _compile(inst_dir)
Exemple #43
0
def install_special_glyphs():
    '''
    More infos:
      https://powerline.readthedocs.io/en/latest/installation/linux.html#fonts-installation
      https://wiki.archlinux.org/index.php/Font_configuration
      $XDG_CONFIG_HOME: http://superuser.com/a/365918
    '''
    from_dir = '~/repos/powerline/font'

    run('mkdir -p ~/.local/share/fonts')
    run(flo('cp {from_dir}/PowerlineSymbols.otf  ~/.local/share/fonts'))

    to_dir = '~/.config/fontconfig/conf.d/'
    run(flo('mkdir -p {to_dir}'))
    run(flo('cp {from_dir}/10-powerline-symbols.conf  {to_dir}'))
Exemple #44
0
def add_tasks_r(addon_module, package_module, package_name):
    '''Recursively iterate through 'package_module' and add every fabric task
    to the 'addon_module' keeping the task hierarchy.

    Args:
        addon_module(types.ModuleType)
        package_module(types.ModuleType)
        package_name(str): Required, to avoid redundant addition of tasks

    Return: None
    '''
    module_dict = package_module.__dict__
    for attr_name, attr_val in module_dict.items():

        if isinstance(attr_val, fabric.tasks.WrappedCallableTask):
            addon_module.__dict__[attr_name] = attr_val

        elif attr_name != package_name \
                and isinstance(attr_val, types.ModuleType) \
                and attr_val.__name__.startswith('fabsetup_') \
                and attr_name.split('.')[-1] != package_name:

            submodule_name = flo('{addon_module.__name__}.{attr_name}')
            submodule = get_or_create_module_r(submodule_name)
            package_module = attr_val

            add_tasks_r(submodule, package_module, package_name)
            addon_module.__dict__[attr_name] = submodule
Exemple #45
0
def add_tasks_r(addon_module, package_module, package_name):
    '''Recursively iterate through 'package_module' and add every fabric task
    to the 'addon_module' keeping the task hierarchy.

    Args:
        addon_module(types.ModuleType)
        package_module(types.ModuleType)
        package_name(str): Required, to avoid redundant addition of tasks

    Return: None
    '''
    module_dict = package_module.__dict__
    for attr_name, attr_val in module_dict.items():

        if isinstance(attr_val, fabric.tasks.WrappedCallableTask):
            addon_module.__dict__[attr_name] = attr_val

        elif attr_name != package_name \
                and isinstance(attr_val, types.ModuleType) \
                and attr_val.__name__.startswith('fabsetup_') \
                and attr_name.split('.')[-1] != package_name:

            submodule_name = flo('{addon_module.__name__}.{attr_name}')
            submodule = get_or_create_module_r(submodule_name)
            package_module = attr_val

            add_tasks_r(submodule, package_module, package_name)
            addon_module.__dict__[attr_name] = submodule
Exemple #46
0
def checkout_latest_release_of_selfoss():
    if not exists('~/repos/selfoss/.git'):
        checkup_git_repo_legacy('https://github.com/SSilence/selfoss.git')
    else:
        run('cd ~/repos/selfoss && git fetch')

    # TODO since selfoss-2.17 Composer is required which needs to be set up
    #      on ubuntu 14.04:
    #      * https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-14-04
    #      * https://getcomposer.org/
    # latest_tag = 'git describe --abbrev=0 --tags --match "[0-9.]*" origin'
    # run(flo('cd ~/repos/selfoss && git checkout $({latest_tag})'))
    latest_working_tag = '2.16'
    run(flo('cd ~/repos/selfoss && git checkout {latest_working_tag}'))

    run(flo('cd ~/repos/selfoss && git status'))  # show latest version
Exemple #47
0
def powerline_shell():
    '''Install and set up powerline-shell prompt.

    More infos:
     * https://github.com/banga/powerline-shell
     * https://github.com/ohnonot/powerline-shell
     * https://askubuntu.com/questions/283908/how-can-i-install-and-use-powerline-plugin
    '''
    assert env.host == 'localhost', 'This task cannot run on a remote host'

    # set up fonts for powerline

    checkup_git_repo_legacy('https://github.com/powerline/fonts.git',
                            name='powerline-fonts')
    run('cd ~/repos/powerline-fonts && ./install.sh')
#    run('fc-cache -vf ~/.local/share/fonts')
    prefix = 'URxvt*font: '
    from config import fontlist
    line = prefix + fontlist
    update_or_append_line(filename='~/.Xresources', prefix=prefix,
            new_line=line)
    if env.host_string == 'localhost':
        run('xrdb  ~/.Xresources')

    # set up powerline-shell

    checkup_git_repo_legacy('https://github.com/banga/powerline-shell.git')
#    checkup_git_repo_legacy('https://github.com/ohnonot/powerline-shell.git')
    install_file_legacy(path='~/repos/powerline-shell/config.py')
    run('cd ~/repos/powerline-shell && ./install.py')

    question = 'Use normal question mark (u003F) for untracked files instead '\
        'of fancy "black question mark ornament" (u2753, which may not work)?'
    if query_yes_no(question, default='yes'):
        filename = '~/repos/powerline-shell/powerline-shell.py'
        update_or_append_line(filename, keep_backup=False,
                              prefix="        'untracked': u'\u2753',",
                              new_line="        'untracked': u'\u003F',")
        run(flo('chmod u+x  {filename}'))

    bash_snippet = '~/.bashrc_powerline_shell'
    install_file_legacy(path=bash_snippet)
    prefix = flo('if [ -f {bash_snippet} ]; ')
    enabler = flo('if [ -f {bash_snippet} ]; then source {bash_snippet}; fi')
    uncomment_or_update_or_append_line(filename='~/.bashrc', prefix=prefix,
                                       new_line=enabler)
Exemple #48
0
def nginx_site_config(username, sitename, hostname):
#    filename = 'trac_site_config.template'  # TODO DEBUG
    filename = 'trac_site_config_gunicorn.template'
#    filename = 'trac_site_config_gunicorn2.template'
#    filename = 'trac_site_config_wsgi.template'
    fabfile_data_dir = FABFILE_DATA_DIR
    path = flo('{fabfile_data_dir}/files/etc/nginx/sites-available/{filename}')
#    dn_cn = query_input('Common Name (CN) of the Distinguished Named (DN) '
#                        'of the webserver certificate?',
#                        default=flo('haw2icalendar.{hostname}'))
    # dn_cn = flo('{hostname}')
    dn_cn = dn_cn_of_certificate_with_san(sitename)
    from_str = filled_out_template(path, username=username, sitename=sitename,
                                   hostname=hostname, dn_cn=dn_cn)
    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}')
    run(flo('sudo mv /tmp/{filename} {to}'))
    run(flo('sudo chown root.root {to}'))
    run(flo('sudo chmod 644 {to}'))
    run(flo(' '.join([
            'sudo  ln -snf ../sites-available/{sitename}',
            '/etc/nginx/sites-enabled/{sitename}',
    ])))
Exemple #49
0
def enable_php5_socket_file():
    filename = '/etc/php5/fpm/pool.d/www.conf'
    print_msg('comment out "listen = 127.0.0.1:9000"')
    comment_out_line(filename, comment=';', line='listen = 127.0.0.1:9000')
    line = 'listen = /var/run/php5-fpm.sock'
    print_msg(flo('\nuncomment "{line}"'))
    uncomment_or_update_or_append_line(filename, prefix=line, new_line=line,
                                       comment=';')
    run('sudo service php5-fpm restart', msg='\nrestart php5-fpm daemon')
Exemple #50
0
def _insert_repo_infos_into_readme(basedir, github_user, github_repo):
    print_msg('\nadd github user and repo name into README.md')
    filename = flo('{basedir}/README.md')
    # FIXME: workaround: line starts with space "trick" for github.io link
    #        correct solution would be: create util function update_line()
    #                                   which will not append if prefix not
    #                                   found in file
    update_or_append_line(filename,
                          #prefix=' https://USER.github.io/REPO',
                          prefix=' https://',
                          new_line=flo(' https://{github_user}.github.io/'
                                       '{github_repo}'))
    update_or_append_line(filename,
                          #prefix='https://github.com/USER/REPO/blob/master/'
                          #       'slides.md',
                          prefix='https://github.com/',
                          new_line=flo('https://github.com/{github_user}/'
                                       '{github_repo}/blob/master/slides.md'))
Exemple #51
0
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)
Exemple #52
0
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}'))