Esempio n. 1
0
def link(src, dst, desc, is_file=True):
    if os.path.islink(dst):
        link_dst = os.readlink(dst)
        if not link_dst == src:
            print_warn(f'Link already exist: {dst} -> {link_dst}')

            print_warn('Replace the link(y/N)?', end=' ')
            choice = input()
            if not choice in ['y', 'Y']:
                print_debug('...Skipping')
                return
        elif not VARS.no_bash:
            return
    elif os.path.isfile(dst):
        print_warn(f'Destination already exist: {dst}')
        print_warn('Replace the file(y/N)?', end=' ')
        choice = input()
        if not choice in ['y', 'Y']:
            print_debug('...Skipping')
            return
    elif os.path.isdir(dst):
        raise NotImplementedError(f'Destination is a directory: "{dst}"')

    if desc:
        print_info(f'Replacing {desc}:')
    else:
        _type = 'file' if is_file else 'dir'
        desc = base_name(dst)
        print_info(f'Replacing {_type}: "{desc}"')

    create_path(dir_name(dst))
    rm_file(dst)
    bash_cmd(f'ln -s "{src}" "{dst}"')
Esempio n. 2
0
def repo():
    '''Initialize submodules'''
    print()

    if not VARS.submodule:
        return

    if not getenv('SUBMODULE_INIT'):
        setenv('SUBMODULE_INIT', 'true')

    bash_cmd('git submodulepull')
Esempio n. 3
0
def write(path, data):
    '''Write data to file'''
    if not VARS.write:
        return
    if os.path.isdir(path):
        raise NotImplementedError(f'Destination is a directory: "{path}"')
    elif os.path.isfile(path):
        print_warn(f'File already exist: "{path}"')
        print_warn('Replace the file(y/N)?', end=' ')
        choice = input()
        if not choice in ['y', 'Y']:
            print_debug('...Skipping')
            return
    print_debug(f'\tWriting to: "{path}"')
    bash_cmd(f'echo "{data}" > "{path}"')
Esempio n. 4
0
def private():
    '''Private dotfiles'''

    name = 'dotfiles_secrets'

    print_section('Clone repo')
    repo = f'https://github.com/davidkristoffersen/{name}.git'

    if not isdir(f'{DOTFILES_PRIVATE}/{name}'):
        bash_cmd(f'git clone {repo} "{DOTFILES_PRIVATE}/{name}"')

    print_section('Link repo')
    link_dir(f'{DOTFILES_PRIVATE}/{name}', name)

    print_section('Shell source')
    secret_body = '#!/usr/bin/env bash\n\n'
    secret_body += f'. \\"\\$DOTFILES_PRIVATE/{name}/.bashrc\\"'
    write(f'{DOTFILES_SHELL}/.bash.d/.90-secrets.bash', secret_body)
Esempio n. 5
0
def rm_file(path):
    if VARS.write and os.path.isfile(path):
        bash_cmd(f'rm "{path}"')
Esempio n. 6
0
def create_path(path):
    if VARS.write and not os.path.isdir(path):
        bash_cmd(f'mkdir -p "{path}"')