Skip to content
Snippets Groups Projects
Commit f6d56dd3 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Added bashrc file (refs #20747).

parent 13444536
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import utils
def setup(interactive=True):
dir_path = utils.get_dir(__file__)
cmds = [
'apt-get clean',
'apt-get update',
......@@ -15,53 +16,7 @@ def setup(interactive=True):
'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',
# Copy bashrc file
'cp "%s/bashrc" "/root/.bashrc"' % dir_path,
]
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'
function cp_to_monitor() {
url=`grep server_name /etc/nginx/sites-enabled/msmonitor.conf | tail -n 1 | cut -f 2 | cut -d " " -f 2`
url="${url::-1}"
echo "cp $1 /home/msmonitor/msmonitor/logs/$1"
cp $1 /home/msmonitor/msmonitor/logs/$1
echo "Files are available here: https://$url/storage/"
}
'''
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.')
#!/bin/bash
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=20000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias rgrep='rgrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias lh='ls -alFh'
alias la='ls -A'
alias l='ls -CF'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
# 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'
# send a file to the dir served by monitor on https
function cp_to_monitor() {
url=`grep server_name /etc/nginx/sites-enabled/msmonitor.conf | tail -n 1 | cut -f 2 | cut -d " " -f 2`
url="${url::-1}"
echo "cp $1 /home/msmonitor/msmonitor/logs/$1"
cp $1 /home/msmonitor/msmonitor/logs/$1
echo "Files are available here: https://$url/storage/"
}
......@@ -27,6 +27,7 @@ def setup(interactive=True):
else:
utils.log('The key "ubicast_support.pub" is already in /root/.ssh/authorized_keys.')
# ubicast
cmds.append('mkdir -p /home/ubicast')
cmds.append('mkdir -p /home/ubicast/.ssh')
cmds.append('chmod 700 /home/ubicast/.ssh')
code, out = utils.exec_cmd(['rgrep', 'support@ubicast', '/home/ubicast/.ssh'])
......@@ -34,6 +35,7 @@ def setup(interactive=True):
cmds.append('cat "%s/ubicast_support.pub" >> /home/ubicast/.ssh/authorized_keys' % dir_path)
else:
utils.log('The key "ubicast_support.pub" is already in /home/ubicast/.ssh/authorized_keys.')
cmds.append('cp "/root/.bashrc" "/home/ubicast/.bashrc"')
cmds.append('chown -R ubicast:ubicast /home/ubicast/.ssh')
utils.run_commands(cmds)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment