Skip to content
Snippets Groups Projects
0_setup.py 2.03 KiB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os

import utils


def setup(interactive=True):
    cmds = [
        'apt-get clean',
        'apt-get update',
        'apt-get install --yes make ipython ipython3 vim netcat git htop iotop bmon host lm-sensors pciutils ntp nfs-client smartmontools pwgen ntpdate dialog curl',
        # Locale
        'locale-gen en_GB.UTF-8',
        'update-locale LANG=en_GB.UTF-8 LANGUAGE=en_GB.UTF-8 LC_ALL=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8',
        # Vim colors
        '[ -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 fo:
            bashrc = fo.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 fo:
            fo.write(new_bashrc)
        utils.log('bashrc file updated: %s' % bashrc_path)
    utils.log('bashrc file up to date.')