Skip to content

Instantly share code, notes, and snippets.

@nguyenl95
Last active Jun 7, 2018
Embed
What would you like to do?
personal snippets for ubuntu 16.04
# 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'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# alias collection in hope of being efficient typing
# https://askubuntu.com/questions/1414/how-to-create-a-permanent-alias
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias p=python
# ~/.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
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# 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|*-256color) 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
# 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 ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
#!/bin/bash
### customize ubuntu 16.04
### Note
# Deactivate current virtualenv (if u got one) by `deactivate`
# variables
update_resourceslist=1
update_dns=1
update_bashrc=1
update_bash_alias=1
install_pydev=1
install_docker=1
install_apt_pkg=1
install_git_kraken=1
install_vsc=1
pyver=2
if [ $update_resourceslist -eq 1 ]; then
echo " [*] UPDATE RESOURCES LIST "
err=0
### https://stackoverflow.com/questions/6156259/sed-expression-doesnt-allow-optional-grouped-string
### https://www.ibm.com/developerworks/library/l-sed2/index.html
sudo sed -ie 's/\([a-zA-Z0-9]*\.archive\.\)\{0,1\}\(archive\.\)\{0,1\}\(security\.\)\{0,1\}ubuntu\.com/opensource\.xtdv\.net/g' /etc/apt/sources.list
err=$(($err+$?)) ### https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script
echo " [!] STATUS " $err
fi
if [ $update_dns -eq 1 ]; then
echo " [*] UPDATE DNS "
err=0
### https://stackoverflow.com/questions/18836853/sudo-cat-eof-file-doesnt-work-sudo-su-does
sudo bash -c 'cat <<EOF >/etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF'
err=$(($err+$?)) ### https://askubuntu.com/questions/224966/how-do-i-get-resolvconf-to-regenerate-resolv-conf-after-i-change-etc-network-in
sudo resolvconf -u
err=$(($err+$?))
echo " [!] STATUS " $err
fi
sudo apt-get update
if [ $update_bashrc -eq 1 ]; then
echo " [*] INSTALL PRERESIQUITES "
err=0
ub=(curl)
sudo apt-get install -y ${ub[@]}
err=$(($err+$?))
curl -L -k https://gist.githubusercontent.com/nguyenl95/b15b462fdca8de66660a5346b8e8f181/raw/.bashrc -o ~/.bashrc # update .bashrc
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $update_bash_alias -eq 1 ]; then
echo " [*] UPDATE BASH ALIASES"
err=0
curl -L -k https://gist.githubusercontent.com/nguyenl95/b15b462fdca8de66660a5346b8e8f181/raw/.bash_aliases -o ~/.bash_aliases
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $install_docker -eq 1 ]; then
echo " [*] INSTALL DOCKER " # https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository
err=0
ru=(docker docker-engine docker.io)
sudo apt-get remove -y ${ru[@]}
err=$(($err+$?))
sudo apt-get update
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
err=$(($err+$?))
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
err=$(($err+$?))
sudo apt-key fingerprint 0EBFCD88
err=$(($err+$?))
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
err=$(($err+$?))
sudo apt-get update
sudo apt-get install -y docker-ce
err=$(($err+$?))
sudo curl -k -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
err=$(($err+$?))
sudo chmod +x /usr/local/bin/docker-compose
err=$(($err+$?))
docker-compose --version
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $install_apt_pkg -eq 1 ]; then
echo " [*] INSTALL APT PKG "
err=0
ub=(vim vi nano git)
sudo apt-get install -y ${ub[@]}
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $install_pydev -eq 1 ]; then
echo " [*] INSTALL PYDEV "
### not sure which bash version it works on
### https://stackoverflow.com/questions/6348902/how-can-i-add-numbers-in-a-bash-script
err=0
ua=(python3 python3-dev python2.7 python2.7-dev)
sudo apt-get install -y ${ua[@]}
err=$(($err+$?))
curl -L -k https://bootstrap.pypa.io/get-pip.py -o ~/get-pip.py
err=$(($err+$?))
sudo -H python2 get-pip.py
err=$(($err+$?))
sudo -H python3 get-pip.py
err=$(($err+$?))
### https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3
cat <<EOF >>~/.bash_aliases
alias python=python${pyver}
alias pip=pip{$pyver}
EOF
err=$(($err+$?))
py2pkg=(virtualenv ipython)
py3pkg=(virtualenv ipython)
sudo -H python2 -m pip install -U ${py2pkg[@]} ### https://github.com/googlesamples/assistant-sdk-python/issues/236
err=$(($err+$?))
python2 -m virtualenv --clear ~/py2env
err=$(($err+$?))
sudo -H python3 -m pip install -U ${py3pkg[@]}
err=$(($err+$?))
python3 -m virtualenv --clear ~/py3env
err=$(($err+$?))
cat <<EOF >>~/.bashrc
. ~/py${pyver}env/bin/activate
EOF
err=$(($err+$?))
. ~/py${pyver}env/bin/activate
pypkg=(ipython pwntools)
pip install ${pypkg[@]}
deactivate
echo " [!] STATUS " $err
fi
if [ $install_git_kraken -eq 1 ]; then
echo " [*] INSTALL GIT KRAKEN "
err=0
sudo curl -L -k https://release.gitkraken.com/linux/gitkraken-amd64.deb -o ~/gkraken.deb
err=$(($err+$?))
sudo dpkg -i ~/gkraken.deb
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $install_vsc -eq 1 ]; then
echo " [*] INSTALL VISUAL STUDIO CODE "
err=0
sudo curl -L -k https://go.microsoft.com/fwlink/?LinkID=760868 -o ~/vsc.deb
err=$(($err+$?))
sudo dpkg -i ~/vsc.deb
err=$(($err+$?))
echo " [!] STATUS " $err
fi
if [ $install_vsc -eq 1 ]; then
echo " [*] INSTALL CHROME "
err=0
sudo curl -L -k https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o ~/chrome.deb
err=$(($err+$?))
sudo dpkg -i ~/chrome.deb
err=$(($err+$?))
echo " [!] STATUS " $err
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment