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'))
def summary(addon_dir, username, taskname): print('run your task:') print('') print(' # with fabsetup as an addon') print(' cd .fabsetup') print(flo(' fab -d {username}.{taskname}')) print(flo(' fab {username}.{taskname}')) print('') print(' # standalone') print(flo(' cd {addon_dir}')) print(flo(' pip2 install -r requirements.txt')) print(flo(' fab {username}.{taskname}')) print('') print('addon development:') print('') print(flo(' cd {addon_dir}')) print(' fab -f fabfile-dev.py -l') print(' fab -f fabfile-dev.py test') print(" git commit -am 'my commit message'") print(' git push origin master # publish at github') print(' fab -f fabfile-dev.py pypi # publish pip package at pypi') print('') print('The task code is defined in') print( cyan(flo(' {addon_dir}/fabsetup_{username}_{taskname}/__init__.py'))) print('Your task output should be in markdown style.\n') print('More infos: ' 'https://github.com/theno/fabsetup/blob/master/howtos/' 'fabsetup-addon.md')
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)
def create_github_remote_repo(basedir, github_user, github_repo): repo_url = cyan(flo('https://github.com/{github_user}/{github_repo}')) question = flo('Create remote repo {repo_url} at github.com?') if query_yes_no(question, default='yes'): run(flo("cd {basedir} && " "curl -u '{github_user}' https://api.github.com/user/repos " "-d '") + '{"name":"' + flo('{github_repo}"') + "}'") run(flo('cd {basedir} && ' 'git remote add origin ' '[email protected]:{github_user}/{github_repo}.git')) run(flo('cd {basedir} && git push origin master')) else: print('\nplease, do it yourself:\n' ' https://help.github.com/articles/' 'adding-an-existing-project-to-github-using-the-command-line/')
def nvm_primer(): '''Getting started with nvm (cf. https://github.com/creationix/nvm#usage). ''' print('\nDownload, compile and install the latest release of node:\n\n' + cyan(' nvm install node')) print('\nAnd then in any new shell:\n\n' + cyan(' nvm use node') + ' # use the installed version\n' + cyan(' nvm run node --version') + ' # run it\n' + cyan(' nvm exec 4.2 node --version') + ' # run any arbitrary ' 'command in a subshell with the desired version of node\n' + cyan(' nvm which 5.0') + ' # get the path to the executable to ' 'where it was installed') print('\nlist installed node versions:\n\n' + cyan(' nvm ls')) print('\nnvm usage:\n\n' + cyan(' nvm --help')) print('\n\n----\nBut at first, use a new shell or run `source ~/.bashrc`')
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 new_addon(): '''Create a repository for a new fabsetup-task addon. The repo will contain the fabsetup addon boilerplate. Running this task you have to enter: * your github user account (your pypi account should be the same or similar) * addon name * task name * headline, short description, and touched (and created) files and dirs for the task docstring and the README.md Created files and dirs: ~/.fabsetup-addon-repos/fabsetup-{user}-{addon} ├── fabfile-dev.py ├── fabfile.py ├── fabsetup_{user}_{task} │ ├── files │ │ └── home │ │ └── USERNAME │ │ └── bin │ │ └── termdown.template │ ├── __init__.py <--. │ └── _version.py `- task definition ├── .git │ ├── ... │ ├── config │ └── ... ├── .gitignore ├── README.md ├── requirements.txt └── setup.py ''' author, author_email = git_name_and_email_or_die() username = query_input('github username:'******'\naddon name:', default='termdown') addonname = addonname.replace('_', '-').replace(' ', '-') # minus only full_addonname = flo('fabsetup-{username}-{addonname}') print('└─> full addon name: {0}\n'.format( cyan(full_addonname))) taskname = query_input('task name:', default=addonname.replace('-', '_')) taskname = taskname.replace('-', '_').replace(' ', '_') # underscores only print('└─> full task name: {0}'.format( cyan(flo('{username}.{taskname}\n')))) addon_dir = os.path.expanduser(flo( '~/.fabsetup-addon-repos/fabsetup-{username}-{addonname}')) if os.path.exists(addon_dir): print(red(flo('\n{addon_dir} already exists.'))) print('abort') else: print('~/.gitconfig') print('├─> author: {0} ─> LICENSE, setup.py'.format(cyan(author))) print('└─> author email: {0} ─> setup.py'.format(cyan(author_email))) headline = query_input( '\nshort task headline:', default='Install or update termdown.') description = query_input( '\ndescribing infos:', default='''Termdown (https://github.com/trehn/termdown) is a "[c]ountdown timer and stopwatch in your terminal". It installs termdown via `pip install --user termdown`. Also, it installs a bash-wrapper script at `~/bin/termdown` which is convenient to time pomodoro sessions and pops up a notification when the timer finishes.''') touched_files = query_input( '\naffected files, dirs, and installed packages:', default='~/bin/termdown\n ' 'pip-package termdown (`--user` install)') print('\naddon git-repository dir: {0}'.format(cyan(addon_dir))) if not query_yes_no('\ncreate new addon?', default='yes'): print('abort') else: create_files(addon_dir, username, addonname, taskname, author, author_email, headline, description, touched_files) init_git_repo(addon_dir) create_github_remote_repo(basedir=addon_dir, github_user=username, github_repo=full_addonname) summary(addon_dir, username, taskname)