Skip to content
Snippets Groups Projects
0_setup.py 1.84 KiB
Newer Older
Stéphane Diemer's avatar
Stéphane Diemer committed
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os

import utils


def setup(interactive=True):
    cmds = [
        'apt-get update',
Julien Allary's avatar
Julien Allary committed
        'apt-get install --yes make ipython ipython3 vim netcat git htop iotop bmon host lm-sensors munin munin-node pciutils ntp nfs-client smartmontools pwgen ntpdate dialog',
Stéphane Diemer's avatar
Stéphane Diemer committed
        '[ -f ~/.vimrc ] || echo "color ron" > ~/.vimrc',
    ]
    utils.run_commands(cmds)
    # Add settings in bashrc
    lines = '''
# Colors
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# PS
PS1='${debian_chroot:+($debian_chroot)}\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '
# ls
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# system
alias lskernels='dpkg --get-selections | grep linux'
alias lspackages='dpkg --get-selections'
alias swapclear='sudo swapoff -a && sudo swapon -a'
alias full-upgrade='sudo apt-get update && sudo apt-get dist-upgrade -y'
alias aptud='sudo apt-get update'
alias aptug='sudo apt-get upgrade'
# python
alias rmpyc='find . -name *.pyc -type f -delete && find . -name __pycache__ -type d -delete'
    '''
    bashrc_path = os.path.expanduser('~/.bashrc')
    bashrc = ''
    if os.path.exists(bashrc_path):
        with open(bashrc_path, 'r') as fd:
            bashrc = fd.read()
    new_bashrc = bashrc.replace('#force_color_prompt=yes', 'force_color_prompt=yes')
    for line in lines.split('\n'):
        line = line.strip()
        if '=' in line:
            name = line.split('=')[0] + '='
            if name not in new_bashrc:
                new_bashrc += '\n' + line
    if new_bashrc != bashrc:
        new_bashrc += '\n'
        with open(bashrc_path, 'w') as fd:
            fd.write(new_bashrc)
        utils.log('bashrc file updated: %s' % bashrc_path)
    utils.log('bashrc file up to date.')